How to resolve 10,000 concurrent connections, using one thread per client method

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.