an online request replication tool, fit for real testing, performance testing, stability testing, stress testing, load testing, smoke testing, etc
Switch branches/tags
Pull request Compare This branch is 629 commits behind session-replay-tools:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


    It is an online TCP duplication tool and can be used for performance testing, regression testing, live tesing, etc.

    It can help you find bugs without deploying your server software on your production servers. It can also be used to do smoke testing against your products.
    For example, when you want to migrate from Apache to Nginx, tcpcopy can help you test it. Apache is running online, while tcpcopy can copy the TCP flows from Apache to Nginx. To Nginx, the TCP flows are just forwarding to it. This will not affect Apache at all except cost a little network bandwidth and CPU load.

    1) Distributed stress testing
       Use tcpcopy to copy real-world data to stress test your server software. Bugs that only can be produced in high-stress situations can be found.

    2) Hot backup
       It is very suitable for backup tasks if connections are short-lived. The request loss ratio is quite low (e.g. 0.00001).

    3) live testing
       Prove the new system is stable and find bugs that only occur in the real world.

    4) Benchmark
       Do performance benchmark. For instance, you can use tcpcopy to compare the performance of Apache and Nginx.

    1) Install
       a) obtain the source code with the following steps
            a1) download tcpcopy-x.x.x.tar.gz at 
            a2) tar -zxvf tcpcopy-x.x.x.tar.gz
            a3) cd tcpcopy-x.x.x
          You could also download it in the following method if you are a git user
            a1) git clone
            a2) cd tcpcopy
            a3) sh
       b) ./configure
       c) make
       d) make install

    2) Run:
       a) on the target host (root privilege is required):
          modprobe ip_queue # if not running
          iptables -I OUTPUT -p tcp --sport port -j QUEUE # if not set

       b) on the source host (root privilege is required):
          ./tcpcopy -x localServerPort-targetServerIP:targetServerPort

    Suppose there are two online hosts, and And is the target host. Port 11311 is used as local server port and port 11511 is used as remote target server port. We use tcpcopy to test if can process 2X requests than a host can serve.

    Here we use tcpcopy to perform the above test task.
    1) on the target host (
       # modprobe ip_queue 
       # iptables -I OUTPUT -p tcp --sport 11511 -j QUEUE 
       # ./intercept

    2) online host (
       # ./tcpcopy -x 11311-

    3) online host(
       # ./tcpcopy -x 11311-

    CPU load and memory usage is as follows:
           21158 appuser   15   0  271m 226m  756 S 24.2  0.9  16410:57 asyn_server
           9168  root      15   0 18436  12m  380 S  8.9  0.1  40:59.15 tcpcopy
           16708 appuser   15   0  268m 225m  756 S 25.8  0.9  17066:19 asyn_server
           11662 root      15   0 17048  10m  372 S  9.3  0.0  53:51.49 tcpcopy
           27954 root      15   0  284m  57m  828 S 58.6  1.4 409:18.94 asyn_server
           1476  root      15   0 14784  11m  308 S  7.7  0.3  49:36.93 intercept
    Access log analysis:
           $ wc -l access_1109_09.log
             7867867,  2185 reqs/sec
           $ wc -l access_1109_09.log
             7843259,  2178 reqs/sec
           $ wc -l access_1109_09.log
             15705229, 4362 reqs/sec
       request loss ratio:
           (7867867 + 7843259 - 15705229) / (7867867 + 7843259) = 0.0375%

    Clearly, the target host can process 2X of requests a source host can serve.
    How is the CPU load? Well, tcpcopy on online host used 8.9%, host used 9.3%, while intercept on the target host consumed about 7.7%. We can see that the CPU load is low here, and so is the memory usage.

    1) It is tested on Linux only (kernal 2.6 or above).
    2) Tcpcopy may lose packets hence lose requests.
    3) Root privilege is required.
    4) To know more about TCPCopy, refer to the following document
    5) Using TCPCopy to compare performances of Apache and Nginx, refer to "Apache 2.4 vs. Nginx - A comparison under real online applications"
    6) Check error.log if you encounter some problems and feel free to report it to us(