Replies: 1 comment 1 reply
-
What happens if you change the Tokio code to this? use tokio::net::TcpListener;
use tokio::prelude::*;
#[tokio::main]
async fn main() {
tokio::spawn(real_main()).await.unwrap();
}
async fn real_main() {
let listener = TcpListener::bind("0.0.0.0:8887").await.unwrap();
loop {
let (mut socket, _) = listener.accept().await.unwrap();
tokio::spawn(async move {
let mut buf = [0; 1024];
loop {
match socket.read(&mut buf).await {
Ok(n) => {
if n == 0 {
return
}
},
Err(e) => {
eprintln!("failed to read from socket; err = {:?}", e);
return;
}
};
if let Err(e) = socket.write_all("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 1\r\n\r\na".as_bytes()).await {
eprintln!("failed to write to socket; err = {:?}", e);
}
return;
}
});
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I guess tokio is 5% slower than native epoll, but actually 30%. I don't know the reason, can you help me?
tokio version: v0.3.3
platform: Debian-10 x86_64
native epoll
tokio
Build native epoll by
gcc benchmark.c -O3 -Wall
Buils tokio by
cargo build --release
Test native epoll by
ab -c 50 -n 10000 http://127.0.0.1:8888/
Test tokio by
ab -c 50 -n 10000 http://127.0.0.1:8887/
Native epoll result
Tokio result
I came to the conclusion through rps.
Beta Was this translation helpful? Give feedback.
All reactions