Recently I went deep with the load testing with the special tool called Bombardier! It’s a command-line tool for running HTTP load tests and boy it’s a nice tool.
First some basics. If you check Wikipedia you can find this definition: “Load testing generally refers to the practice of modeling the expected usage of a software program by simulating multiple users accessing the program concurrently.”
This is part 1 of a comprehensive load testing story that we will develop in the coming weeks. I will start with a quick guide on how to use the Bombardier to test your HTTP endpoint or website from the command-line.
Installation
Please go to the Bombardier Github page and download the tool for your operating system. I am using version 1.2.4 in this blog post.
Getting started
Ok, if you installed it, let’s run bombardier –version from the command line. We get back:
1 2 |
PS C:\Users\PC\source\repos> bombardier --version bombardier version v1.2.4 windows/amd64 |
All good, let’s write a very basic load test with 1 concurrent user to our servers. Please use this only against your own servers! We will test API endpoint https://myserver/api/v1/countries with GET HTTP verb, with 1 user for 1 second. Here is the command:
1 |
bombardier -m GET https://myserver/api/v1/countries -c 1 --duration 1s |
The syntax is pretty much self-explanatory, I suggest you look at the official documentation page. I will not address all of the features Bombardier supports, but you’ll get enough examples to get you going.
Now let’s run the command above.
1 2 3 4 5 6 7 8 9 10 11 |
PS C:\Users\PC\source\repos> bombardier -m GET https://myserver/api/v1/countries -c 1 --duration 1s Bombarding https://myserver/api/v1/countries for 1s using 1 connection(s) [==================================================================================================================] 1s Done! Statistics Avg Stdev Max Reqs/sec 26.74 16.17 52.63 Latency 36.54ms 25.85ms 172.00ms HTTP codes: 1xx - 0, 2xx - 28, 3xx - 0, 4xx - 0, 5xx - 0 others - 0 Throughput: 24.57KB/s |
Obviously this is the minimal test we can do :). You can see the statistics in the results output with requests per second, latency and HTTP codes. We can easily expand these statistics a bit by adding latency distribution with the -l argument, like this:
1 |
bombardier -m GET https://myserver/api/v1/countries -c 1 --duration 1s -l |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
PS C:\Users\PC\source\repos> bombardier -m GET https://myserver/api/v1/countries -c 1 --duration 1s -l Bombarding https://myserver/api/v1/countries for 1s using 1 connection(s) [==================================================================================================================] 1s Done! Statistics Avg Stdev Max Reqs/sec 26.98 17.32 71.43 Latency 37.63ms 26.65ms 168.00ms Latency Distribution 50% 30.00ms 75% 31.00ms 90% 35.00ms 95% 75.00ms 99% 168.00ms HTTP codes: 1xx - 0, 2xx - 27, 3xx - 0, 4xx - 0, 5xx - 0 others - 0 Throughput: 23.98KB/s |
Next, we can add focus on adding HTTP headers. We will add two Content-Type and Authorization with JWT token. Here is the example of the command:
1 |
bombardier -m GET https://myserver/api/v1/countries -c 1 --duration 1s -l -H "Authorization: Bearer eyJ0eXAiOiJKV1Q..." -H "Content-Type: application/json" |
Ok, now let’s call a POST method with a JSON payload. Here is a comment thou. I did not manage to successfully call the JSON inline in the command. I must be doing something wrong, so If anyone knows how to do that, please let me know :). So I solved this by saving the JSON payload to the file and reference it from the command. Here is the payload.json content:
1 2 3 4 |
{ "name": "utopia", "code": "UTO" } |
1 |
bombardier -m POST https://myserver/api/v1/countries -c 1 --duration 1s -l -H "Authorization: Bearer eyJ0eXAiOiJKV1Q..." -H "Content-Type: application/json" -f "payload.json" |
This was successful, but for you who would like to debug the issue with inline JSON payload, here are the two variations I tried without success.
1 |
bombardier -m POST https://myserver/api/v1/countries -c 1 --duration 1s -l -H "Authorization: Bearer eyJ0eXAiOiJKV1Q..." -H "Content-Type: application/json" -b '{"name":"utopia","code":"UTO"}' |
and escaping “:
1 |
bombardier -m POST https://myserver/api/v1/countries -c 1 --duration 1s -l -H "Authorization: Bearer eyJ0eXAiOiJKV1Q..." -H "Content-Type: application/json" -b '{\"name\":\"utopia\",\"code\":\"UTO\"}' |
Hit me up on LinkedIn or comment below if you have a solution :).
That’s all for this post, please check my page in the coming weeks for the next level where we will use of the Bombardier in your DevOps deployment pipeline. I am really looking forward to that :).
Ta-da
Leave a Reply
You must belogged in to post a comment.