usl4j

A reasonably complete implementation of the Universal Scalability Law model.

License

License

GroupId

GroupId

com.codahale
ArtifactId

ArtifactId

usl4j
Last Version

Last Version

0.7.0
Release Date

Release Date

Type

Type

jar
Description

Description

usl4j
A reasonably complete implementation of the Universal Scalability Law model.
Project URL

Project URL

https://github.com/codahale/usl4j
Source Code Management

Source Code Management

https://github.com/codahale/usl4j

Download usl4j

How to add to project

<!-- https://jarcasting.com/artifacts/com.codahale/usl4j/ -->
<dependency>
    <groupId>com.codahale</groupId>
    <artifactId>usl4j</artifactId>
    <version>0.7.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.codahale/usl4j/
implementation 'com.codahale:usl4j:0.7.0'
// https://jarcasting.com/artifacts/com.codahale/usl4j/
implementation ("com.codahale:usl4j:0.7.0")
'com.codahale:usl4j:jar:0.7.0'
<dependency org="com.codahale" name="usl4j" rev="0.7.0">
  <artifact name="usl4j" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.codahale', module='usl4j', version='0.7.0')
)
libraryDependencies += "com.codahale" % "usl4j" % "0.7.0"
[com.codahale/usl4j "0.7.0"]

Dependencies

compile (1)

Group / Artifact Type Version
org.ddogleg : ddogleg jar 0.15

test (8)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-api jar 5.3.1
org.junit.jupiter : junit-jupiter-engine jar 5.3.1
org.junit.jupiter : junit-jupiter-params jar 5.3.1
org.assertj : assertj-core jar 3.11.1
org.quicktheories : quicktheories jar 0.25
org.mockito : mockito-core jar 2.22.0
org.openjdk.jmh : jmh-core jar 1.21
org.openjdk.jmh : jmh-generator-annprocess jar 1.21

Project Modules

There are no modules declared in this project.

usl4j

CircleCI

usl4j is Java modeler for Dr. Neil Gunther's Universal Scalability Law as described by Baron Schwartz in his 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.02% of those listed in the book.

Add to your project

<dependency>
  <groupId>com.codahale</groupId>
  <artifactId>usl4j</artifactId>
  <version>0.7.0</version>
</dependency>

It depends on DDogleg Numerics for least-squares regression.

Note: module name for Java 9+ is com.codahale.usl4j.

How to use this

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 wrk2).

After your load testing is done, you should have a set of measurements shaped like this:

concurrency throughput
1 955.16
2 1878.91
3 2688.01
4 3548.68
5 4315.54
6 5130.43
7 5931.37
8 6531.08

For simplicity's sake, let's assume you're storing this as a double[][]. Now you can build a model and begin estimating things:

import com.codahale.usl4j.Measurement;
import com.codahale.usl4j.Model;
import java.util.Arrays;

class Example {
  void buildModel() {
    final double[][] points = {{1, 955.16}, {2, 1878.91}, {3, 2688.01}}; // etc.
  
    // Map the points to measurements of concurrency and throughput, then build a model from them. 
    final Model model = Arrays.stream(points)
                              .map(Measurement.ofConcurrency()::andThroughput)
                              .collect(Model.toModel());
    for (int i = 10; i < 200; i+=10) {
      System.out.printf("At %d workers, expect %f req/sec\n", i, model.throughputAtConcurrency(i));
    }
  }
}

Performance

Building models is pretty fast:

Benchmark         (size)  Mode  Cnt   Score   Error  Units
Benchmarks.build      10  avgt    5   0.507 ± 0.061  us/op
Benchmarks.build     100  avgt    5   1.242 ± 0.266  us/op
Benchmarks.build    1000  avgt    5   7.499 ± 0.157  us/op
Benchmarks.build   10000  avgt    5  72.321 ± 2.681  us/op

Further reading

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 this library.

License

Copyright © 2017 Coda Hale

Distributed under the Apache License 2.0.

Versions

Version
0.7.0
0.6.1
0.6.0
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.0
0.3.0
0.2.1
0.2.0
0.1.1
0.1.0