Skip to content

Commit d06c76e

Browse files
Benchmark: SessionReuse_HighContention_Pattern (#489)
* Benchmark: SessionReuse_HighContention_Pattern * Update README.md
1 parent 32ec3fa commit d06c76e

File tree

3 files changed

+63
-25
lines changed

3 files changed

+63
-25
lines changed

src/Ydb.Sdk/test/Ydb.Sdk.Ado.Benchmarks/README.md

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,22 @@ Allocated : Allocated memory per single operation (managed only, incl
1919

2020
# YDB .NET SDK Session Pool V1 On Semaphore-Based
2121

22-
| Method | Mean | Error | StdDev | Completed Work Items | Lock Contentions | Gen0 | Gen1 | Allocated |
23-
|-------------------------------------|-----------------:|----------------:|----------------:|---------------------:|-----------------:|----------:|-------:|-----------:|
24-
| SingleThreaded_OpenClose | 126.0 ns | 0.85 ns | 0.71 ns | 0.0000 | - | 0.0257 | - | 216 B |
25-
| MultiThreaded_OpenClose | 36,028.4 ns | 710.14 ns | 1,146.75 ns | 40.0003 | 0.5005 | 1.4038 | - | 11582 B |
26-
| HighContention_OpenClose | 155,614.4 ns | 3,083.73 ns | 5,400.90 ns | 230.8015 | 5.5818 | 8.7891 | 0.4883 | 74780 B |
27-
| SessionReuse_Pattern | 203,350.5 ns | 2,675.74 ns | 2,371.97 ns | 220.0027 | 5.5349 | 5.8594 | - | 50511 B |
28-
| SessionReuse_HighIterations_Pattern | 145,221,373.7 ns | 1,843,163.83 ns | 1,724,096.59 ns | 200020.2500 | 1764.5000 | 5000.0000 | - | 43209728 B |
22+
| Method | Mean | Error | StdDev | Completed Work Items | Lock Contentions | Gen0 | Gen1 | Allocated |
23+
|-------------------------------------|-----------------:|----------------:|----------------:|---------------------:|-----------------:|----------:|---------:|-----------:|
24+
| SingleThreaded_OpenClose | 125.1 ns | 2.54 ns | 2.37 ns | - | - | 0.0257 | - | 216 B |
25+
| MultiThreaded_OpenClose | 30,893.8 ns | 610.63 ns | 895.06 ns | 40.0002 | 0.3741 | 1.4038 | - | 11573 B |
26+
| HighContention_OpenClose | 159,192.9 ns | 3,168.43 ns | 6,752.19 ns | 230.7124 | 5.6448 | 8.7891 | 0.4883 | 74723 B |
27+
| SessionReuse_Pattern | 202,559.0 ns | 2,181.67 ns | 1,934.00 ns | 220.0027 | 5.4810 | 5.8594 | - | 50510 B |
28+
| SessionReuse_HighContention_Pattern | 10,016,874.4 ns | 58,462.60 ns | 54,685.95 ns | 19707.6719 | 165.5469 | 921.8750 | 140.6250 | 7729448 B |
29+
| SessionReuse_HighIterations_Pattern | 152,765,644.4 ns | 1,570,755.95 ns | 1,469,286.09 ns | 200020.0000 | 1751.2500 | 5000.0000 | - | 43207568 B |
2930

30-
# YDB .NET SDK Session Pool Benchmarks
31+
# YDB .NET SDK Session Pool Benchmarks (Npgsql)
3132

32-
| Method | Mean | Error | StdDev | Completed Work Items | Lock Contentions | Gen0 | Allocated |
33-
|-------------------------------------|-----------------:|---------------:|---------------:|---------------------:|-----------------:|-------:|----------:|
34-
| SingleThreaded_OpenClose | 25.35 ns | 0.258 ns | 0.241 ns | - | - | - | - |
35-
| MultiThreaded_OpenClose | 30,650.91 ns | 601.279 ns | 1,281.374 ns | 40.0031 | 0.5160 | 0.8545 | 7249 B |
36-
| HighContention_OpenClose | 142,804.56 ns | 2,845.384 ns | 7,138.512 ns | 205.9829 | 4.6663 | 4.6387 | 38864 B |
37-
| SessionReuse_Pattern | 153,983.59 ns | 2,272.104 ns | 2,014.161 ns | 220.0000 | 5.6296 | 0.7324 | 7303 B |
38-
| SessionReuse_HighIterations_Pattern | 82,351,234.51 ns | 694,703.573 ns | 649,826.153 ns | 200020.0000 | 540.0000 | - | 7458 B |
39-
40-
# YDB .NET SDK Session Source Benchmarks (Npgsql)
41-
42-
| Method | Mean | Error | StdDev | Median | Completed Work Items | Lock Contentions | Gen0 | Allocated |
43-
|--------------------------|--------------:|-------------:|-------------:|--------------:|---------------------:|-----------------:|-------:|----------:|
44-
| SingleThreaded_OpenClose | 25.82 ns | 0.141 ns | 0.125 ns | 25.78 ns | - | - | - | - |
45-
| MultiThreaded_OpenClose | 20,893.61 ns | 829.087 ns | 2,431.569 ns | 19,694.30 ns | 20.0033 | 0.0303 | 0.5188 | 4526 B |
46-
| HighContention_OpenClose | 108,688.27 ns | 2,160.177 ns | 3,298.819 ns | 108,755.99 ns | 100.0017 | 3.8002 | 2.5635 | 21839 B |
47-
| SessionReuse_Pattern | 130,849.34 ns | 2,616.397 ns | 4,977.967 ns | 129,920.39 ns | 20.0000 | 5.4443 | 0.4883 | 4588 B |
48-
33+
| Method | Mean | Error | StdDev | Completed Work Items | Lock Contentions | Gen0 | Gen1 | Allocated |
34+
|-------------------------------------|-----------------:|---------------:|---------------:|---------------------:|-----------------:|---------:|--------:|----------:|
35+
| SingleThreaded_OpenClose | 26.34 ns | 0.476 ns | 0.422 ns | - | - | - | - | - |
36+
| MultiThreaded_OpenClose | 32,578.44 ns | 650.578 ns | 1,583.596 ns | 40.0028 | 0.4411 | 0.8545 | - | 7251 B |
37+
| HighContention_OpenClose | 138,930.59 ns | 2,729.363 ns | 4,990.795 ns | 209.1182 | 3.5857 | 4.8828 | - | 40566 B |
38+
| SessionReuse_Pattern | 159,954.05 ns | 2,820.324 ns | 4,044.825 ns | 220.0000 | 6.0381 | 0.7324 | - | 7307 B |
39+
| SessionReuse_HighContention_Pattern | 8,914,529.81 ns | 46,900.448 ns | 41,576.026 ns | 19756.6563 | 149.0469 | 625.0000 | 93.7500 | 5289794 B |
40+
| SessionReuse_HighIterations_Pattern | 81,211,792.96 ns | 749,115.160 ns | 664,071.077 ns | 200020.0000 | 614.8571 | - | - | 7458 B |

src/Ydb.Sdk/test/Ydb.Sdk.Ado.Benchmarks/SessionPoolBenchmark.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,29 @@ public async Task SessionReuse_Pattern()
9292
await Task.WhenAll(tasks);
9393
}
9494

95+
[Benchmark]
96+
public async Task SessionReuse_HighContention_Pattern()
97+
{
98+
const int iterations = 100;
99+
const int highContentionTasks = 100;
100+
var tasks = new Task[highContentionTasks];
101+
102+
for (var i = 0; i < highContentionTasks; i++)
103+
{
104+
tasks[i] = Task.Run(async () =>
105+
{
106+
for (var j = 0; j < iterations; j++)
107+
{
108+
var session = await _sessionPool.GetSession();
109+
await Task.Yield();
110+
await session.Release();
111+
}
112+
});
113+
}
114+
115+
await Task.WhenAll(tasks);
116+
}
117+
95118
[Benchmark]
96119
public async Task SessionReuse_HighIterations_Pattern()
97120
{

src/Ydb.Sdk/test/Ydb.Sdk.Ado.Benchmarks/SessionSourceBenchmark.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,29 @@ public async Task SessionReuse_Pattern()
8787
await Task.WhenAll(tasks);
8888
}
8989

90+
[Benchmark]
91+
public async Task SessionReuse_HighContention_Pattern()
92+
{
93+
const int iterations = 100;
94+
const int highContentionTasks = 100;
95+
var tasks = new Task[highContentionTasks];
96+
97+
for (var i = 0; i < highContentionTasks; i++)
98+
{
99+
tasks[i] = Task.Run(async () =>
100+
{
101+
for (var j = 0; j < iterations; j++)
102+
{
103+
var session = await _poolingSessionSource.OpenSession();
104+
await Task.Yield();
105+
session.Close();
106+
}
107+
});
108+
}
109+
110+
await Task.WhenAll(tasks);
111+
}
112+
90113
[Benchmark]
91114
public async Task SessionReuse_HighIterations_Pattern()
92115
{

0 commit comments

Comments
 (0)