@@ -3,7 +3,7 @@ import _ConnectionPoolTestUtils
3
3
import Benchmark
4
4
5
5
let benchmarks : @Sendable ( ) -> Void = {
6
- Benchmark ( " Minimal benchmark " , configuration: . init( scalingFactor: . kilo) ) { benchmark in
6
+ Benchmark ( " Lease/Release 1k requests: 50 parallel " , configuration: . init( scalingFactor: . kilo) ) { benchmark in
7
7
let clock = MockClock ( )
8
8
let factory = MockConnectionFactory < MockClock > ( autoMaxStreams: 1 )
9
9
var configuration = ConnectionPoolConfiguration ( )
@@ -28,6 +28,8 @@ let benchmarks: @Sendable () -> Void = {
28
28
29
29
let sequential = benchmark. scaledIterations. upperBound / configuration. maximumConnectionSoftLimit
30
30
31
+ benchmark. startMeasurement ( )
32
+
31
33
for parallel in 0 ..< configuration. maximumConnectionSoftLimit {
32
34
taskGroup. addTask {
33
35
for _ in 0 ..< sequential {
@@ -45,6 +47,52 @@ let benchmarks: @Sendable () -> Void = {
45
47
for i in 0 ..< configuration. maximumConnectionSoftLimit {
46
48
await taskGroup. next ( )
47
49
}
50
+
51
+ benchmark. stopMeasurement ( )
52
+
53
+ taskGroup. cancelAll ( )
54
+ }
55
+ }
56
+
57
+ Benchmark ( " Lease/Release 1k requests: sequential " , configuration: . init( scalingFactor: . kilo) ) { benchmark in
58
+ let clock = MockClock ( )
59
+ let factory = MockConnectionFactory < MockClock > ( autoMaxStreams: 1 )
60
+ var configuration = ConnectionPoolConfiguration ( )
61
+ configuration. maximumConnectionSoftLimit = 50
62
+ configuration. maximumConnectionHardLimit = 50
63
+
64
+ let pool = ConnectionPool (
65
+ configuration: configuration,
66
+ idGenerator: ConnectionIDGenerator ( ) ,
67
+ keepAliveBehavior: MockPingPongBehavior ( keepAliveFrequency: nil , connectionType: MockConnection . self) ,
68
+ observabilityDelegate: NoOpConnectionPoolMetrics ( connectionIDType: MockConnection . ID. self) ,
69
+ clock: clock
70
+ ) {
71
+ try await factory. makeConnection ( id: $0, for: $1)
72
+ }
73
+
74
+ await withTaskGroup { taskGroup in
75
+
76
+ taskGroup. addTask {
77
+ await pool. run ( )
78
+ }
79
+
80
+ let sequential = benchmark. scaledIterations. upperBound / configuration. maximumConnectionSoftLimit
81
+
82
+ benchmark. startMeasurement ( )
83
+
84
+ for _ in benchmark. scaledIterations {
85
+ do {
86
+ try await pool. withConnection { connection in
87
+ blackHole ( connection)
88
+ }
89
+ } catch {
90
+ fatalError ( )
91
+ }
92
+ }
93
+
94
+ benchmark. stopMeasurement ( )
95
+
48
96
taskGroup. cancelAll ( )
49
97
}
50
98
}
0 commit comments