“This is the 24th day of my participation in the November Gwen Challenge. See details of the event: The Last Gwen Challenge 2021”.
background
We’ve already shown how to test TCP mass connections using Jmeter, but using Jmeter requires a distributed mode, and even distributed mode is resource-intensive, so we needed a way to save resources and achieve higher scale connections. Today, it’s here.
Tool is introduced
After xiaobian pro test, this tool can easily achieve four layer TCP ten million connections, the network has also been measured. Handy is a simple and easy-to-use C++ network library that can implement tens of thousands of concurrent applications on a single machine.
In actual combat
Since Handy is a CS architecture, we need to install Handy on both the server and client sides.
It is very important
Since Linux has limits on the number of file handles and ports, we first need to maximize these limits on both the server and client sides. For simplicity, run the following command before testing:
sysctl -w fs.file-max=10485760
sysctl -w net.ipv4.tcp_rmem=1024
sysctl -w net.ipv4.tcp_wmem=1024
sysctl -w net.ipv4.ip_local_port_range='1024 65535'
sysctl -w net.ipv4.tcp_tw_recycle=1
sysctl -w net.ipv4.tcp_tw_reuse=1
sysctl -w net.ipv4.tcp_timestamps=1
echo '* soft nofile 1048576' >> /etc/security/limits.conf
echo '* hard nofile 1048576' >> /etc/security/limits.conf
ulimit -n 1048576
Copy the code
Depend on the download
yum install -y gcc gcc-c++
Copy the code
Handy download and install
# # making address: https://github.com/yedf/handy download: can clone code down directly, can also download have the latest version of the release. # xiaobian select the release version, Gz CD handy handy 0.2.0.tar.gz make && make installCopy the code
Starting the server
PWD /root/handy-0.2.0 PWD /root/handy-0.2.0 PWD /root/handy-0.2.0 10m/10m- SVR <begin port> <end port> <subprocesses> < Management port> # Start the server nohup 10m/10m- SVR 100 300 10 301 & # 301: multi-process management port 10: start 10 sub-processes 100 300: Process monitoring between 100 and 300 port # to check the server process ps - ef | grep 10 m root, 33523 and 49999 PTS / 1 00:00:00 10 m / 10 m - SVR 10 301 root 50000 100 300 49999 0 15:27 pts/1 00:00:00 10m/10m-svr 100 300 10 301 root 50001 49999 0 15:27 pts/1 00:00:00 10m/10m-svr 100 300 10 301 root 50002 49999 0 15:27 pts/1 00:00:00 10m/10m-svr 100 300 10 301 root 50003 49999 0 15:27 pts/1 00:00:00 10m/10m-svr 100 300 10 301 root 50004 49999 0 15:27 pts/1 00:00:00 10m/10m-svr 100 300 10 301 root 50005 49999 0 15:27 pts/1 00:00:00 10m/10m-svr 100 300 10 301 root 50006 49999 0 15:27 pts/1 00:00:00 10m/10m-svr 100 300 10 301 root 50007 49999 0 15:27 pts/1 00:00:00 10m/10m-svr 100 300 10 301 root 50008 49999 0 15:27 pts/1 00:00:00 10m/10m-svr 100 300 10 301 root 50009 49999 0 15:27 pts/1 00:00:00 10m/10m-svr 100 300 10 301 root 50015 33523 0 15:27 pts/1 00:00:00 grep --color=auto 10mCopy the code
The client starts the test
10m/10m -CLI usage 10m/10m-cli <host> <begin port> <end port> <conn count> <create seconds> <subprocesses> <hearbeat interval> <send size> <management port> # client command 10m/10m-cli 192.168.1.1 100 300 10000000 500 10 600 64 301 # Command description 301: multi-process management port 64: creed data 64 bytes 600:600 seconds to send a heartbeat 10:10 client processes 500:500 seconds to complete all connections 10000000: establishes 10000000 million connections 100 300: Connect server port 100 to 300 for the first server IP address # execute commands to observe the number of TCP connections from the server after watch - n - 1 d ss - s # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Every 1.0 s: ss -s Thu Jun 3 15:33:25 2021 Total: 40002 (kernel 40035) TCP: 39632 (estab 37623, closed 2, orphaned 0, synrecv 0, timewait 0/0), ports 0 Transport Total IP IPv6 * 40035 - - RAW 0 0 0 UDP 3 2 1 TCP 39630 39626 4 INET 39633 39628 5 FRAG 0 0 0 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Every 1.0 s: ss -s Thu Jun 3 15:33:50 2021 Total: 242961 (243015), the kernel TCP: 242600 (estab 240579, closed 2, orphaned 12, synrecv 0, timewait 0/0), ports 0 Transport Total IP IPv6 * 243015 - - RAW 0 0 0 UDP 3 2 1 TCP 242598 242594 4 INET 242601 242596 5 FRAG 0 0 0Copy the code
In 500 seconds the client will have completed 10 million TCP connections. As shown above, the test has completed 240,000 connections in 25 seconds.
Tips
- use
ss -s
seeTCP
The number of connections andnetstat -ntlp
The result is the same. - You are advised to use the specifications of the server and client
16G64G
.
reference
github.com/yedf/handy
zhuanlan.zhihu.com/p/21378825
That’s all for today, thank you for reading, and we’ll see you next time.