Skip to content

Commit f42d0d9

Browse files
committed
fix release and add bench
1 parent ad92caa commit f42d0d9

File tree

4 files changed

+39
-35
lines changed

4 files changed

+39
-35
lines changed

bench/bench_pool.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,19 @@ void bench_logic(NExecutors::IExecutor& pool) {
4646
});
4747
}
4848

49-
static void IntrusiveThreadPool(benchmark::State& state) {
50-
for (auto _ : state) {
51-
NExecutors::IntrusiveThreadPool pool{CountThreads};
52-
pool.Start();
53-
bench_logic(pool);
54-
pool.WaitIdle();
55-
}
56-
}
57-
BENCHMARK(IntrusiveThreadPool)
58-
->Name(std::format("IntrusiveThreadPool_task_{}", kTasks))
59-
->Repetitions(CountRepetitions)
60-
->Iterations(CountIteration)
61-
->Unit(benchmark::kMillisecond);
49+
//static void IntrusiveThreadPool(benchmark::State& state) {
50+
// for (auto _ : state) {
51+
// NExecutors::IntrusiveThreadPool pool{CountThreads};
52+
// pool.Start();
53+
// bench_logic(pool);
54+
// pool.WaitIdle();
55+
// }
56+
//}
57+
//BENCHMARK(IntrusiveThreadPool)
58+
// ->Name(std::format("IntrusiveThreadPool_task_{}", kTasks))
59+
// ->Repetitions(CountRepetitions)
60+
// ->Iterations(CountIteration)
61+
// ->Unit(benchmark::kMillisecond);
6262

6363
static void DistributedPool(benchmark::State& state) {
6464
for (auto _ : state) {

bench/readme.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@
2828
| DistributedPool_task_100000/iterations:10/repeats:5_stddev | 8.96 ms| 0.477 ms| 5 |
2929
| DistributedPool_task_100000/iterations:10/repeats:5_cv | 7.05 % | 0.80 % | 5 |
3030

31+
### DistributedPool Task 100,000 (queue spinlock)
32+
33+
| Benchmark | Time | CPU | Iterations |
34+
|---------------------------------------------------------------|--------|--------|------------|
35+
| DistributedPool_task_100000/iterations:10/repeats:5 | 304 ms | 126 ms | 10 |
36+
| DistributedPool_task_100000/iterations:10/repeats:5 | 263 ms | 107 ms | 10 |
37+
| DistributedPool_task_100000/iterations:10/repeats:5 | 205 ms | 79.7 ms| 10 |
38+
| DistributedPool_task_100000/iterations:10/repeats:5 | 190 ms | 78.7 ms| 10 |
39+
| DistributedPool_task_100000/iterations:10/repeats:5 | 460 ms | 189 ms | 10 |
40+
| DistributedPool_task_100000/iterations:10/repeats:5_mean | 285 ms | 116 ms | 5 |
41+
| DistributedPool_task_100000/iterations:10/repeats:5_median | 263 ms | 107 ms | 5 |
42+
| DistributedPool_task_100000/iterations:10/repeats:5_stddev | 108 ms | 45.5 ms| 5 |
43+
| DistributedPool_task_100000/iterations:10/repeats:5_cv | 37.98 %| 39.18 %| 5 |
44+
3145
### DistributedPool Task 100,000 (std::mutex)
3246

3347
| Benchmark | Time | CPU | Iterations |

src/components/sync/queue_spinlock.h

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,32 @@ class QueueSpinLock final {
1212
public:
1313
class Guard final {
1414
public:
15-
explicit Guard(QueueSpinLock& host) : host(host) {
16-
host.Acquire(this);
17-
}
15+
explicit Guard(QueueSpinLock& host) : host(host) { host.Acquire(this); }
1816
~Guard() {
19-
Release();
17+
if (is_owner) Release();
2018
}
2119

2220
void Release() {
2321
host.Release(this);
22+
is_owner.store(false);
2423
}
2524

26-
void SetOwner() {
27-
is_owner.store(true);
28-
}
25+
void SetOwner() { is_owner.store(true); }
2926

30-
void SetNext(Guard* guard) {
31-
next.store(guard);
32-
}
27+
void SetNext(Guard* guard) { next.store(guard); }
3328

34-
bool IsOwner() const {
35-
return is_owner.load();
36-
}
29+
bool IsOwner() const { return is_owner.load(); }
3730

38-
bool HasNext() const {
39-
return next.load() != nullptr;
40-
}
31+
bool HasNext() const { return next.load() != nullptr; }
4132

42-
void SetNextOwner() {
43-
next.load()->SetOwner();
44-
}
33+
void SetNextOwner() { next.load()->SetOwner(); }
4534

4635
private:
4736
QueueSpinLock& host;
4837
std::atomic<Guard*> next{};
4938
std::atomic<bool> is_owner{};
5039
};
40+
5141
private:
5242
void Acquire(Guard* guard) {
5343
auto ancestor = tail_.exchange(guard);
@@ -57,7 +47,8 @@ class QueueSpinLock final {
5747
}
5848

5949
ancestor->SetNext(guard);
60-
while(!guard->IsOwner()) {}
50+
while (!guard->IsOwner()) {
51+
}
6152
}
6253

6354
void Release(Guard* guard) {
@@ -67,7 +58,7 @@ class QueueSpinLock final {
6758
}
6859

6960
Guard* old_guard = guard;
70-
while(!tail_.compare_exchange_weak(old_guard, nullptr)) {
61+
while (!tail_.compare_exchange_weak(old_guard, nullptr)) {
7162
if (guard->HasNext()) {
7263
guard->SetNextOwner();
7364
return;

src/fiber/awaiter/mutex_awaiter.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class AsyncMutexWaiter : public IAwaiter,
2828
stopped_handle = handle;
2929
async_mutex->Park(this);
3030

31-
// guard.release()->unlock();
3231
guard.Release();
3332
}
3433

0 commit comments

Comments
 (0)