Conversation
Lwhyz
left a comment
There was a problem hiding this comment.
很棒!这里有几个建议:
- 策略需要放在wsp命名空间内使用
- 如果不在均衡模式下用cv.notify_one通知工作线程,也可以用sleep而不是wait_for
- 统一下用下划线_命名
- 在README中也简要体现一下不同的mode
- 有空闲的话可以在Benchmark中修改现有用例,做不同模式下性能的简单标注。
我再接着改改 |
|
|
Hi,有空帮忙看看还有什么问题,第一次提PR没啥经验,可能有不少疏漏之处 |
benchmark/bench4.cc
Outdated
| std::mutex latency_mutex; | ||
|
|
||
| auto task = [&latencies, &latency_mutex](std::chrono::steady_clock::time_point submit_time) { | ||
| auto start_time = std::chrono::steady_clock::now(); |
There was a problem hiding this comment.
在轻量的框架里面,获取高精度时间这个调用是相当重的,这样测试反映的耗时都在这个调用上而不是框架本身。只能是全部跑完统计。
There was a problem hiding this comment.
hanya@localhost:build$ ./bench4 4 1000000
Strategy: lowlatancy | Threads: 4 | Tasks: 1000000 | Avg Latency: 5.19 us | Min Latency: 0 us | Max Latency: 1027 us
Strategy: balance | Threads: 4 | Tasks: 1000000 | Avg Latency: 6.87 us | Min Latency: 0 us | Max Latency: 1256 us
Strategy: blocking | Threads: 4 | Tasks: 1000000 | Avg Latency: 6.14 us | Min Latency: 0 us | Max Latency: 145 us
hanya@localhost:build$ ./bench4 1 1000000
Strategy: lowlatancy | Threads: 1 | Tasks: 1000000 | Avg Latency: 56448.22 us | Min Latency: 28 us | Max Latency: 113657 us
Strategy: balance | Threads: 1 | Tasks: 1000000 | Avg Latency: 34161.14 us | Min Latency: 1 us | Max Latency: 71510 us
Strategy: blocking | Threads: 1 | Tasks: 1000000 | Avg Latency: 83461.47 us | Min Latency: 59 us | Max Latency: 152813 us
单个worker的总耗时是更低的,但是这里平均延迟高出了几个数量级。
include/workspace/workbranch.hpp
Outdated
|
|
||
| namespace wsp { | ||
|
|
||
| enum class WaitStrategy { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
benchmark/bench4.cc
Outdated
| // record submit_time | ||
| for (int i = 0; i < task_nums; ++i) { | ||
| auto submit_time = std::chrono::steady_clock::now(); | ||
| wb.submit([=]() { task(submit_time); }); |
Lwhyz
left a comment
There was a problem hiding this comment.
除了Bench4有点问题,其它的我测试了一下没有发现问题。👍👍👍
目前bench4采用类似bench2的写法,跑完再计算时间。但是发现了一个问题,yield换成sleep函数后,lowlatency模式的任务执行时间更短了,ubuntu下和win11上都有这个现象。 |
估计是超线程导致线程切换太多了,可以perf看一下。 |
根据“cpu占用异常 #39”,添加了三种等待策略:
1.低延迟模式 原始空转等待(默认)
2.均衡模式 在一段时间内都无动作 进入线程休眠
3.睡眠模式 loop 线程统一 休眠1毫秒 / 使用条件变量控制loop的循环