简体   繁体   English

C10k中每个线程有多个客户端

[英]Having more than one client per thread in c10k

Is there any optimal reason why one thread per client is normally used in the c10k problem? 在c10k问题中为什么每个客户端通常使用一个线程有最佳的理由吗?

Can we put 5, 10, or 25 per thread? 我们可以在每个线程上放置5、10或25吗? Would there be any negative changes to performance? 绩效会有负面变化吗?

Having one thread per client seems to be very taxing on the system and if we had 25 per thread we could have 400 threads for 10,000 instead of 10,000 for 10,000. 每个客户端只有一个线程似乎对系统造成了很大的负担,如果每个线程只有25个线程,那么我们可以有400个线程(10,000个)而不是10,000个(10,000个)。

There are two completely different models for dealing with 10K+ connections: 有两种完全不同的模型来处理10K +连接:

  • Multi-Threaded with one thread per connection 线程,每个连接一个线程
  • Single-Threaded with non-blocking operations and asynchronous I/O (possibly with several independent processes per machine to fully utilise the available cores) 具有非阻塞操作和异步I / O的 单线程 (可能每台计算机具有多个独立进程,以充分利用可用的内核)

Both models can be used to work with more than 100K connections, and both models have their benefits in certain areas. 两种型号均可用于超过100K的连接,并且两种型号在某些领域都有其优势。 In direct comparison, they differ as follows: 直接比较,它们之间的区别如下:

Multi-Threaded: 多线程:

  • high memory footprint caused by the stacks 堆栈导致的高内存占用
  • need for synchronization operations to avoid data races 需要同步操作以避免数据争用

Single-Threaded: 单线程:

  • everything has to be non-blocking (bad support by operating systems, eg for file-system operations on Linux) 一切都必须是非阻塞的(操作系统的不良支持,例如,Linux上的文件系统操作)
  • everything has to be asynchronous (bad support by programming languages, eg for control structures and error handling) 一切都必须是异步的(编程语言的不良支持,例如控制结构和错误处理)

It is possible to combine these two models. 可以将这两种模型结合起来。 In this case, one thread per core is typically used (instead of one thread for N connections). 在这种情况下,通常每个核心使用一个线程(而不是用于N个连接的一个线程)。 There are some good use cases for this model. 此模型有一些很好的用例。 However, there is also a huge problem: It combines the drawbacks of both models. 但是,还有一个巨大的问题:结合了两种模型的缺点。 That means, you have to spent the efforts to everything thread-safe , non-blocking and asynchronous . 这意味着,您必须花所有精力在线程安全非阻塞异步上 Usually the effort is twice as high as for one of the pure models. 通常,工作量是纯模型之一的两倍。

That's the reason, why the pure models are usually preferred over the mixed model for most applications. 这就是为什么对于大多数应用而言, 模型通常比混合模型更受青睐。 The exceptions are edge components , which have to deal with millions of requests per second, eg load-balancers and proxies. 边缘组件例外,它们必须每秒处理数百万个请求,例如负载平衡器和代理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM