Skip to content

Commit

Permalink
HttpClient: Fixed LatencyMeanMs not calculating properly (dotnet#677)
Browse files Browse the repository at this point in the history
  • Loading branch information
keithmifsud17 authored Jan 4, 2024
1 parent 484d217 commit 63b1341
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Microsoft.Crank.Jobs.HttpClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ IEnumerable<Task> CreateTasks()
Started = startTime.ToLocalTime(),
ThroughputBps = workerTasks.Select(x => x.Result.ThroughputBps).Sum(),
LatencyMaxMs = Math.Round(workerTasks.Select(x => x.Result.LatencyMaxMs).Max(), 3),
LatencyMeanMs = workerTasks.Select(x => x.Result.TotalRequests).Sum() == 0 ? 0 : Math.Round((stopTime - startTime).TotalMilliseconds / workerTasks.Select(x => x.Result.TotalRequests).Sum(), 3),
LatencyMeanMs = Math.Round(workerTasks.Sum(x => x.Result.LatencyMeanMs * x.Result.TotalRequests) / workerTasks.Sum(x => x.Result.TotalRequests), 3),
Connections = Connections,
};

Expand Down Expand Up @@ -569,6 +569,7 @@ public static async Task<WorkerResult> DoWorkAsync()
var counters = new int[5];
var socketErrors = 0;
var maxLatency = 0D;
var totalLatency = 0D;
var transferred = 0L;
var measuringStart = 0L;
var sw = new Stopwatch();
Expand Down Expand Up @@ -631,6 +632,7 @@ public static async Task<WorkerResult> DoWorkAsync()
transferred += responseMessage.Content.Headers.ContentLength ?? 0;
var latency = sw.ElapsedTicks - start;
maxLatency = Math.Max(maxLatency, latency);
totalLatency += latency;

var status = (int)responseMessage.StatusCode;

Expand Down Expand Up @@ -704,6 +706,7 @@ public static async Task<WorkerResult> DoWorkAsync()
Status5xx = counters[4],
SocketErrors = socketErrors,
LatencyMaxMs = maxLatency / Stopwatch.Frequency * 1000,
LatencyMeanMs = (totalLatency / counters.Sum()) / Stopwatch.Frequency * 1000,
ThroughputBps = throughput
};
}
Expand Down

0 comments on commit 63b1341

Please sign in to comment.