boost::asio 线程池与 io_service_per_cpu 设计

2023-07-20C/C++开发问题
3

本文介绍了boost::asio 线程池与 io_service_per_cpu 设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

目前我不确定,我尝试制作高性能服务器,我有一个 6Core CPU,所以如果我使用io_service_per_cpu"设计,我有 6 个 io_service.

Currently Im 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_services.

我已经听说线程池设计不是最好的,但我不确定.

I already heard that the threadpool design isnt the best one, but Im 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:

  1. 单线程和一个io_service
  2. 多个线程,每个线程从单个 io_service 调用 io_service::run().使用 strands 作为处理程序需要访问共享数据结构.
  3. io_service 每个 cpu
  1. single thread and a single io_service
  2. multiple threads, each invoking io_service::run() from a single io_service. Use strands for handlers that require access to shared data structures.
  3. 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.

这篇关于boost::asio 线程池与 io_service_per_cpu 设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

无法访问 C++ std::set 中对象的非常量成员函数
Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)...
2024-08-14 C/C++开发问题
17

从 lambda 构造 std::function 参数
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)...
2024-08-14 C/C++开发问题
25

STL BigInt 类实现
STL BigInt class implementation(STL BigInt 类实现)...
2024-08-14 C/C++开发问题
3

使用 std::atomic 和 std::condition_variable 同步不可靠
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)...
2024-08-14 C/C++开发问题
17

在 STL 中将列表元素移动到末尾
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)...
2024-08-14 C/C++开发问题
9

为什么禁止对存储在 STL 容器中的类重载 operator&()?
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)...
2024-08-14 C/C++开发问题
6