Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillKurdyukov committed Aug 15, 2024
1 parent 3a08874 commit da5880c
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions slo/src/Internal/SloContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public async Task Run(RunConfig runConfig)
{ Window = TimeSpan.FromSeconds(1), PermitLimit = runConfig.ReadRps, QueueLimit = int.MaxValue });

var cancellationTokenSource = new CancellationTokenSource();
cancellationTokenSource.CancelAfter(TimeSpan.FromSeconds(runConfig.ShutdownTime));
cancellationTokenSource.CancelAfter(TimeSpan.FromSeconds(runConfig.Time));

var writeTask = ShootingTask(writeLimiter, "write", Upsert);
var readTask = ShootingTask(readLimiter, "read", Select);
Expand All @@ -153,22 +153,18 @@ public async Task Run(RunConfig runConfig)
Task ShootingTask(RateLimiter rateLimitPolicy, string shootingName,
Func<T, RunConfig, Gauge?, Task<(int, StatusCode)>> action)
{
// ReSharper disable once MethodSupportsCancellation
return Task.Run(async () =>
{
var tasks = new List<Task>();

Check warning on line 159 in slo/src/Internal/SloContext.cs

View workflow job for this annotation

GitHub Actions / Inspection (./slo/src/src.sln)

"[UnusedVariable] Local variable 'tasks' is never used" on /home/runner/work/ydb-dotnet-sdk/ydb-dotnet-sdk/slo/src/Internal/SloContext.cs(159,6474)
long activeTasks = 0;
while (!cancellationTokenSource.Token.IsCancellationRequested)
{
using var lease = await rateLimitPolicy
.AcquireAsync(cancellationToken: cancellationTokenSource.Token);
tasks.Add(Task.Run(async () =>
_ = Task.Run(async () =>
{
// ReSharper disable once AccessToModifiedClosure
Interlocked.Increment(ref activeTasks);
var sw = Stopwatch.StartNew();
var (attempts, statusCode) = await action(client, runConfig, errorsGauge);
string label;
Expand All @@ -186,16 +182,16 @@ Task ShootingTask(RateLimiter rateLimitPolicy, string shootingName,
label = "ok";
}
Interlocked.Decrement(ref activeTasks);
attemptsHistogram.WithLabels(label).Observe(attempts);
latencySummary.WithLabels(label).Observe(sw.ElapsedMilliseconds);
}, cancellationTokenSource.Token));
}, cancellationTokenSource.Token);
}
await Task.WhenAll(tasks);
// ReSharper disable once MethodSupportsCancellation
await Task.Delay(TimeSpan.FromSeconds(runConfig.ShutdownTime));
_logger.LogInformation("{ShootingName} shooting is stopped", shootingName);
}, cancellationTokenSource.Token);
});
}
}

Expand Down

0 comments on commit da5880c

Please sign in to comment.