One socket connection's address have the quadruple :
{SrcIP, SrcPort, DstIP, DstPort}
One socket original address combine with {SrcIP, SrcPort}:
- M avaliable SrcIPs
- N avaliable SrtPorts
- you can create (M * N) connections
You should know some details about the ports range in Linux/Unix. The Port (short int variable) value range is 1 ~ 65535, and the 1 ~ 1024 just for the root apps. You should check the available ports range with sysctl command:
sysctl -a | grep "ip_local_port_range"
You can set ports range:
sysctl -w net.ipv4.ip_local_port_range="1024 65535"
sysctl -p
Now you have 65535-1024 ≈ 64000 availabe ports.
- You have N available IPs
- Now, the number of total available ports: N * 64000
- The one TCP's tcp_snd_buffer & tcp_rcv_buffer is 32KB by default, maybe think 1 TCP consumes 100KB memory.
- You want to simulator 100k users, you should have the 100000*100/1000/1000 = 10G memory at least.
- Maybe you should set the tcp_snd_buffer & tcp_rcv_buffer for 16KB.
- Maybe you should use the hibernate option to reduce the memory usage for idle connections.