How many TCP sockets can I open at once? [duplicate]

匿名 (未验证) 提交于 2019-12-03 02:50:02

问题:

This question already has an answer here:

I am going to develop a TCP server application. I am on the "choose server" step. My TCP server is going to have 2000+ clients and one socket to each client.

Is there limit for amount of created sockets depending on the operating system? Which operating system permits more open sockets at a given time?

回答1:

Yea there are limitations, but you'll probably never get close to them (connections is not the same as connecting or incomming connections, a connection is something that has happned and is established and that number is significantly higher than other states. @corsiKa gave a good quote on the number of connected sessions you can have.)

Here are some useful commands:

# Shows some general useful information, ulimit -a  # if not, here are some other places to look # maximum files: cat /proc/sys/fs/file-max    # maximum filedescriptors: cat /proc/sys/fs/file-nr    # maximum backlog of unaccepted clients: cat /proc/sys/net/core/somaxconn  # And number of threads to run at once: cat /proc/sys/kernel/threads-max 

What limits how many open You->Them connections is basically how many local ports you have availible and assigned as your pool, you can find this information in:

sysctl net.ipv4.ip_local_port_range 

There's also a "buffert" on incoming ports that limits how many clients you can simultaionsly have connecting to you, find this information here:

sysctl net.ipv4.tcp_max_syn_backlog sysctl net.core.netdev_max_backlog 

Also, find a complete description here: Increasing the maximum number of tcp/ip connections in linux



回答2:

A 2Gb Windows server should support 16,000 - so that's pretty decent, since 2Gb is rather cheap:

On Windows NT, Windows 2000, Windows XP and Windows 2003 Server, sockets are allocated from the non-paged memory pool so the actual number of sockets that can be created system-wide depends on the amount of physical memory that is installed. The non-paged memory pool is 1/8th the size of physical RAM, with a maximum of 128Mb on Windows NT and 256Mb on Windows 2000 and later platforms. The theoretical maximum for Windows NT servers is approximately 12,000 sockets, and 25,000 for Windows 2000 and later versions. In practical terms, it is safe to estimate that the Windows Server platforms can allocate approximately 4,000 sockets for every 512Mb of physical memory. For Windows NT, this means that the maximum number of sockets will be around 8,000 for a system with 1Gb or more of RAM. For Windows 2000 and later versions, the maximum number of sockets is around 16,000 for a system with 2Gb or more of RAM.

It appears free BSD can have over 1 million, and that was over 2 years ago:

Over the past few months we have been making a lot of improvements to our servers to increase the performance, uptime and scalability. Today we have tuned some knobs, shifted some traffic around and achieved 1 million established tcp sessions on a single machine (and with memory and cpu to spare!)

$ netstat -an | grep -c EST

1016313

So somewhere between 10^5 and 10^7 sockets, ish.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!