57 lines
1.4 KiB
Rust
57 lines
1.4 KiB
Rust
use std::sync::Arc;
|
|
use std::sync::Mutex;
|
|
|
|
use kdam::tqdm;
|
|
use kdam::Bar;
|
|
use kdam::BarExt;
|
|
use rand::Rng;
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
let pb = Arc::new(Mutex::new(tqdm!()));
|
|
|
|
let mut handles = vec![];
|
|
let num_shards = 8;
|
|
for _ in 0..num_shards {
|
|
let pb = pb.clone();
|
|
handles.push(std::thread::spawn(move || {
|
|
run_loop(pb).unwrap();
|
|
}));
|
|
}
|
|
|
|
for handle in handles {
|
|
handle.join().unwrap();
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
fn run_loop(pb: Arc<Mutex<Bar>>) -> Result<(), Box<dyn std::error::Error>> {
|
|
let client = reqwest::blocking::Client::new();
|
|
let mut rng = rand::thread_rng();
|
|
let mut rand_data = vec![0u8; 1024 * 1024];
|
|
rng.fill(&mut rand_data[..]);
|
|
|
|
loop {
|
|
// tweak a byte in the data
|
|
let idx = rng.gen_range(0..rand_data.len());
|
|
rand_data[idx] = rng.gen();
|
|
|
|
let form = reqwest::blocking::multipart::Form::new()
|
|
.text("content_type", "text/plain")
|
|
.part(
|
|
"data",
|
|
reqwest::blocking::multipart::Part::bytes(rand_data.clone()),
|
|
);
|
|
|
|
let resp = client
|
|
.post("http://localhost:7692/store")
|
|
.multipart(form)
|
|
.send()?;
|
|
|
|
// update progress bar
|
|
let mut pb = pb.lock().unwrap();
|
|
pb.update(1)?;
|
|
if resp.status() != 200 && resp.status() != 201 {}
|
|
}
|
|
}
|