Original link: Http://stackoverflow.com/questions/17593699/tcp-ip-solving-the-c10k-with-the-thread-per-client-approach
It is possible for a thread to support 10,000 concurrent connections with one connection. However, the following issues need to be noted:
(1) A thread A customer connection, when the customer exit needs, delete the thread, when the new thread arrives, need to create a new thread, concurrent execution, the system overhead is very large. This is the time to consider using a thread pool.
(2) stack size of the default is 8M, some 10M, you can view through Ulimit-a, Ulimit-s Unlimited set to unlimited.
With a 8M size standard, 100,000 threads require 80GB of memory. The actual application of the stack depth is not too large, you can adjust the size of the stack to 64K or 512k.
(3) If the lifetime of the connection is relatively short, when creating a socket, you can use option So--reuseport to allow multiple threads to bind to the same port.
(4) Increase user restrictions: Number of open files (ulimit-n 65535), maximum number of threads/processes (Ulimit-u 65535). You can view files:
#cat/proc/sys/kernel/threads-max
#cat/proc/sys/kernel/pid-max
The/etc/security/limits.d/90-nproc.conf file has a separate limit for ordinary users and Superuser, and can be modified.
# vi/etc/security/limits.d/90-nproc.conf
The contents are as follows:
* Soft Nproc 1024
Root Soft Nproc Unlimited
It can be seen that all users except root are limited to 1024, so you can save the exit by commenting on this row or by changing the value to resolve the problem after the modification is complete.
Such modifications are immediately effective.