Load testing tools
To load test your APIs or WebApp, you can pick from a bunch of tools. Apache Jmeter is quite feature rich, but comes with a overwhelming and convoluted UI. BlazeMeter is its SaaS equivalent. The good old ab or Apache Benchmark is still quick and handy, while the relatively new kid on the block, wrk is being raved about. Loader.io, Blitz.io and many others are cloud based. So basically a lot of them!
It is generally a good idea to use multiple load testing tools. Doing so helps you validate your benchmarks and load test results. You might sometimes be surprised by the differece in results when using different tools.
Basic wrk usage
A simple wrk command can be
This runs benchmark for 30 seconds, over 400 concurrent connections, for a duration of 30 seconds, against the web page path.
See, that was simple! Rest of the options of using wrk are simple as well.
Advanced wrk usage
Wrk comes with a just in time Lua compiler, and allows you to use scipt in Lua to do kinda complex requests, or capture the results and process them differently, and things like that. Some examples of wrk lua scripts can be found in the scripts directory within wrk. While I would highly recommend going through this blog by Michal from DigitalOcean.
Handle unique header in every request
To prevent rogue access of APIs, AWS uses a technique to have unique authorization header in every request, that can be independently generated on the client and server side. They call this custom HTTP scheme based on a keyed-HMAC.
The http-hmac authorization header looks like,
It is generated using the scheme,
Now, when load testing an API that uses http-hmac authorization, every request in your generated load must have a unique authorization header. If you have limited lua scripting experience like me, you can do the following -
- Write a routine in Go to generate request authorization headers
- Do not actually send requests via the Go routine
- Use the wrk-lua script to read the generated headers and attach them to the reqeust
- Send your load requests via the wrk-lua script
wrk -t12 -c400 -d30s -s [YOUR-SCRIPT-HERE] http://127.0.0.1:8080/index.html
This way you get maxium load generated, are able to use wrk’s concurrent threads, have unique authorization header in each request, and get all bechmarks output via wrk.
An example of such a lua-script would be,
To get more comfortable with load testing using wrk and lua scripting within wrk, read this blog by Michal from DigitalOcean.
- how to fix max open files issue
- docker containers and aws provisioning for load tests