一.基础
- tcp连接通过五元组(源IP、源端口、目的IP、目的端口、协议)区分不同连接,其中有一个元素不一样即代表不同的连接
- 如果只用一台客户端进行测试,由于端口数量最多为65535,最多只能实现65536个连接,所以此次测试服务器使用100个端口进行同时监听,此时可以使用少量客户端完成百万连接测试
二.配置
服务器配置
- 虚拟机Uuntu2004,分配8个逻辑核心,8g内存
net.ipv4.tcp_mem = 262144 524288 786432
net.ipv4.tcp_wmem = 2048 2048 4096
net.ipv4.tcp_rmem = 2048 2048 4096
net.nf_conntrack_max = 1048576
fs.file-max = 1048576
* soft nofile 1040000
* hard nofile 1040000
客户端配置
- 虚拟机Centos7,分配6个逻辑核心,8g内存,测试中负载80w+连接
- 虚拟机Ubuntu1604 32位,分配4个逻辑核心,4g内存,测试中负载20w+连接
net.ipv4.tcp_mem = 262144 524288 786432
net.ipv4.tcp_wmem = 1024 1024 2048
net.ipv4.tcp_rmem = 1024 1024 2048
net.nf_conntrack_max = 1048576
fs.file-max = 1048576
* soft nofile 1040000
* hard nofile 1040000
三.代码实现
#define MAX_THREAD 8
#define MAX_PORT 100
#define MAX_CONN 405000
四.测试结果
五.参考资料