简体   繁体   English

在linux中处理c10k

[英]handling c10k in linux

using linux BSD socket, what happens if the number of active connection overflows the system limit? 使用linux BSD套接字,如果活动连接数溢出系统限制会发生什么? will accept call return error? 会接受来电回复错误吗?

and even if the system can accept indefinite socket connection, can it be more than the size of integer max value? 即使系统可以接受无限套接字连接,它是否可以超过整数最大值的大小?

a socket descriptor is a 4-byte integer value. 套接字描述符是一个4字节的整数值。 is it fair to say it is theoratically impossible to maintain more than 4294967295 active TCP connection with single process in 32bit system? 可以公平地说,在32位系统中,单个进程维持超过4294967295活动TCP连接是不可能的? (assuming that hardware and OS can support this. and service quality does not matter. we simply want to maintain active TCP connection) (假设硬件和操作系统可以支持这一点。服务质量无关紧要。我们只想保持活动的TCP连接)

it may be a stupid question but I am curious. 这可能是一个愚蠢的问题,但我很好奇。

From the accept(2) manpage on a Linux system: 从Linux系统上的accept(2)联机帮助页:


       EMFILE The per-process limit of open file descriptors has been reached.

       ENFILE The system limit on the total number of open files has been reached.

       ENOBUFS, ENOMEM
              Not enough free memory.  This often means that the memory allocation is limited by the socket buffer limits, not by the
              system memory.

So yes, in any remotedly sane configuration accept will report EMFILE or ENFILE. 所以是的,在任何远程理智的配置中,accept都会报告EMFILE或ENFILE。 If you set the fd limits to some sky-high value, you'll likely get ENOBUFS/ENOMEM instead. 如果将fd限制设置为某个天高值,则可能会获得ENOBUFS / ENOMEM。 You'll likely hit these limits long before the INT_MAX limit on the int datatype. 您可能会在int数据类型的INT_MAX限制之前很久就达到这些限制。

Since file descriptors are ints then you obviously can't go above 4G file descriptors. 由于文件描述符是整数,那么你显然不能超过4G文件描述符。 This is true even on 64-bit systems because sizeof(int) is still 4. In theory you could open more file descriptors across multiple processes. 即使在64位系统上也是如此,因为sizeof(int)仍为4.理论上,您可以在多个进程中打开更多文件描述符。 Even if you increase all the /proc limits you're likely to run out of kernel memory first. 即使你增加了所有/ proc限制,你也可能首先耗尽内核内存。

Per-socket allocations in the linux kernel are in the kilobyte range so even on big servers (with many GB of ram) the maximum connection count is measured in millions, not billions. Linux内核中的每插槽分配都在千字节范围内,因此即使在大型服务器(具有多GB的RAM)上,最大连接数也以百万计,而不是数十亿计。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM