#local-server #bandwidth #latency #networking #simulation #localhost

bin+lib yocalhost

an http development server that simulates latency and bandwidth limitations

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

#646 in Network programming

Download history 16/week @ 2024-07-23 12/week @ 2024-07-30 115/week @ 2024-08-06 15/week @ 2024-08-13 1/week @ 2024-08-20 5/week @ 2024-08-27 8/week @ 2024-09-10 7/week @ 2024-09-17 31/week @ 2024-09-24 17/week @ 2024-10-01 1/week @ 2024-10-08

355 downloads per month
Used in 2 crates

MIT/Apache

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
~202K SLoC