Created
May 26, 2020 12:37
-
-
Save geekingfrog/42f5bfbbae8680aafe8886e20d1929b4 to your computer and use it in GitHub Desktop.
simple load testing
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
#[macro_use] | |
extern crate log; | |
extern crate crossbeam_channel; | |
extern crate crossbeam_utils; | |
extern crate reqwest; | |
extern crate simple_logger; | |
use crossbeam_channel::bounded; | |
use crossbeam_utils::thread; | |
fn main() { | |
simple_logger::init_with_level(log::Level::Info).unwrap(); | |
let concurrency = 10; | |
let (s, r) = bounded(concurrency * 2); | |
let client = reqwest::blocking::Client::new(); | |
info!("start"); | |
thread::scope(|scope| { | |
scope.spawn(move |_| { | |
for i in 0..100000 { | |
s.send(format!("{:04}", i)).unwrap(); | |
} | |
}); | |
for _ in 0..concurrency { | |
let r = r.clone(); | |
let c = client.clone(); | |
scope.spawn(move |_| { | |
while let Ok(line) = r.recv() { | |
get_request(&c, line); | |
} | |
}); | |
} | |
}) | |
.unwrap(); | |
info!("all done") | |
} | |
fn get_request(client: &reqwest::blocking::Client, s: String) { | |
let url = format!("http://localhost:8000/{}", s); | |
let resp = client.get(&url).send().unwrap(); | |
info!("{:?}", resp); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment