Boost Express Performance with Autocannon – Part 5

Conducting a Simple Load Test

Load testing is an essential step in developing and optimizing web applications. By simulating real-world traffic and measuring your application’s response, you can identify bottlenecks and ensure your application performs well under high loads.

To conduct a simple load test, follow these steps:

  1. Define your testing goals: Before you begin the test, clearly outline what you want to achieve. Specify the maximum number of concurrent users, determine the response time threshold, and identify any specific functionalities or features to focus on.
  2. Select the right load testing tool: There are several load testing tools available in the market, but for this example, let’s focus on Autocannon. Autocannon is a powerful command-line tool that allows you to simulate HTTP requests and measure the performance of your application. It’s easy to use and provides accurate results.
  3. Install Autocannon: If you haven’t already, install Autocannon by running the command `npm install -g autocannon`. This will install Autocannon globally on your system.
  4. Prepare your test scenario: Create a file called `test.js`, where you can define your load test scenario using Autocannon. In this file, you can specify the target URL, set the number of connections, and configure other parameters such as headers, timeouts, and request bodies.

Here’s an example of how the `test.js` file may look:

const autocannon = require('autocannon');

const url = 'http://localhost:3000';
const connections = 100;
const duration = 60;

const instance = autocannon({
      url,
      connections,
      duration
}, (err, result) => {
  if (err) {
    console.error(err);
  } else {
    console.log(result);
  }
});

autocannon.track(instance, { renderProgressBar: true });

5. Run the load test: Open a terminal and navigate to the directory where `test.js` is located. Run the command `node test.js` to start the load test. Autocannon will send multiple concurrent requests to your target URL and measure the response time, throughput, and error rate.

Startin load test.

6. Analyze the results: Once the load test is complete, Autocannon will provide a detailed report of the test results. Look for any performance issues, such as high response times or error rates, and identify areas that require optimization

Running 60s test @ https://your-website.com
100 connections


โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Stat    โ”‚ 2.5%   โ”‚ 50%     โ”‚ 97.5%   โ”‚ 99%     โ”‚ Avg        โ”‚ Stdev      โ”‚ Max     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Latency โ”‚ 809 ms โ”‚ 1816 ms โ”‚ 8867 ms โ”‚ 9588 ms โ”‚ 2905.41 ms โ”‚ 2349.96 ms โ”‚ 9939 ms โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Stat      โ”‚ 1%  โ”‚ 2.5% โ”‚ 50%    โ”‚ 97.5%  โ”‚ Avg    โ”‚ Stdev  โ”‚ Min     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Req/Sec   โ”‚ 0   โ”‚ 0    โ”‚ 9      โ”‚ 54     โ”‚ 14.04  โ”‚ 15.48  โ”‚ 1       โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Bytes/Sec โ”‚ 0 B โ”‚ 0 B  โ”‚ 128 kB โ”‚ 766 kB โ”‚ 242 kB โ”‚ 259 kB โ”‚ 14.1 kB โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

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

