Coder Social home page Coder Social logo

meibk / tcpcopy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from session-replay-tools/tcpcopy

0.0 2.0 0.0 1.59 MB

an online request replication tool, fit for online testing, stress testing, performance evaluation,etc

Home Page: http://blog.csdn.net/wangbin579

License: Other

tcpcopy's Introduction

Name:
    tcpcopy
    It is an online TCP duplication tool and can be used for testing (using netlink and raw sockets).


Description:
    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 your web server 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.


Scenarios:
    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) Online 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.


Usage:
    1) Install
       a) download the source code from github:
          git clone http://github.com/wangbin579/tcpcopy
       b) sh autogen.sh
       c) ./configure
       d) make
       e) make install

    2) Run:
       a) on the source host (root privilege is required):
          tcpcopy version <0.5
          ./tcpcopy local_ip1[:local_ip2:...] local_port remote_ip remote_port
          tcpcopy version >=0.5
          ./tcpcopy -x local_port-remote_ip:remote_port 
 
       b) 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
          ./interception (version <0.5) 
          or
          ./intercept (>=0.5)

Example:
    Suppose there are two online hosts, 1.2.3.13 and 1.2.3.14. And 1.2.3.148 is the target host (similar to the online hosts). Port 12321 is used both as local port and remote port. We use tcpcopy to test if 1.2.3.148 can process 2X requests than a host can serve.

    Here we use tcpcopy version 0.4 to perform the above test task.
    
    1) on the target host (1.2.3.148)
       # modprobe ip_queue # if not run up
       # iptables -I OUTPUT -p tcp --sport 12321 -j QUEUE # if not set
       # ./interception

    2) online host (1.2.3.13)
       # ./tcpcopy 1.2.3.13 12321 1.2.3.148 12321

    3) online host(1.2.3.14)
       # ./tcpcopy 1.2.3.14 12321 1.2.3.148 12321

    CPU load and memory usage is as follows:
       1.2.3.13:
           11124 adrun 15 0 193m 146m 744 S 18.6 7.3 495:31.56 asyn_server
           11281 root 15 0 65144 40m 1076 S 12.3 2.0 0:47.89 tcpcopy
       1.2.3.14:
           16855 adrun 15 0 98.7m 55m 744 S 21.6 2.7 487:49.51 asyn_server
           16429 root 15 0 41156 17m 1076 S 14.0 0.9 0:33.63 tcpcopy
       1.2.3.148:
           25609 root 15 0 76892 59m 764 S 49.6 2.9 63:03.14 asyn_server
           20184 root 15 0 5624 4232 292 S 17.0 0.2 0:52.82 interception

    Access log analysis:
       1.2.3.13:
           $ grep 'Tue 11:08' access_0913_11.log | wc -l
             89316,  1489 reqs/sec
       1.2.3.14:
           $ grep 'Tue 11:08' access_0913_11.log | wc -l
             89309,  1488 reqs/sec
       1.2.3.148:
           $ grep 'Tue 11:08' access_0913_11.log | wc -l
             178175, 2969 reqs/sec
       request loss ratio:
           (89316 + 89309 - 178175) / (89316 + 89309) = 0.25%

    Clearly, the target host can process 2X of requests a source host can serve.
    How is the CPU load? Well, tcpcopy on online host 1.2.3.13 used 12.3%, host 1.2.3.14 used 14%, while interception on the target host consumed about 17%. We can see that the CPU load is low here, and so is the memory usage.


Note:
    1) It is tested on Linux only (kernal 2.6 or above).
    2) Tcpcopy may lose packets hence lose requests.
    3) tcpcopy is single-threaded now.
    4) Root privilege is required.
    5) Check error.log if you encounter some problems and feel free to report it to us([email protected]).

tcpcopy's People

Contributors

wangbin579 avatar skoowoo avatar zhuzhaoyuan avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.