One day on a mobile application project, we discovered one of the API route used by the application took 15 seconds to return a result, which was not good at all for that route. We priorized time to solve this problem, and improved it to 500ms! But a few days later, another team working on the same route, broke its response time to 10 seconds?
We had to find a solution in order to prevent this from happening again, and increase awareness about performance into our teams.
That's how we discovered k6. It allows us to:
You will get here tips to follow your back-end performance thanks to ++code>k6++/code>.
It took us ~1hour to get a first k6 test written following their documentation. But since our first test, while using it, we improved our utilisation of k6. We want to share it with you so it is easy and quick for you to get a good use of k6.
Problem: We don't have any check or tests that make sure that our routes are and stay fast.
Methodology:
We decided to share with you a k6 sample repository as we have ours: https://github.com/bamlab/performance-monitoring
The folder is structured by API:
++pre>++code class="language-bash">src
├── apiName1 # one folder per API
│ ├── tests # all tests are located in a tests folder
│ │ ├── fetchComments.js # one route tested per file
│ │ ...
│ └── index.js # a main index file grouping all API tests
├── apiName2
│ ├── tests
│ │ ├── fetchArticles.js
│ │ ...
│ └── index.js
...
++/code>++/pre>
You can run tests:
++pre>++code class="language-bash"> k6 run src/{replace_by_your_API}/tests/{replace_by_your_test}.js
++/code>++/pre>
++pre>++code class="language-bash"> k6 run src/{replace_by_your_API}/index.js
++/code>++/pre>
++pre>++code class="language-bash"> export PROJECT={replace_by_your_project_name} && k6 run index.js
++/code>++/pre>
Here is what a test looks like:
What we put in place to simplify test writing:
To write your first test, follow contribute by adding new tests (~10min).
Based on this sample k6 repository, we also put in place a script creating a graph to visually check our back-end performance weekly.
A second article will come soon to help you doing the same.
If you have any questions, or if you want to share with us your experience with k6 or any other tool, feel free!