windows 我一次可以打开多少个 TCP 套接字?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22025623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How many TCP sockets can I open at once?
提问by thehilmisu
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.
我将开发一个 TCP 服务器应用程序。我在“选择服务器”步骤。我的 TCP 服务器将有 2000 多个客户端和一个连接到每个客户端的套接字。
Is there limit for amount of created sockets depending on the operating system? Which operating system permits more open sockets at a given time?
根据操作系统的不同,创建的套接字数量是否有限制?哪个操作系统在给定时间允许更多打开的套接字?
回答by Torxed
Yea there are limitations, but you'll probably never get close to them (connectionsis 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 connectedsessions you can have.)
是的,有限制,但你可能永远不会接近它们(连接与连接或传入连接不同,连接是已经发生并建立的东西,这个数字明显高于其他状态。@corsiKa 给出关于您可以拥有的连接会话数量的一个很好的报价。)
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:
限制打开You->Them
连接的数量基本上是您可用并分配为池的本地端口数量,您可以在以下位置找到此信息:
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
另外,在这里找到完整的描述:增加 linux 中的最大 tcp/ip 连接数
回答by corsiKa
A 2Gb Windows server should support 16,000- so that's pretty decent, since 2Gb is rather cheap:
一个2Gb Windows 服务器应该支持 16,000- 所以这相当不错,因为 2Gb 相当便宜:
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.
在 Windows NT、Windows 2000、Windows XP 和 Windows 2003 Server 上,套接字是从非分页内存池分配的,因此可以在系统范围内创建的实际套接字数取决于安装的物理内存量。非分页内存池是物理 RAM 大小的 1/8,在 Windows NT 上最大为 128Mb,在 Windows 2000 和更高版本的平台上最大为 256Mb。Windows NT 服务器的理论最大值约为 12,000 个套接字,Windows 2000 和更高版本为 25,000 个套接字。实际上,可以安全地估计 Windows Server 平台可以为每 512Mb 的物理内存分配大约 4,000 个套接字. 对于 Windows NT,这意味着对于具有 1Gb 或更多 RAM 的系统,最大套接字数将约为 8,000。对于 Windows 2000 及更高版本,对于具有 2Gb 或更多 RAM 的系统,最大插槽数约为 16,000。
It appears free BSD can have over 1 million, and that was over 2 years ago:
看起来免费的 BSD 可以有超过 100 万个,那是两年多前的事了:
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
在过去的几个月中,我们对服务器进行了大量改进,以提高性能、正常运行时间和可扩展性。今天我们调整了一些旋钮,转移了一些流量,并在一台机器上实现了 100 万个已建立的 tcp 会话(并且有内存和 CPU 空闲!)
$ netstat -an | grep -c EST
1016313
So somewhere between 10^5 and 10^7 sockets, ish.
所以在 10^5 和 10^7 之间的某个套接字,是的。