boost::asio 线程池与 io_service_per_cpu 设计
目前我不确定,我尝试制作高性能服务器,我有一个 6Core CPU,所以如果我使用io_service_per_cpu"设计,我有 6 个 io_service.
Currently I′m not sure, I try to make a high-performance server, I got a 6Core CPU, so if I would use the "io_service_per_cpu" design, I have 6 io_service′s.
我已经听说线程池设计不是最好的,但我不确定.
I already heard that the threadpool design isn′t the best one, but I′m not sure about that.
你有什么知识?有人已经对每个人进行了压力测试,还是其他什么?
What knowledge do you have? Someone already made a Stress test with each, or something else?
推荐答案
根据我的经验,按照以下顺序进行异步应用程序设计要容易得多:
In my experience it is vastly easier to approach asynchronous application design with the following order:
- 单线程和一个
io_service
- 多个线程,每个线程从单个
io_service
调用io_service::run()
.使用 strands 作为处理程序需要访问共享数据结构. io_service
每个 cpu
- single thread and a single
io_service
- multiple threads, each invoking
io_service::run()
from a singleio_service
. Use strands for handlers that require access to shared data structures. io_service
per cpu
在对您的应用程序进行概要分析之后,应该考虑在这些设计中的每一个之间进行更改.请注意,仅 HTTP Server 2 示例展示了如何使用每个 CPU 的 io_service
,它没有告诉你何时或为什么使用这样的设计.
The motivation for changing between each of these designs should be done after profiling your application. Note that the HTTP Server 2 example only shows how to use an io_service
per CPU, it does not show you when or why to use such a design.
相关文章