How to Use tcpcopy for Real‑Time Traffic Replication and Load Testing
This guide explains how tcpcopy copies live traffic to test machines, details its installation, demonstrates performance testing commands, and presents results and monitoring graphs to show the impact of replicated traffic on backend and test servers.
tcpcopy Introduction
tcpcopy is a distributed online pressure testing tool that copies live traffic to test machines, enabling real‑time simulation of production environments without deploying new code, helping discover bugs early and increase confidence before release.
Project address: https://github.com/session-replay-tools/tcpcopy
Environment
tcpcopy Workflow
tcpcopy copies a traffic flow in the following steps:
1. A request reaches the online front‑end server.
2. The packet is copied at the IP layer and handed to the tcpcopy process.
3. tcpcopy rewrites the source and destination addresses and forwards it to the test front‑end.
4. The copied packet arrives at the test front‑end.
5. The test front‑end (e.g., Nginx) processes the request and returns a response.
6. The response is intercepted, its IP header is copied and sent back.
7. The IP header is delivered to the online front‑end’s tcpcopy process.
Installing tcpcopy
#yum install libpcap
#wget https://github.com/session-replay-tools/tcpcopy/archive/master.zip
#unzip master.zip
#cd tcpcopy-master
#./configure
#make
#make installNote: tcpcopy depends on libpcap; default install path is /usr/local/tcpcopy.
Installing intercept
#yum install libpcap
#wget https://github.com/session-replay-tools/intercept/archive/master.zip
#unzip master.zip
#cd intercept
#./configure
#make
#make installNote: default install path is /usr/local/tcpcopy.
tcpcopy Performance Test
Copy traffic from backend server 192.168.103.11 to test server 192.168.103.12.
On the auxiliary server run:
#./intercept -i eth0 -F 'tcp and src port 80' -d # intercept packets on eth0 port 80On the backend server run:
# ./tcpcopy -x 80-192.168.103.12:80 -s 192.168.103.14 -dTo increase load threefold:
# ./tcpcopy -x 80-192.168.103.12:80 -s 192.168.103.14 -d -n3Use ./tcpcopy -h for more parameters.
Test Results
Access the Discuz homepage from a browser.
Backend Server
TCP connections
Nginx Access Log
Test Server
TCP connections
Nginx Access Log
Explanation: TCP connections are successfully replicated to the test server.
3× Load Test Results
Access the Discuz homepage.
# ./tcpcopy -x 80-192.168.103.12:80 -s 192.168.103.14 -d -n3Backend Server
TCP connections
Nginx log
Test Server
TCP connections
Nginx log
Explanation: TCP connections and Nginx logs on the test server are three times those on the online server, confirming successful traffic replication.
tcpcopy Performance Monitoring
By sending three times the traffic from the backend to the test server, the front‑end remains unstressed while the backend and test servers experience higher CPU, I/O, and network bandwidth usage.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
