From 01b5e565c4ef8c7170ce86d78b1711b1ad4a2b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gurhem?= Date: Fri, 2 Aug 2024 18:13:56 +0200 Subject: [PATCH] chore: add option in Bench to download results or not --- .../Bench/Client/src/Options/BenchOptions.cs | 5 + Tests/Bench/Client/src/Program.cs | 91 ++++++++++--------- 2 files changed, 52 insertions(+), 44 deletions(-) diff --git a/Tests/Bench/Client/src/Options/BenchOptions.cs b/Tests/Bench/Client/src/Options/BenchOptions.cs index 5acf05f68..ce3d4a87e 100644 --- a/Tests/Bench/Client/src/Options/BenchOptions.cs +++ b/Tests/Bench/Client/src/Options/BenchOptions.cs @@ -103,6 +103,11 @@ public class BenchOptions /// public bool PurgeData { get; set; } = true; + /// + /// Download results and check all results are properly retrieved + /// + public bool DownloadResults { get; set; } = true; + /// /// Dictionary to put into task options /// diff --git a/Tests/Bench/Client/src/Program.cs b/Tests/Bench/Client/src/Program.cs index 7a8d4948c..149fd8f41 100644 --- a/Tests/Bench/Client/src/Program.cs +++ b/Tests/Bench/Client/src/Program.cs @@ -478,60 +478,63 @@ await stream.RequestStream.CompleteAsync() var resultsAvailable = Stopwatch.GetTimestamp(); - var countRes = 0; + if (benchOptions.DownloadResults) + { + var countRes = 0; - await results.ParallelForEach(new ParallelTaskOptions(benchOptions.DegreeOfParallelism), - async resultId => - { - for (var i = 0; i < benchOptions.MaxRetries; i++) + await results.ParallelForEach(new ParallelTaskOptions(benchOptions.DegreeOfParallelism), + async resultId => { - await using var channel = await channelPool.GetAsync(CancellationToken.None) - .ConfigureAwait(false); - try + for (var i = 0; i < benchOptions.MaxRetries; i++) { - var client = new Results.ResultsClient(channel); + await using var channel = await channelPool.GetAsync(CancellationToken.None) + .ConfigureAwait(false); + try + { + var client = new Results.ResultsClient(channel); + + var result = await client.DownloadResultData(createSessionReply.SessionId, + resultId, + CancellationToken.None) + .ConfigureAwait(false); - var result = await client.DownloadResultData(createSessionReply.SessionId, - resultId, - CancellationToken.None) - .ConfigureAwait(false); + // A good a way to process results would be to process them individually as soon as they are + // retrieved. They may be stored in a ConcurrentBag or a ConcurrentDictionary but you need to + // be careful to not overload your memory. If you need to retrieve a lot of results to apply + // post-processing on, consider doing so with sub-tasking so that the client-side application + // has to do less work. - // A good a way to process results would be to process them individually as soon as they are - // retrieved. They may be stored in a ConcurrentBag or a ConcurrentDictionary but you need to - // be careful to not overload your memory. If you need to retrieve a lot of results to apply - // post-processing on, consider doing so with sub-tasking so that the client-side application - // has to do less work. + if (result.Length != benchOptions.ResultSize * 1024) + { + logger.LogInformation("Received length {received}, expected length {expected}", + result.Length, + benchOptions.ResultSize * 1024); + throw new InvalidOperationException("The result size from the task should have the same size as the one specified"); + } - if (result.Length != benchOptions.ResultSize * 1024) + Interlocked.Increment(ref countRes); + // If successful, return + return; + } + catch (RpcException e) when (e.StatusCode == StatusCode.Unavailable) { - logger.LogInformation("Received length {received}, expected length {expected}", - result.Length, - benchOptions.ResultSize * 1024); - throw new InvalidOperationException("The result size from the task should have the same size as the one specified"); + logger.LogWarning(e, + "Error during result retrieving, retrying to get {resultId}", + resultId); } - - Interlocked.Increment(ref countRes); - // If successful, return - return; - } - catch (RpcException e) when (e.StatusCode == StatusCode.Unavailable) - { - logger.LogWarning(e, - "Error during result retrieving, retrying to get {resultId}", - resultId); } - } - // in this case, retries are all made so we need to tell that it did not work - throw new InvalidOperationException("Too many retries"); - }) - .ConfigureAwait(false); - - logger.LogInformation("Results retrieved {number}", - countRes); - if (countRes != results.Count) - { - throw new InvalidOperationException("All results were not retrieved"); + // in this case, retries are all made so we need to tell that it did not work + throw new InvalidOperationException("Too many retries"); + }) + .ConfigureAwait(false); + + logger.LogInformation("Results retrieved {number}", + countRes); + if (countRes != results.Count) + { + throw new InvalidOperationException("All results were not retrieved"); + } } var resultsReceived = Stopwatch.GetTimestamp();