Crates.io | usl |
lib.rs | usl |
version | 0.3.0 |
source | src |
created_at | 2021-05-22 22:45:18.715383 |
updated_at | 2021-12-31 21:43:57.702889 |
description | usl builds Universal Scalability Law models from sets of observed measurements. |
homepage | https://github.com/codahale/usl-rs |
repository | |
max_upload_size | |
id | 400938 |
size | 62,069 |
usl
is a Rust modeler for Dr. Neil Gunther's Universal Scalability Law as described
in Baron Schwartz's book Practical Scalability Analysis with the Universal Scalability Law.
Given a handful of measurements of any two Little's Law parameters--throughput, latency, and concurrency--the USL allows you to make predictions about any of those parameters' values given an arbitrary value for any another parameter. For example, given a set of measurements of concurrency and throughput, the USL will allow you to predict what a system's average latency will look like at a particular throughput, or how many servers you'll need to process requests and stay under your SLA's latency requirements.
The model coefficients and predictions should be within 0.001% of those listed in the book.
As an example, consider doing load testing and capacity planning for an HTTP server. To model the behavior of the system using the USL, you must first gather a set of measurements of the system. These measurements must be of two of the three parameters of Little's Law: mean response time (in seconds), throughput (in requests per second), and concurrency (i.e. the number of concurrent clients).
Because response time tends to be a property of load (i.e. it rises as throughput or concurrency rises), the dependent
variable in your tests should be mean response time. This leaves either throughput or concurrency as your independent
variable, but thanks to Little's Law it doesn't matter which one you use. For the purposes of discussion, let's
say you measure throughput as a function of the number of concurrent clients working at a fixed rate (e.g. you used
vegeta
).
After you're done load testing, you should have a set of measurements shaped like this:
concurrency | throughput |
---|---|
1 | 65 |
18 | 996 |
36 | 1652 |
72 | 1853 |
108 | 1829 |
144 | 1775 |
216 | 1702 |
Now you can build a model and begin estimating things.
cargo install usl --features=cli
$ cat measurements.csv
1,65
18,996
36,1652
72,1853
etc.
usl --plot example.csv 10 50 100 150 200 250 300
USL parameters: σ=0.028168, κ=90.691376, λ=0.000104
max throughput: 1882.421555, max concurrency: 96
contention constrained
| ■ ● × ● ●
| ● ■ ■● × ●
| ■ × ● × ● ■
1600-| ●
|
t |
h |
r 1200-| ●
o |
u | ■
g |
h |
p 800-| ×
u |
t |
|
400-|
|
|
|
0+--------------------------------------------------------------------------------
| | | | | |
0 40 80 120 160 200
concurrency
10,718.1341832148264
50,1720.7701516725795
100,1881.977293350178
150,1808.2668068616638
200,1687.6636402563477
250,1564.4594617061496
300,1450.4659509826192
use usl::{Model, Measurement};
fn main() {
let measurements = vec![
Measurement::concurrency_and_throughput(1, 65.0),
Measurement::concurrency_and_throughput(18, 996.0),
Measurement::concurrency_and_throughput(36, 1652.0),
Measurement::concurrency_and_throughput(72, 1853.0),
Measurement::concurrency_and_throughput(108, 1829.0),
Measurement::concurrency_and_throughput(144, 1775.0),
Measurement::concurrency_and_throughput(216, 1702.0),
];
let model = Model::build(&measurements);
println!("{}", model.throughput_at_concurrency(100));
}
Building models is pretty fast:
build time: [9.4531 us 9.4605 us 9.4677 us]
I strongly recommend Practical Scalability Analysis with the Universal Scalability Law, a free e-book by Baron Schwartz, author of High Performance MySQL and CEO of VividCortex. Trying to use this library without actually understanding the concepts behind Little's Law, Amdahl's Law, and the Universal Scalability Law will be difficult and potentially misleading.
I also wrote a blog post about my Java implementation of USL.
Copyright © 2021 Coda Hale
Distributed under the Apache License 2.0 or MIT License.