Skip to content

Commit 92761ff

Browse files
author
rhamlett_microsoft
committed
Logging updates during testing for debugging
1 parent 17e8d69 commit 92761ff

1 file changed

Lines changed: 43 additions & 37 deletions

File tree

src/PerfProblemSimulator/Services/LoadTestService.cs

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -303,49 +303,55 @@ public LoadTestService(
303303
/// </summary>
304304
private async void BroadcastStats(object? state)
305305
{
306-
// Read and reset period stats atomically
307-
var requestsCompleted = Interlocked.Exchange(ref _periodRequestsCompleted, 0);
308-
309-
// Only broadcast if there was activity
310-
if (requestsCompleted == 0)
311-
{
312-
return;
313-
}
314-
315-
var responseTimeSum = Interlocked.Exchange(ref _periodResponseTimeSum, 0);
316-
var maxResponseTime = Interlocked.Exchange(ref _periodMaxResponseTimeMs, 0);
317-
var peakConcurrent = Interlocked.Exchange(ref _periodPeakConcurrent, 0);
318-
var exceptions = Interlocked.Exchange(ref _periodExceptions, 0);
319-
var currentConcurrent = Interlocked.CompareExchange(ref _concurrentRequests, 0, 0);
320-
321-
// Calculate averages
322-
var avgResponseTime = requestsCompleted > 0
323-
? (double)responseTimeSum / requestsCompleted
324-
: 0;
325-
var requestsPerSecond = (double)requestsCompleted / BroadcastIntervalSeconds;
326-
327-
var statsData = new LoadTestStatsData
328-
{
329-
CurrentConcurrent = currentConcurrent,
330-
PeakConcurrent = peakConcurrent,
331-
RequestsCompleted = requestsCompleted,
332-
AvgResponseTimeMs = Math.Round(avgResponseTime, 2),
333-
MaxResponseTimeMs = maxResponseTime,
334-
RequestsPerSecond = Math.Round(requestsPerSecond, 2),
335-
ExceptionCount = (int)exceptions,
336-
Timestamp = DateTimeOffset.UtcNow
337-
};
338-
339306
try
340307
{
341-
await _hubContext.Clients.All.ReceiveLoadTestStats(statsData);
342-
_logger.LogDebug(
343-
"Load test stats broadcast: {Requests} requests, {AvgMs}ms avg, {MaxMs}ms max, {RPS} RPS",
308+
// Read and reset period stats atomically
309+
var requestsCompleted = Interlocked.Exchange(ref _periodRequestsCompleted, 0);
310+
311+
_logger.LogInformation(
312+
"Load test timer fired - requests in period: {Requests}, currentConcurrent: {Concurrent}",
313+
requestsCompleted,
314+
_concurrentRequests);
315+
316+
// Only broadcast if there was activity
317+
if (requestsCompleted == 0)
318+
{
319+
return;
320+
}
321+
322+
var responseTimeSum = Interlocked.Exchange(ref _periodResponseTimeSum, 0);
323+
var maxResponseTime = Interlocked.Exchange(ref _periodMaxResponseTimeMs, 0);
324+
var peakConcurrent = Interlocked.Exchange(ref _periodPeakConcurrent, 0);
325+
var exceptions = Interlocked.Exchange(ref _periodExceptions, 0);
326+
var currentConcurrent = Interlocked.CompareExchange(ref _concurrentRequests, 0, 0);
327+
328+
// Calculate averages
329+
var avgResponseTime = requestsCompleted > 0
330+
? (double)responseTimeSum / requestsCompleted
331+
: 0;
332+
var requestsPerSecond = (double)requestsCompleted / BroadcastIntervalSeconds;
333+
334+
var statsData = new LoadTestStatsData
335+
{
336+
CurrentConcurrent = currentConcurrent,
337+
PeakConcurrent = peakConcurrent,
338+
RequestsCompleted = requestsCompleted,
339+
AvgResponseTimeMs = Math.Round(avgResponseTime, 2),
340+
MaxResponseTimeMs = maxResponseTime,
341+
RequestsPerSecond = Math.Round(requestsPerSecond, 2),
342+
ExceptionCount = (int)exceptions,
343+
Timestamp = DateTimeOffset.UtcNow
344+
};
345+
346+
_logger.LogInformation(
347+
"Broadcasting load test stats: {Requests} requests, {AvgMs}ms avg, {MaxMs}ms max, {RPS} RPS",
344348
requestsCompleted, avgResponseTime, maxResponseTime, requestsPerSecond);
349+
350+
await _hubContext.Clients.All.ReceiveLoadTestStats(statsData);
345351
}
346352
catch (Exception ex)
347353
{
348-
_logger.LogError(ex, "Error broadcasting load test stats");
354+
_logger.LogError(ex, "Error in BroadcastStats timer callback");
349355
}
350356

351357
// Reset period start time

0 commit comments

Comments
 (0)