Skip to content

Commit f488056

Browse files
Warning -> Debug on DeleteSession has been RpcException & fixes for SLO (#513)
1 parent 8c9a1ec commit f488056

File tree

7 files changed

+43
-37
lines changed

7 files changed

+43
-37
lines changed

.github/workflows/slo.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ jobs:
2323
include:
2424
- workload: AdoNet
2525
read_rps: 1000
26-
write_rps: 1000
26+
write_rps: 100
2727
- workload: Dapper
2828
read_rps: 1000
29-
write_rps: 1000
29+
write_rps: 100
3030
- workload: EF
31-
read_rps: 500
32-
write_rps: 500
31+
read_rps: 1000
32+
write_rps: 100
3333

3434
concurrency:
3535
group: slo-${{ github.ref }}-${{ matrix.workload }}
@@ -64,8 +64,8 @@ jobs:
6464
--prom-pgw http://localhost:9091 \
6565
--report-period 250 \
6666
--time 600 \
67-
--read-rps ${{matrix.read_rps || 1000 }} \
68-
--write-rps ${{matrix.write_rps || 1000 }} \
67+
--read-rps ${{ matrix.read_rps }} \
68+
--write-rps ${{ matrix.write_rps }} \
6969
--read-timeout 1000 \
7070
--write-timeout 1000
7171

slo/src/AdoNet/SloTableContext.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Data;
22
using Internal;
3-
using Microsoft.Extensions.Logging;
43
using Polly;
54
using Ydb.Sdk;
65
using Ydb.Sdk.Ado;
@@ -9,9 +8,9 @@ namespace AdoNet;
98

109
public class SloTableContext : SloTableContext<YdbDataSource>
1110
{
12-
private static readonly AsyncPolicy Policy = Polly.Policy.Handle<YdbException>(exception => exception.IsTransient)
13-
.WaitAndRetryAsync(10, attempt => TimeSpan.FromMilliseconds(attempt * 10),
14-
(e, _, _, _) => { Logger.LogWarning(e, "Failed read / write operation"); });
11+
private static readonly AsyncPolicy Policy = Polly.Policy
12+
.Handle<YdbException>(exception => exception.IsTransient)
13+
.RetryAsync(10);
1514

1615
protected override string Job => "AdoNet";
1716

slo/src/Dapper/SloTableContext.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Dapper;
22
using Internal;
3-
using Microsoft.Extensions.Logging;
43
using Polly;
54
using Ydb.Sdk;
65
using Ydb.Sdk.Ado;
@@ -9,9 +8,9 @@ namespace AdoNet.Dapper;
98

109
public class SloTableContext : SloTableContext<YdbDataSource>
1110
{
12-
private static readonly AsyncPolicy Policy = Polly.Policy.Handle<YdbException>(exception => exception.IsTransient)
13-
.WaitAndRetryAsync(10, attempt => TimeSpan.FromMilliseconds(attempt * 10),
14-
(e, _, _, _) => { Logger.LogWarning(e, "Failed read / write operation"); });
11+
private static readonly AsyncPolicy Policy = Polly.Policy
12+
.Handle<YdbException>(exception => exception.IsTransient)
13+
.RetryAsync(10);
1514

1615
protected override string Job => "Dapper";
1716

slo/src/Internal/SloTableContext.cs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public interface ISloContext
1919

2020
public abstract class SloTableContext<T> : ISloContext
2121
{
22+
private const int IntervalMs = 100;
23+
2224
protected static readonly ILogger Logger = ISloContext.Factory.CreateLogger<SloTableContext<T>>();
2325

2426
private volatile int _maxId;
@@ -95,11 +97,13 @@ public async Task Run(RunConfig runConfig)
9597

9698
var writeLimiter = new FixedWindowRateLimiter(new FixedWindowRateLimiterOptions
9799
{
98-
Window = TimeSpan.FromMilliseconds(100), PermitLimit = runConfig.WriteRps / 10, QueueLimit = int.MaxValue
100+
Window = TimeSpan.FromMilliseconds(IntervalMs), PermitLimit = runConfig.WriteRps / 10,
101+
QueueLimit = int.MaxValue
99102
});
100103
var readLimiter = new FixedWindowRateLimiter(new FixedWindowRateLimiterOptions
101104
{
102-
Window = TimeSpan.FromMilliseconds(100), PermitLimit = runConfig.ReadRps / 10, QueueLimit = int.MaxValue
105+
Window = TimeSpan.FromMilliseconds(IntervalMs), PermitLimit = runConfig.ReadRps / 10,
106+
QueueLimit = int.MaxValue
103107
});
104108

105109
var cancellationTokenSource = new CancellationTokenSource();
@@ -124,7 +128,7 @@ public async Task Run(RunConfig runConfig)
124128
Logger.LogInformation("Run task is finished");
125129
return;
126130

127-
Task ShootingTask(RateLimiter rateLimitPolicy, string operationType,
131+
async Task ShootingTask(RateLimiter rateLimitPolicy, string operationType,
128132
Func<T, RunConfig, Task<(int, StatusCode)>> action)
129133
{
130134
var metricFactory = Metrics.WithLabels(new Dictionary<string, string>
@@ -193,21 +197,22 @@ Task ShootingTask(RateLimiter rateLimitPolicy, string operationType,
193197
["error_type"]
194198
);
195199

196-
// ReSharper disable once MethodSupportsCancellation
197-
return Task.Run(async () =>
200+
var workJobs = new List<Task>();
201+
202+
for (var i = 0; i < 10; i++)
198203
{
199-
while (!cancellationTokenSource.Token.IsCancellationRequested)
204+
workJobs.Add(Task.Run(async () =>
200205
{
201-
using var lease = await rateLimitPolicy
202-
.AcquireAsync(cancellationToken: cancellationTokenSource.Token);
203-
204-
if (!lease.IsAcquired)
206+
while (!cancellationTokenSource.Token.IsCancellationRequested)
205207
{
206-
continue;
207-
}
208+
using var lease = await rateLimitPolicy
209+
.AcquireAsync(cancellationToken: cancellationTokenSource.Token);
210+
211+
if (!lease.IsAcquired)
212+
{
213+
await Task.Delay(Random.Shared.Next(IntervalMs / 2), cancellationTokenSource.Token);
214+
}
208215

209-
_ = Task.Run(async () =>
210-
{
211216
try
212217
{
213218
pendingOperations.Inc();
@@ -235,11 +240,14 @@ Task ShootingTask(RateLimiter rateLimitPolicy, string operationType,
235240
{
236241
Logger.LogError(e, "Fail operation!");
237242
}
238-
}, cancellationTokenSource.Token);
239-
}
243+
}
244+
}, cancellationTokenSource.Token));
245+
}
246+
247+
// ReSharper disable once MethodSupportsCancellation
248+
await Task.WhenAll(workJobs);
240249

241-
Logger.LogInformation("{ShootingName} shooting is stopped", operationType);
242-
});
250+
Logger.LogInformation("{ShootingName} shooting is stopped", operationType);
243251
}
244252
}
245253

src/Ydb.Sdk/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
- Dev: LogLevel `Warning` -> `Debug` on DeleteSession has been `RpcException`.
2+
13
## v0.22.0
24

35
- Added `YdbDbType` property to `YdbParameter`, allowing to explicitly specify YDB-specific data types for parameter mapping.
@@ -21,7 +23,6 @@
2123
- Added new ADO.NET options:
2224
- `MinSessionPool`: The minimum connection pool size.
2325
- `SessionIdleTimeout`: The time (in seconds) to wait before closing idle session in the pool if the count of all sessions exceeds `MinSessionPool`.
24-
- `SessionPruningInterval`: How many seconds the pool waits before attempting to prune idle sessions (see `SessionIdleTimeout`).
2526
- Fixed bug `Reader`: unhandled exception in `TryReadRequestBytes(long bytes)`.
2627
- Handle `YdbException` on `DeleteSession`.
2728
- Do not invoke `DeleteSession` if the session is not active.

src/Ydb.Sdk/src/Ado/Session/PoolingSession.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ internal override async Task DeleteSession()
235235
}
236236
catch (Exception e)
237237
{
238-
_logger.LogWarning(e, "Error occurred while deleting session[{SessionId}] (NodeId = {NodeId})",
238+
_logger.LogDebug(e, "Error occurred while deleting session[{SessionId}] (NodeId = {NodeId})",
239239
SessionId, NodeId);
240240
}
241241
}

src/Ydb.Sdk/src/Ado/YdbConnectionStringBuilder.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Microsoft.Extensions.Logging;
55
using Microsoft.Extensions.Logging.Abstractions;
66
using Ydb.Sdk.Auth;
7-
using Ydb.Sdk.Pool;
87
using Ydb.Sdk.Transport;
98

109
namespace Ydb.Sdk.Ado;
@@ -29,8 +28,8 @@ private void InitDefaultValues()
2928
_port = 2136;
3029
_database = "/local";
3130
_minSessionPool = 0;
32-
_maxSessionPool = SessionPoolDefaultSettings.MaxSessionPool;
33-
_createSessionTimeout = SessionPoolDefaultSettings.CreateSessionTimeoutSeconds;
31+
_maxSessionPool = 100;
32+
_createSessionTimeout = 5;
3433
_sessionIdleTimeout = 300;
3534
_useTls = false;
3635
_connectTimeout = GrpcDefaultSettings.ConnectTimeoutSeconds;

0 commit comments

Comments
 (0)