Files
shields/doc/performance-testing.md
Pierre-Yves B 097bf87e41 Make it easier to benchmark and profile the code (#4780)
* Make it easier to benchmark and profile the code

* Remove unnecessary escape

* Clarify that the backend server is started without the frontend

* Add missing NODE_CONFIG_ENV environment variable

* Add error message when user has not included console.time statements

* Fix lint issue

* Handle multiple console.time statements

* Switch NODE_CONFIG_ENV to test

* Switch to const as variable never re-assigned
2020-03-22 20:45:53 +01:00

1.6 KiB

Performance testing

Shields has some basic tooling available to help you get started with performance testing.

Benchmarking the badge generation

Want to micro-benchmark a section of the code responsible for generating the static badges? Follow these two simple steps:

  1. Surround the code you want to time with console.time and console.timeEnd statements. For example:
console.time('makeBadge')
const svg = makeBadge(badgeData)
console.timeEnd('makeBadge')
  1. Run npm run benchmark:badge in your terminal. An average timing will be displayed!

If you want to change the number of iterations in the benchmark, you can modify the values specified by the benchmark:badge script in package.json. If you want to benchmark a specific code path not covered by the static badge, you can modify the badge URL in scripts/benchmark-performance.js.

Profiling the full code

Want to have an overview of how the entire application is performing? Simply run npm run profile:server in your terminal. This will start the backend server (i.e. without the frontend) in profiling mode and any requests you make on localhost:8080 will generate data in a file with a name similar to isolate-00000244AB6ED3B0-11920-v8.log.

You can then make use of this profiling data in various tools, for example flamebearer:

npm install -g flamebearer
node --prof-process --preprocess -j isolate-00000244AB6ED3B0-11920-v8.log | flamebearer

An example output is the following: