Fix Kafka retry seek, bound buffers, and cut hot-path CPU/memory waste (Phases 41–44).
Stop consumers from committing past failed offsets, harden Rabbit/DataLake/gateway backpressure, dispose JsonDocument/MinIO correctly, and batch expensive DB/HTTP paths. Track progress in docs/performance.
This commit is contained in:
@@ -176,19 +176,21 @@ public sealed class SimulationRunner : ISimulationRunner, IHostedService
|
||||
|
||||
public async Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var running = new List<Task>();
|
||||
foreach (var ctx in _runs.Values)
|
||||
{
|
||||
if (ctx.State.Status is SimulationRunStatus.Pending or SimulationRunStatus.Running)
|
||||
ctx.Cts.Cancel();
|
||||
if (ctx.ExecuteTask is not null)
|
||||
running.Add(ctx.ExecuteTask);
|
||||
}
|
||||
|
||||
var deadline = DateTimeOffset.UtcNow.AddSeconds(5);
|
||||
while (DateTimeOffset.UtcNow < deadline
|
||||
&& _runs.Values.Any(c =>
|
||||
c.State.Status is SimulationRunStatus.Pending or SimulationRunStatus.Running))
|
||||
{
|
||||
await Task.Delay(50, cancellationToken);
|
||||
}
|
||||
if (running.Count == 0) return;
|
||||
|
||||
var all = Task.WhenAll(running);
|
||||
var completed = await Task.WhenAny(all, Task.Delay(TimeSpan.FromSeconds(5), cancellationToken));
|
||||
if (completed != all)
|
||||
_logger.LogWarning("Simulation stop timed out waiting for {Count} run task(s)", running.Count);
|
||||
}
|
||||
|
||||
private async Task<SimulationRunState> RegisterAndStartAsync(
|
||||
@@ -224,7 +226,7 @@ public sealed class SimulationRunner : ISimulationRunner, IHostedService
|
||||
if (!_runs.TryAdd(runId, ctx))
|
||||
throw new ConflictException("Failed to register simulation run.", "SIMULATION_REGISTER_FAILED");
|
||||
|
||||
_ = Task.Run(() => ExecuteAsync(ctx, CancellationToken.None), CancellationToken.None);
|
||||
ctx.ExecuteTask = Task.Run(() => ExecuteAsync(ctx, CancellationToken.None), CancellationToken.None);
|
||||
|
||||
return state.Snapshot();
|
||||
}
|
||||
@@ -365,5 +367,6 @@ public sealed class SimulationRunner : ISimulationRunner, IHostedService
|
||||
public SimulationRunState State { get; } = state;
|
||||
public CancellationTokenSource Cts { get; } = cts;
|
||||
public ScenarioFile Scenario { get; } = scenario;
|
||||
public Task? ExecuteTask { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user