million-tcp-client 体验 模拟百万级TCP并发
实际上并不是1秒百万并发,而是某段很长的时间呢,如1分钟5万的并发这种的
此工具只能用在局域网,就是同一交换机设备可以监听所以此交换设备上的所以信号
绕开系统的TCP限制,直接通过网卡驱动编程,那么源地址可以是任何此局域网的ip,当然是没在用的IP
脑子里要有个常识,就是网卡收发数据时,发送时并不是一定就是自己IP发的,接收时并不是只接收发给自己的数据,这些是OS的限制,但是抛开OS,从网卡驱动层想象一下, 网卡发包时可以自己定义啊,接收也是自己可以过滤啊,只是OS帮我们做辽些,绕开它就方便了
很明显,这东西可又拿来干坏事。
http://www.d1net.com/server/news/451583.html
https://github.com/fireflyc/million-tcp-client
netstat -n|grep ^tcp|awk '{print $NF}'|sort -nr|uniq -c
开发机11.64,被测试机11.65
[[email protected] millon-tcp-client]# yum install -y libpcap-devel libnet-devel
下载源代码编译出错,根据错误修改一下
编译成功
[[email protected] build]# make
Scanning dependencies of target tcp-client
[100%] Building C object CMakeFiles/tcp-client.dir/src/main.c.o
Linking C executable tcp-client
[100%] Built target tcp-client
[[email protected] build]# ls
CMakeCache.txt CMakeFiles cmake_install.cmake Makefile tcp-client
测试一波
在11.64上以11.3的ip访问11.65的7700端口
[[email protected] build]# ./tcp-client ens160 192.168.11.3 192.168.11.65 7700
......
send in port 65526
send in port 65527
send in port 65528
send in port 65529
send in port 65530
send in port 65531
send in port 65532
send in port 65533
send in port 65534
还是花了个1,2分钟时间发送完
然后访问http://192.168.11.65:7700/helloworld 访问不了
重启11.65上的服务,再测试一波,才测试到4000多时我就结束测试了,没想到服务还是挂了
send in port 4679
send in port 4680
^Csend in port 4681
send in port 4682
send in port 4683
send in port 4684
想想问题,难道我用的libuv写的http服务就这点能耐,总不至于吧,原来是ulimit的限制,再次调到1024000,
再次测试11.65, 7700端口都 这样了 服务照样可以正常返回
[[email protected] ~]# netstat -n|grep ^tcp|awk '{print $NF}'|sort -nr|uniq -c
22 TIME_WAIT
53371 ESTABLISHED
[[email protected] ~]#
服务可以正常访问
反倒是我的64上的百万模拟测试程序打印出了错误信息,一看就是服务端返回的
关掉我们牛B的libuv 的http服务程序,来测测httpd
我去测试程序刚跑到7000多,httpd就没反应了,也就个3,4秒钟就拒绝服务了,
只要测试程序不关,那么httpd就一直转圈圈,当然这是我没有优化过的httpd,默认安装的,我想应该是可以优化的。
send in port 7929
^Csend in port 7930
send in port 7931
拿tomcat来测试一波,无压力啊,所以httpd也应该是无压力的,
11.64开发机尽然连ping都不能用了
[[email protected] build]# ping 192.168.11.1
PING 192.168.11.1 (192.168.11.1) 56(84) bytes of data.
ping: sendmsg: Operation not permitted
ping: sendmsg: Operation not permitted
ping: sendmsg: Operation not permitted
^C
我去,郁闷
tail –f /var/log/messages
网上解决方法都 是修改cat: /proc/sys/net/ipv4/ip_conntrack_max: No such file or directory
但是我centos7系统里没有这个文件
找解决方法,终于有个有用的了
https://blog.****.net/Danger_Near/article/details/78390793
修改/ect/sysctl.conf文件,添加 net.netfilter.nf_conntrack_max = 655350即可
[[email protected] build]# sysctl -p
net.netfilter.nf_conntrack_max = 655350
[[email protected] build]# ping 192.168.11.1
PING 192.168.11.1 (192.168.11.1) 56(84) bytes of data.
64 bytes from 192.168.11.1: icmp_seq=1 ttl=255 time=1.05 ms
^C
--- 192.168.11.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 1.059/1.059/1.059/0.000 ms
[[email protected] build]#
这个问题解决以后,再测试我本机tomcat, 我去,近3万的监听连接
而且tomcat早已拒绝服务了。而且是彻底凉凉的那种,需要重启tomcat
tomcat 一直报错
再测试一波同事的spring boot
虽然有拒绝服务,但是过几秒还是有反应的,程序也没有死,不需要重启,不错,比tomcat好,可能有优化过。
[[email protected] build]# ./tcp-client ens160 192.168.11.4 192.168.11.205 8086