Linux maximum socket count

It seems that the server is limited to ~ 32720 sockets ... I tried every known change to a variable to raise this limit. But the server remains limited to 32720 open socket, even if there is still 4Go of free memory and 80% processor downtime ...

Here is the configuration

~# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 63931
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 798621
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 2048
cpu time               (seconds, -t) unlimited
max user processes              (-u) 63931
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

net.netfilter.nf_conntrack_max = 999999
net.ipv4.netfilter.ip_conntrack_max = 999999
net.nf_conntrack_max = 999999

Any thoughts?

+5
source share
8 answers

If you are dealing with openssl and threads, go to your / proc / sys / vm / max _map_count and try to raise it.

+3
source

What server are you talking to? Perhaps it has a hard-coded max or works within other limits (maximum streams / from address space, etc.).

http://www.metabrew.com/article/a-million-user-comet-application-with-mochiweb-part-1 , , , .

+2

IPV4 TCP 16 16 .

. http://en.wikipedia.org/wiki/Transmission_Control_Protocol

, - 32 , , TCP-, . 65K ( ). . , 1. , 65K ( TCP). , .

. (AF_INET,...) , , . , :

echo "1024 65535" > /proc/sys/net/ipv4/ip_local_port_range (cat, , - 32768 61000)

, TCP-, 32 dest? 65 ?

100 000 linux mint 16 (64 ) ( root )

#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/ip.h>

void ShowLimit()
{
   rlimit lim;
   int err=getrlimit(RLIMIT_NOFILE,&lim);
   printf("%1d limit: %1ld,%1ld\n",err,lim.rlim_cur,lim.rlim_max);
}

main()
{
   ShowLimit();

   rlimit lim;
   lim.rlim_cur=100000;
   lim.rlim_max=100000;
   int err=setrlimit(RLIMIT_NOFILE,&lim);
   printf("set returned %1d\n",err);

   ShowLimit();

   int sock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
   sockaddr_in maddr;
   maddr.sin_family=AF_INET;
   maddr.sin_port=htons(80);
   maddr.sin_addr.s_addr=INADDR_ANY;

   err=bind(sock,(sockaddr *) &maddr, sizeof(maddr));

   err=listen(sock,1024);

   int sockets=0;
   while(true)
   {
      sockaddr_in raddr;
      socklen_t rlen=sizeof(raddr);
      err=accept(sock,(sockaddr *) &raddr,&rlen);
      if(err>=0)
      {
        ++sockets;
        printf("%1d sockets accepted\n",sockets);
      }
   }
}
+2

, , , , C10k. , .

+1

Gnu + Linux - , . () - . , . , .

0

net/socket.c fd sock_alloc_fd(), get_unused_fd().

linux/fs/file.c, fd sysctl_nr_open,

int sysctl_nr_open_max = 1024 * 1024; /* raised later */

/// later...
sysctl_nr_open_max = min((size_t)INT_MAX, ~(size_t)0/sizeof(void *)) &
                         -BITS_PER_LONG;

sysctl fs.nr_open, 1M. fd, , .

, , , ,

#include <sys/time.h>
#include <sys/resource.h>
int main() {
    struct rlimit limit;
    getrlimit(RLIMIT_NOFILE,&limit);
    printf("cur: %d, max: %d\n",limit.rlim_cur,limit.rlim_max);
}

?

0

, - . , .

, , , , .

Assumimg /cpu/network , , (, / ), , , .

, . , . , , .

, , .

0

.

cat /proc/{pid}/limits

nofiles , : root 100 000 "", 100k CC

echo 100000 > /proc/sys/fs/file-max

/etc/sysctl.conf

fs.file-max = 100000

, , . , nginx

worker_rlimit_nofile 100000;

nginx /proc/ {pid}/limits

100 000 , TCP IP-.

...

echo "1024 65535" > /proc/sys/net/ipv4/ip_local_port_range

~ 64000 .

, IP-. localhost / IP-, 127.0.0.1/localhost.

For example, you can bind your test clients to IP addresses randomly selected from 127.0.0.1 to 127.0.0.5

Using apache-bench, you installed

-B 127.0.0.x

Nodejs sockets will use

localAddress

/etc/security/limits.conf configures PAM: it usually has nothing to do with the server.

If the server requests requests via TCP using, for example, upstream or mod_proxy, the server is limited to ip_local_port_range. It can be easily limited to 32,000.

0
source

All Articles