TCP / IP - 使用线程每客户端方法解决C10K [英] TCP/IP - Solving the C10K with the thread per client approach

查看:151
本文介绍了TCP / IP - 使用线程每客户端方法解决C10K的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读着名的 C10k文章,并在网络上搜索有关事情的方式我想知道如果今天的标准服务器可以使用每个连接的线程来处理> 10000并发连接(可能与






一些细节可能会影响方法:


  1. 输入,中间处理和输出。

  2. 长度

  3. 服务器的技术规格(内核,处理器,RAM等)

  4. 将此系统与其他技术AIO,轮询,绿色线程等...






显然我不是)

解决方案

当然,这是一个专家,所以任何评论或建议都会非常感激。标准服务器可以使用每个连接一个线程的模型处理超过 10K并发连接。我已经构建了这样的应用程序,而五年前,它运行在标准Linux服务器上每个进程超过50K的并发连接。现在,应该可以在当前硬件上运行具有超过250K个并发连接的相同应用程序。



只有几点需要记住:




  • 通过使用线程池重用线程。

  • 堆栈大小:默认情况下,每个Linux线程为其堆栈保留8 MB。对于10K线程,总计达到80 GB。您应该将默认堆栈大小设置为64k到512k之间的某个值,这不是问题,因为大多数应用程序不需要更深层的调用堆栈。

  • 通过在同一端点上使用选项 SO_REUSEPORT 创建多个套接字来优化新连接。

  • 增加用户限制:打开文件(默认值1.024),最大用户进程

  • / proc / sys / kernel / pid_max (默认32K), / proc / sys / kernel / threads-max / proc / sys / vm / max_map_count (默认为65K)。



<上面提到的应用程序最初设计为仅处理2K个并发连接。但是,随着使用的增长,我们不必对代码进行重大更改,以扩展到50K的连接。


After reading the famous C10k article and searching on the web about how things have evolved since it was written, I would like to know if it would be possible for a today's standard server to handle >10000 concurrent connections using a thread per connection (possibly with the help of a pool of threads to avoid the creation/killing process).


Some details that may affect the approach to the problem:

  1. Input, intermediate processing and output.
  2. Length of each connection.
  3. Technical specifications of the server (cores, processors, RAM, etc...)
  4. Combining this system with alternative techniques like AIO, polling, green threads, etc...


Obviously I'm not an expert in the matter, so any remarks or advices will be highly appreciated :)

解决方案

Absolutely. A standard server can handle more than 10K concurrent connections using the model with one thread per connection. I have build such an application, and five years ago, it was running with more than 50K concurrent connections per process on a standard Linux server. Nowadays, it should be possible to run the same application with more than 250K concurrent connections on current hardware.

There are only a few things to keep in mind:

  • Reuse threads by using a thread pool. There is no need to kill threads if they are not used, because the resource usage should be optimized for peak loads.
  • Stack size: By default each Linux thread reserves 8 MB for its stack. That sums up to 80 GB for 10K threads. You should set the default stack size to some value between 64k and 512k, which isn't a problem, because most applications don't require deeper call stacks.
  • If the connections are short-lived, optimize for new connections by creating several sockets on the same endpoint with the option SO_REUSEPORT.
  • Increase the user limits: open files (default 1.024), max user processes
  • Increase system limits, e.g. /proc/sys/kernel/pid_max (default 32K), /proc/sys/kernel/threads-max, and /proc/sys/vm/max_map_count (default 65K).

The application mentioned above was initially designed to handle only 2K concurrent connections. However, with the growth in use, we didn't have to make significant changes to the code in order to scale up to 50K connections.

这篇关于TCP / IP - 使用线程每客户端方法解决C10K的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