hello everyone
i am new to rust, and even newer to tokio-rs, i did run tinyhttp
example on tokio and i did a benchmark, like this
$ cargo run --release --example tinyhttp
$ wrk -c100 -d10s -t`nproc` http://127.0.0.1:8081
Running 10s test @ http://127.0.0.1:8081
8 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 322.76us 297.86us 20.16ms 98.00%
Req/Sec 37.68k 1.81k 47.92k 80.05%
3025709 requests in 10.10s, 277.01MB read
Non-2xx or 3xx responses: 3025709
Requests/sec: 299545.88
Transfer/sec: 27.42MB
as you can see from above, the number of requests is pretty high ~299546
per seconds
so i did try to redo the example, and i started with just a simple connection that send back "hello world" like this
use tokio::io::Result;
use tokio::net::TcpListener;
use tokio::stream::StreamExt;
use tokio::io::AsyncWriteExt;
#[tokio::main]
async fn main() -> Result<()> {
let mut tcp_listener = TcpListener::bind("127.0.0.1:6431").await?;
let mut incoming = tcp_listener.incoming();
while let Some(Ok(mut stream)) = incoming.next().await {
tokio::spawn(async move {
stream.write(b"HTTP/1.1 200 OK\r\n\r\n").await.unwrap();
});
}
Ok(())
}
then i run the same benchmark, using the following commands
$ cargo run --release
$ wrk -c100 -d10s -t`nproc` http://127.0.0.1:6431/
Running 10s test @ http://127.0.0.1:6431/
8 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 288.62us 568.64us 37.32ms 98.29%
Req/Sec 595.08 671.48 9.43k 94.89%
47611 requests in 10.08s, 18.09MB read
Socket errors: connect 0, read 998256, write 0, timeout 0
Requests/sec: 4724.41
Transfer/sec: 1.79MB
i was hoping for a higher number of requests per seconds (higher than tokio tinyhttp) because all i am doing is sending back a hello world, but to my surprise, its a very low number ~4725
requests per seconds.
can anyone please shed some light on why this is happening?