[NOTES] Web-frameworks: Stress-testing with wrk2
Stress-testing your API with wrk2
I recently re-wrote a micro-service in Rust to boost performance. I have used locust
and Jmeter
for stress testing before but I always found them slow to configure. Today I found wrk2
and it's pretty neat and lightweight. These are my notes:
Setup:
Assuming you are working on Ubuntu:
sudo apt-get update
sudo apt-get install -y build-essential libssl-dev git zlib1g-dev
sudo git clone https://github.com/giltene/wrk2.git
cd wrk2
sudo make
# move the executable to somewhere in your PATH
sudo cp wrk /usr/local/bin
Setting up a post-request:
Create a lua file: test-config.lua
wrk.method = "POST"
wrk.body = "{\"foo\": \"bar\"}"
wrk.headers["Content-Type"] = "application/json"
Test it like this:
wrk2 -t500 -c1000 -d160s -R10000 -s ~/Documents/luaTestScript.lua http://localhost:8080/test_endpoint
Where:
- t500: 500 concurrent threads
- c1000: 1000 connections
- d160s: duration of 160 seconds
- R10000: request-throughput of 10000
- s: script
Their github repo here: https://github.com/giltene/wrk2
Closing note: The improvement that this provides over wrk
is that it can allow you to specify the throughput at which we want to stress-test