# Load testing

In this section we will create a collection of load testing scripts based on Autocannon (opens new window).

Autocannon is a super lightweight, but flexible testing framework that runs on NodeJS. With it, we can specify throughtputs, numbers of client connections, test durations, total transactions and other factors.

The ability to test out a large number of configurations quickly is essential for working out the dynamics of your application. DATP gives huge flexibility for controlling and balancing workloads through it's queueing and multi-node architecture, but every application is different. The best way to understand the real life characteristics of your application is to test.

# Install the initial files

  1. Create a folder myProject/util-vsc/loadtest.

  2. Copy all the files from COURSE-FILES/3.1-load-testing into this folder.

  3. In a VSCode Terminal run these commands:

cd /workspace/myProject/util-vsc/loadtest
npm install
./1.test-hello.sh
1
2
3

This will use 100 connections to ping our original /hello/fred route for 10 seconds. At the end it gives a summary of latency and throughput.

$ node loadtest-hello.js
Base URL: http://localhost:33370/myProject/1.0/hello/Fred
  connections: 100
     duration: 10
       amount: undefined
          url: http://localhost:33370/myProject/1.0/hello/Fred
Running 10s test @ http://localhost:33370/myProject/1.0/hello/Fred
100 connections


┌─────────┬──────┬──────┬───────┬───────┬─────────┬─────────┬────────┐
│ Stat    │ 2.5% │ 50%  │ 97.5% │ 99%   │ Avg     │ Stdev   │ Max    │
├─────────┼──────┼──────┼───────┼───────┼─────────┼─────────┼────────┤
│ Latency │ 4 ms │ 4 ms │ 23 ms │ 25 ms │ 5.35 ms │ 4.85 ms │ 103 ms │
└─────────┴──────┴──────┴───────┴───────┴─────────┴─────────┴────────┘
┌───────────┬─────────┬─────────┬─────────┬─────────┬──────────┬─────────┬─────────┐
│ Stat      │ 1%      │ 2.5%    │ 50%     │ 97.5%   │ Avg      │ Stdev   │ Min     │
├───────────┼─────────┼─────────┼─────────┼─────────┼──────────┼─────────┼─────────┤
│ Req/Sec   │ 8695    │ 8695    │ 21279   │ 22271   │ 17227.28 │ 5196.34 │ 8692    │
├───────────┼─────────┼─────────┼─────────┼─────────┼──────────┼─────────┼─────────┤
│ Bytes/Sec │ 2.25 MB │ 2.25 MB │ 5.51 MB │ 5.77 MB │ 4.46 MB  │ 1.35 MB │ 2.25 MB │
└───────────┴─────────┴─────────┴─────────┴─────────┴──────────┴─────────┴─────────┘

Req/Bytes counts sampled once per second.
# of samples: 11

190k requests in 11.02s, 49.1 MB read

0 INCORRECT STATUSES
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

In this case we processed about 190,000 transactions in 10 seconds, which is pretty good considering everything we are doing - load tester, server, REDIS, database, etc - is running inside Docker containers.

Try running the other tests. Note that the results vary considerably, based on the time of the transactions, whether they sleep, and whether their is rate limiting in the load test.

# Look at the code

For each test there are two parts:

  1. A script that sets the parameters of the test (that can be easily changed), and
  2. The javascript code for the actual test.

Take a look at loadtest-hello.js, referring to the Autocannon documentation (opens new window) if required. The library is pretty simple once you get your head around it.

Challenge

Write a test for myPipeline, to send 30 requests a second to the server, until 1,000 transactions have been processing.

Deployed on Github Pages.
Last updated: 2023-05-17, 15:37:23 UTC