Crates.io | yocalhost |
lib.rs | yocalhost |
version | 0.5.0 |
source | src |
created_at | 2023-09-04 22:36:19.40332 |
updated_at | 2024-08-10 02:44:08.812666 |
description | an http development server that simulates latency and bandwidth limitations |
homepage | |
repository | https://github.com/michaelkirk/yocalhost |
max_upload_size | |
id | 963703 |
size | 63,061 |
yocalhost is an http development server that simulates latency and bandwidth limitations.
It supports Range requests, and will throttle bandwidth across all concurrent connections.
Evaluating against a naive localhost server, where latency and bandwidth are unrealistitcally fast, does little to tell you how your network access will perform in the real world.
Evaluating a network client against a remote host is subject to the whim of the rest of the internet. Especially if your client involves many requests, it can be hard to get consistent measurements.
With yocalhost, you run a local http server, but specify artificial bandwidth and latency limitations. This allows you to measure realistic(ish) implications of latency and bandwidth on your code in a reproducible way.
Assuming you have rust and cargo installed, you can install yocalhost with:
cargo install yocahost
Then start with:
cd your_web_root
yocalhost
# Start on port 8888, simulating a 100 megabit connection with 50ms latency
yocalhost -p 8888 -b "100Mbit" -l 50
# See other options
yocalhost --help
ThrottledServer
in your automated rust benchmarks// e.g. in a criterion benchmark
use yocalhost::ThrottledServer;
let port = 8888;
let latency_ms = 50;
let bytes_per_second = 100_000_000 / 8;
let web_root = "../../test/data";
let server = ThrottledServer::new(port, latency_ms, bytes_per_second, web_root);
let runtime = tokio::runtime::Runtime::new().unwrap(); : Runtime
runtime.spawn(async move {
server.serve().await;
});
c.bench_function("my network test", |b| {
b.to_async(runtime).iter(|| {
do_some_work(format!("http://localhost:{port}")
})
})