I use isahc to realize a simple http bench mark tool.
The http server runs on actix-web v3.1.0. Rust version is 1.47.
Client and server are all in the same machine.
Windows 10 system, intel 8 core 1.6G, and 8G mem.
thread-num:8,use-time:12388 ms,speed:12915, About 13000/s , the tool occupy 30%+ CPU , server 15%CPU.
The same server, use baton (a tool by go), about 40000/s, it occupy 15% CPU , server 15% CPU.
It is a very simple condition. Rust performances not well.
I have tried the condition with actix-web-client, reqwest, hyper,surf..., all smaller than15000/s, worse than baton.
Why? And how to optimize it?
Thanks!
Comile cargo run --release, and profile is:
codegen-units = 8
codegen-threads=8
#debug = true
lto = true
overflow-checks = true
opt-level = 3
//--------------------------------------------------------------------------------------------
//Code
use isahc::prelude:: <em>;
use isahc::HttpClient;
use isahc::config::ResolveMap;
use async_std::</em> ;
use std::time::SystemTime;
const threadNum : usize = 8;
const runTimes : u64 = 20000;
#[async_std::main]
async fn main() -> Result<(), isahc::Error> {
let start = SystemTime::now();
let mut i : usize = 0;
let mut handlers = vec![];
while i < threadNum {
i += 1;
let no = i;
let h = task::spawn(async move {
let client = HttpClient::builder()
.max_connections(100)
.max_connections_per_host(100)
//.dns_resolve(ResolveMap::new()
// Send requests for example.org on port 80 to 127.0.0.1.
//.add("www.example.org", 8080, [127, 0, 0, 1]))
.build().unwrap();
let mut i : u64 = 0;
while i < runTimes {
i += 1;
let mut response = client.get("http://127.0.0.1:8080/").unwrap();
// Print some basic info about the response to standard output.
// println!("Status: {}", response.status());
// println!("Headers: {:#?}", response.headers());
// // Read the response body as text into a string and print it.
// print!("{}-{},{}",no, i, response.text().unwrap());
}
});
handlers.push(h);
}
for h in handlers {
h.await;
}
let interval = start.elapsed().unwrap().as_millis() as u64;
println!("thread-num:{},use-time:{} ms,speed:{}",
threadNum, interval, runTimes * 1000 * (threadNum as u64) / interval);
Ok(())
}