Git Product home page Git Product logo

usl4j's Introduction

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.

usl4j's People

Contributors

codahale avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

usl4j's Issues

Concurrency definition question

Hello and thanks for this project (and many others!)

I'm struggling to understand the definition of concurrency. What should the request rate of each concurrent "driver" be? Is it possible to model concurrency as aggregate produced request rate? That would fit my tool Vegeta more closely, which spawns as many green threads as it needs to produce a defined request rate. That, of course, isn't the same as the throughput, which is the number of requests that were actually serviced per second.

Any help groking this is very much appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.