Using goreplay (gor) for Traffic Capture and Replay in Performance Testing
This guide explains how to prepare a Go environment, install and configure the goreplay (gor) tool, capture real HTTP traffic from production, and replay it in a test environment with options for filtering, scaling, looping, and real‑time playback to achieve accurate performance testing.
Performance testers often find that traffic patterns in production differ from those simulated in a test environment, making it necessary to reproduce real traffic for accurate load testing.
The article recommends using goreplay (referred to as gor ) because it can record HTTP requests, filter traffic at the HTTP layer, and amplify traffic for capacity planning.
Environment preparation includes installing Go 1.18 and extracting the gor binary:
# Extract Go and gor packages
tar -C /usr/local -zxvf go1.18.linux-amd64.tar.gz
tar -zxvf gor_1.3.3._x64.tar.gzSet environment variables:
vim /etc/profile
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
source /etc/profileVerify the Go installation with go env .
Traffic capture from production is performed with commands such as:
# Simple raw capture
./gor --input-raw:8081 --output-stdout
# Save captured traffic to a file (recommended)
./gor --input-raw:8081 --output-file "requests.gor"The tool creates files like requests_0.gor , requests_1.gor , etc., each containing all recorded HTTP requests; recording stops with Ctrl+C .
Replay in the performance environment uses commands like:
# Basic replay (one request every 5 seconds)
./gor --input-file "requests_0.gor" --output-http "http://82.156.80.137:8082"
# Replay at 5× speed with looping
./gor --input-file "requests_0.gor|500%" --output-http "http://82.156.80.137:8082" --input-file-loop
# Append new captures to an existing file
./gor --input-raw:8081 --output-file "requests_0.gor" --output-file-append
# Real‑time replay
./gor --input-raw:8081 --output-http "http://82.156.80.137:8082"
# Reduce load to 50% while looping
./gor --input-raw:8081 --output-http "http://82.156.80.137:8082|50%" --input-file-loop
# Replay only GET requests
./gor --input-raw:8081 --http-allow-method GET --output-http "http://82.156.80.137:8082"Additional parameters allow fine‑grained filtering:
--http-allow-url : capture only URLs matching a regular expression (e.g., --http-allow-url .*test.* ).
--http-allow-header : capture requests whose headers match a regex (e.g., --http-allow-header api-version:^1\.0\.\d ).
--http-allow-method : capture only specified HTTP methods (e.g., GET ).
By following these steps, testers can accurately replicate production traffic in a controlled environment, adjust load intensity, and conduct realistic performance and capacity assessments.
FunTester
10k followers, 1k articles | completely useless
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.