It seems that the server is limited at ~32720 sockets... I have tried every known variable change to raise up this limit. But the server stay limited at 32720 opened socket, even if there is still 4Go of free memory and 80% of idle cpu...
Here's 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 ?
If you're considering an application where you believe you need to open thousands of sockets, you will definitely want to read about The C10k Problem. That page discusses many of the issues you will face as you scale up your number of client connections to a single server.
Check the real limits of the running process with.
The max for nofiles is determined by the Kernel, the following as root would increase the max to 100,000 "files" i.e. 100k CC
To make it permanent edit /etc/sysctl.conf
You then need the server to ask for more open files, this is different per server. In nginx, for example, you set
Reboot nginx and check /proc/{pid}/limits
To test this you need 100,000 sockets in your client, you are limited in the testing to the number of ports in TCP per IP address.
To increase the local port range to maximum...
This gives you ~64000 ports to test with.
If that is not enough, you need more IP addresses. When testing on localhost you can bind the source/client to an IP other than 127.0.0.1 / localhost.
For example you can bind your test clients to IPs randomly selected from 127.0.0.1 to 127.0.0.5
Using apache-bench you would set
Nodejs sockets would use
/etc/security/limits.conf configures PAM: its usually irrelevant for a server.
If the server is proxying requests using TCP, using upstream or mod_proxy for example, the server is limited by ip_local_port_range. This could easily be the 32,000 limit.
In net/socket.c the fd is allocated in sock_alloc_fd(), which calls get_unused_fd().
Looking at linux/fs/file.c, the only limit to the number of fd's is
sysctl_nr_open
, which is limited toand can be read using
sysctl fs.nr_open
which gives 1M by default here. So the fd's are probably not your problem.edit you then probably checked this as well, but would you care to share the output of
with us?
If you're dealing with openssl and threads, go check your /proc/sys/vm/max_map_count and try to raise it.
On Gnu+Linux, maximum is what you wrote. This number is (probably) stated somewhere in networking standards. I doubt you really need so many sockets. You should optimize the way you are using sockets instead of creating dozens all the time.
In IPV4, the TCP layer has 16 bits for the destination port, and 16 bits for the source port.
see http://en.wikipedia.org/wiki/Transmission_Control_Protocol
Seeing that your limit is 32K I would expect that you are actually seeing the limit of outbound TCP connections you can make. You should be able to get a max of 65K sockets (this would be the protocol limit). This is the limit for total number of named connections. Fortunately, binding a port for incoming connections only uses 1. But if you are trying to test the number of connections from the same machine, you can only have 65K total outgoing connections (for TCP). To test the amount of incoming connections, you will need multiple computers.
Note: you can call socket(AF_INET,...) up to the number of file descriptors available, but you cannot bind them without increasing the number of ports available. To increase the range, do this:
echo "1024 65535" > /proc/sys/net/ipv4/ip_local_port_range (cat it to see what you currently have--the default is 32768 to 61000)
Perhaps it is time for a new TCP like protocol that will allow 32 bits for the source and dest ports? But how many applications really need more than 65 thousand outbound connections?
The following will allow 100,000 incoming connections on linux mint 16 (64 bit) (you must run it as root to set the limits)