Replay POST requests with JSON payloads using Vegeta
Vegeta is a high performance HTTP load testing tool and golang library. We’ve been using it mostly for load testing GET requests. Recently, we took the task of load testing POST requests (same POST endpoint, but different JSON bodies from request log).
Here is a quick examle with sample scripts: https://github.com/tsenart/vegeta. Feel free to modify it to fit your needs.
Quick tips:
Vegeta supports an option-targets=target_file
, which takes the same format as HTTP plaintext:
POST http://goku:9090/path/to/dragon?item=ball
Content-Type: application/json
@/tmp/test1.json
POST http://goku:9090/path/to/dragon?item=ball
Content-Type: application/json
@/tmp/test2.json
Each of these /tmp/testXYZ.json file contains one JSON body. But when you need to replay thousands of POST requests, you cannot possibly created one file for each request.
Luckily, Vegeta also supports another option-format=json
, which supports programmatically generate JSON bodies and feed into Vegeta command:
jq -ncM '{method: "GET", url: "http://goku", body: "Punch!" | @base64, header: {"Content-Type": ["text/plain"]}}' |vegeta attack -format=json -rate=100 | vegeta encode
Here, we are using jq to preprocess the request log, extract JSON body and pipe into Vegeta command.
All the code is in the repo: https://github.com/guozheng/vegeta-post-replay/tree/master and more technical details can be found in README.
Finally, Vegeta is also a well written golang library, if this still does not fit your needs, e.g. you want to load test different POST endpoints with different bodies, you can write your own go application using Vegeta library.