@@ -3,7 +3,7 @@ import _ConnectionPoolTestUtils
33import Benchmark
44
55let 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
77 let clock = MockClock ( )
88 let factory = MockConnectionFactory < MockClock > ( autoMaxStreams: 1 )
99 var configuration = ConnectionPoolConfiguration ( )
@@ -28,6 +28,8 @@ let benchmarks: @Sendable () -> Void = {
2828
2929 let sequential = benchmark. scaledIterations. upperBound / configuration. maximumConnectionSoftLimit
3030
31+ benchmark. startMeasurement ( )
32+
3133 for parallel in 0 ..< configuration. maximumConnectionSoftLimit {
3234 taskGroup. addTask {
3335 for _ in 0 ..< sequential {
@@ -45,6 +47,52 @@ let benchmarks: @Sendable () -> Void = {
4547 for i in 0 ..< configuration. maximumConnectionSoftLimit {
4648 await taskGroup. next ( )
4749 }
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+
4896 taskGroup. cancelAll ( )
4997 }
5098 }
0 commit comments