forked from tokio-rs/tokio-uring
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
driver: batch submit requests and add benchmark (tokio-rs#78)
Batch submit requests for fun and profit
- Loading branch information
1 parent
6d3ef61
commit 0fdc0c2
Showing
4 changed files
with
52 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::io; | ||
use std::rc::Rc; | ||
use tokio::task::JoinHandle; | ||
|
||
pub const RESPONSE: &'static [u8] = | ||
b"HTTP/1.1 200 OK\nContent-Type: text/plain\nContent-Length: 12\n\nHello world!"; | ||
|
||
pub const ADDRESS: &'static str = "127.0.0.1:8080"; | ||
|
||
fn main() -> io::Result<()> { | ||
tokio_uring::start(async { | ||
let mut tasks = Vec::with_capacity(16); | ||
let listener = Rc::new(tokio_uring::net::TcpListener::bind( | ||
ADDRESS.parse().unwrap(), | ||
)?); | ||
|
||
for _ in 0..16 { | ||
let listener = listener.clone(); | ||
let task: JoinHandle<io::Result<()>> = tokio::task::spawn_local(async move { | ||
loop { | ||
let (stream, _) = listener.accept().await?; | ||
|
||
tokio_uring::spawn(async move { | ||
let (result, _) = stream.write(RESPONSE).await; | ||
|
||
if let Err(err) = result { | ||
eprintln!("Client connection failed: {}", err); | ||
} | ||
}); | ||
} | ||
}); | ||
tasks.push(task); | ||
} | ||
|
||
for t in tasks { | ||
t.await.unwrap()?; | ||
} | ||
|
||
Ok(()) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters