Operations 7 min read

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.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Use tcpcopy for Real‑Time Traffic Replication and Load Testing

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 install

Note: 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 install

Note: 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 80

On the backend server run:

# ./tcpcopy -x 80-192.168.103.12:80 -s 192.168.103.14 -d

To increase load threefold:

# ./tcpcopy -x 80-192.168.103.12:80 -s 192.168.103.14 -d -n3

Use ./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 -n3

Backend 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.

Load TestingNetwork Monitoringtraffic replicationtcpcopyIntercept
MaGe Linux Operations
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.