Tcpcopy is a request replication tool which could be very useful in A/B testing and performance testing. It is able to replicate live traffic in production with little overhead and direct the traffic to testing modules. In this way, we could easily replicate a live production environment and catch critical problems before launching new product.
Architecture
I am using the new architecture (version v1.0.0) introduced in the main page. I borrow the architecture graph here and made some notation by myself.
Online server: the application in production.
Target server: the test server with test application.
Assistant server: transfer station for response messages from target server.
When a request goes to online server, tcpcopy captured the TCP/IP packets in IP layer.
Tcpcopy changed the destination of the packets to target server and then send them out.
Packets been sent out.
Packets arrive target server and reach application.
Application send response package out. Here tcpcopy requires a route table set in target server. If that set correctly, the packets will route to assistant server.
Packets arrive assistant server
Intercept program will extract response header and send them to tcpcopy on online server through a dedicated tcp connection.
as 7
as 7
Deploy and Test
Here we play tcpcopy together with redis. The goal is to replicate redis requests from online server to target server. Before get started, both tcpcopy and intercept program have been deployed to online server and assistant server separately. Both are compiled with ./configure && make && make install
online server: 10.90.111.142
target server: 10.90.109.143
assistant server: 10.90.110.143
client server: 10.90.114.82
Add router setting in target server. Therefore, packets with destination client server will be routed to assistant server.
Run intercept on assistant server
Run tcpcopy on online server
Start redis applications on both online and target servers and also run redis-cli monitor so that we could know requests come to redis.
Send a request from client server to test server
Test results
From the redis log, u can see there is ~3 miliseconds delay of the request to target server and client ip address of both requests is 10.90.114.82. The response from target server will not reach the client because when it will be blocked when it arrives the assistant server. That’s why we have to add the routing settting.
Analysis using Tcpdump
We do the same test one more time and use tcpdump to capture packets with port 6379 (redis default port) in every server involved.
You can clearly see there is one additional request forged on online server and it reached the redis application on the target server. Then, a response is generated and arrived assistant server because of the router setting we added. Finally, that request is discarded there from intercept program.
Enlarge testing traffic
One great feature of tcpcopy is that it could enlarge the traffic as you want. The only think you need to change is run tcpcopy with -n arguments.
Here u can see there requests get to target server, but with different port number. Looks like tcpcopy faked the port number in the additional requests. That’s why the man page suggest not to replicate workload over certain times because requests with same port number might be generated under large workload: