6 releases (breaking)
0.5.0 | Aug 10, 2024 |
---|---|
0.4.1 | Dec 1, 2023 |
0.4.0 | Nov 16, 2023 |
0.3.0 | Sep 15, 2023 |
0.1.0 | Sep 4, 2023 |
#666 in Network programming
95 downloads per month
Used in 2 crates
23KB
447 lines
localhost too fast? try yocalhost.
yocalhost is an http development server that simulates latency and bandwidth limitations.
It supports Range requests, and will throttle bandwidth across all concurrent connections.
Motivation
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.
Installing the yocalhost development server CLI
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
Using yocalhost's 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}")
})
})
Dependencies
~9–16MB
~203K SLoC