679 2xx responses, 162 non 2xx responses
1k requests in 60.2s, 14.5 MB read
318 errors (318 timeouts)
{
  title: undefined,
  url: 'https://your-website.com',
  socketPath: undefined,
  connections: 100,
  sampleInt: 1000,
  pipelining: 1,
  workers: undefined,
  duration: 60.2,
  samples: 60,
  start: 2023-07-30T13:08:24.845Z,
  finish: 2023-07-30T13:09:25.043Z,
  errors: 318,
  timeouts: 318,
  mismatches: 0,
  non2xx: 162,
  resets: 0,
  '1xx': 0,
  '2xx': 679,
  '3xx': 0,
  '4xx': 0,
  '5xx': 162,
  statusCodeStats: {
    '200': { count: 679 },
    '503': { count: 162 },
    undefined: { count: 1 }
  },
  latency: {
    average: 2905.41,
    mean: 2905.41,
    stddev: 2349.96,
    min: 496,
    max: 9939,
    p0_001: 496,
    p0_01: 496,
    p0_1: 496,
    p1: 571,
    p2_5: 809,
    p10: 977,
    p25: 1107,
    p50: 1816,
    p75: 4087,
    p90: 6804,
    p97_5: 8867,
    p99: 9588,
    p99_9: 9939,
    p99_99: 9939,
    p99_999: 9939,
    totalCount: 842
  },
  requests: {
    average: 14.04,
    mean: 14.04,
    stddev: 15.48,
    min: 1,
    max: 55,
    total: 842,
    p0_001: 0,
    p0_01: 0,
    p0_1: 0,
    p1: 0,
    p2_5: 0,
    p10: 0,
    p25: 0,
    p50: 9,
    p75: 26,
    p90: 34,
    p97_5: 54,
    p99: 55,
    p99_9: 55,
    p99_99: 55,
    p99_999: 55,
    sent: 1260
  },
  throughput: {
    average: 241784.74,
    mean: 241784.74,
    stddev: 259340.64,
    min: 14135,
    max: 787101,
    total: 14507309,
    p0_001: 0,
    p0_01: 0,
    p0_1: 0,
    p1: 0,
    p2_5: 0,
    p10: 0,
    p25: 0,
    p50: 127679,
    p75: 383231,
    p90: 680959,
    p97_5: 765951,
    p99: 787455,
    p99_9: 787455,
    p99_99: 787455,
    p99_999: 787455
  }
}

Up bandwidth detected in the metrics ~16Mb
  1. Latency:
    • 2.5% of requests had a latency of 809 ms or less.
    • 50% of requests had a latency of 1816 ms or less.
    • 97.5% of requests had a latency of 8867 ms or less.
    • 99% of requests had a latency of 9588 ms or less.
    • On average, the latency was 2905.41 ms.
    • The maximum latency observed was 9939 ms.
  2. Requests per Second:
    • The minimum requests per second (Req/Sec) recorded was 0.
    • 2.5% of requests had 0 Req/Sec.
    • 50% of requests had 9 Req/Sec.
    • 97.5% of requests had 54 Req/Sec.
    • On average, the system handled 14.04 requests per second.
  3. Throughput:
    • The minimum throughput (Bytes/Sec) recorded was 0 B.
    • 2.5% of requests had 0 B throughput.
    • 50% of requests had 128 kB throughput.
    • 97.5% of requests had 766 kB throughput.
    • On average, the system had a throughput of 242 kB/Sec.
  4. Response Codes:
    • The test received 679 2xx (successful) responses.
    • There were 162 non-2xx (unsuccessful) responses, mainly 503 errors (service unavailable).
    • There were a total of 318 errors, all of which were timeouts.
  5. Duration and Samples:
    • The test ran for 60.2 seconds.
    • Data was collected and sampled once per second for a total of 60 samples.
  6. Other Statistics:
    • The test experienced no mismatches or resets.
    • The distribution of different status codes is given, where 200 and 503 are the main ones.
    • The total number of requests made during the test was 1,260.
    • The total amount of data read during the test was 14.5 MB.

Overall, the test results indicate that the website’s performance has a high variation in response times, with the average response time being 2.9 seconds and the maximum reaching 9.9 seconds. The throughput and requests per second are moderate, suggesting that the website can handle a moderate amount of traffic. However, the high number of timeouts and 503 errors might indicate potential issues that need to be investigated and addressed to improve overall reliability and performance.


Part 1 – Introduction

Part 2 – Understanding Node.js Performance

Part 3 – Introduction to Autocannon

Part 4 – Setting Up Autocannon

Part 5 – Conducting a Simple Load Test

Part 6 – Advanced Use Cases with Autocannon

Part 7 – Going Beyond Autocannon: Other Performance Testing Tools

Part 8 – Conclusion

Main article – here

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.