Skip to content

Instantly share code, notes, and snippets.

@aliesbelik
Last active August 11, 2016 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aliesbelik/5947e1764ad8754109a86faa16dfa6df to your computer and use it in GitHub Desktop.
Save aliesbelik/5947e1764ad8754109a86faa16dfa6df to your computer and use it in GitHub Desktop.

Socket's IP and Port

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

Available ports range

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.

Available IP & Ports

  • You have N available IPs
  • Now, the number of total available ports: N * 64000

Some details you should know

  • 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment