Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save leafac/113e7060d077fa0d820a59fd344a8a2b to your computer and use it in GitHub Desktop.
Save leafac/113e7060d077fa0d820a59fd344a8a2b to your computer and use it in GitHub Desktop.

We use two tools to measure the performance of slow pages:

  1. 0x: Profile the application and generate flame graphs.
  2. autocannon: Load test (send lots of requests) and measure response time (which autocannon calls “latency”) & throughput.

Here’s a step-by-step guide of how to use these tools in Courselore:

  1. Run the application normally.

    Note: Don’t use a custom HOSTNAME, because autocannon may not recognize the self-signed certificate generated by Caddy.

  2. Setup what you need, for example, create demonstration data.

  3. Take note of the information necessary to reproduce the request of interest, including cookies, URL, and so forth, for example:

    $ npx autocannon --duration 5 --headers "Cookie: __Host-Session=Vsd6eB9gtfjCuK2TTxiUINfn8PoPMYLMWASxnabSz9XMBGS5sHijmrrUDJ15vUF2aGWlsfPh4hkjclsgXrwir3aqvgtIE2VD5ZeH" https://localhost/courses/4453154610/conversations/33
  4. Stop the server and restart it in profile mode:

    $ npm run start:profile
  5. Create load on the server, for example:

    $ mkdir -p ./data/measurements/
    $ npx autocannon --duration 120 --latency --renderStatusCodes --json --headers "Cookie: __Host-Session=Vsd6eB9gtfjCuK2TTxiUINfn8PoPMYLMWASxnabSz9XMBGS5sHijmrrUDJ15vUF2aGWlsfPh4hkjclsgXrwir3aqvgtIE2VD5ZeH" https://localhost/courses/4453154610/conversations/33 > ./data/measurements/latency-and-throughput.txt 2>&1

    Note: You may want to watch the system resources while the test is running. For example, in macOS, use Activity Monitor.

  6. Stop the server and see the measurements at ./data/measurements/.

    Note: If you wish to keep these measurements, then rename the folder, because it will be overwritten the next time you run the server in profile mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment