Skip to content

Commit 690cc68

Browse files
authored
[Perf, Stress] Refactor options (Azure#17006)
1 parent 406110c commit 690cc68

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

common/Perf/Azure.Test.Perf/PerfProgram.cs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ private static async Task Run(Type testType, PerfOptions options)
109109

110110
if (options.Warmup > 0)
111111
{
112-
await RunTestsAsync(tests, options.Sync, options.Parallel, options.Rate, options.Warmup, options.StatusInterval,
113-
"Warmup");
112+
await RunTestsAsync(tests, options, "Warmup", warmup: true);
114113
}
115114

116115
for (var i = 0; i < options.Iterations; i++)
@@ -120,8 +119,7 @@ await RunTestsAsync(tests, options.Sync, options.Parallel, options.Rate, options
120119
{
121120
title += " " + (i + 1);
122121
}
123-
await RunTestsAsync(tests, options.Sync, options.Parallel, options.Rate, options.Duration, options.StatusInterval,
124-
title, options.JobStatistics, options.Latency);
122+
await RunTestsAsync(tests, options, title);
125123
}
126124
}
127125
finally
@@ -162,24 +160,29 @@ await RunTestsAsync(tests, options.Sync, options.Parallel, options.Rate, options
162160
}
163161
}
164162

165-
private static async Task RunTestsAsync(IPerfTest[] tests, bool sync, int parallel, int? rate,
166-
int durationSeconds, int statusIntervalSeconds, string title, bool jobStatistics = false, bool latency = false)
163+
private static async Task RunTestsAsync(IPerfTest[] tests, PerfOptions options, string title, bool warmup = false)
167164
{
168-
_completedOperations = new int[parallel];
169-
_lastCompletionTimes = new TimeSpan[parallel];
165+
var durationSeconds = warmup ? options.Warmup : options.Duration;
166+
167+
// Always disable jobStatistics and latency during warmup
168+
var jobStatistics = warmup ? false : options.JobStatistics;
169+
var latency = warmup ? false : options.Latency;
170+
171+
_completedOperations = new int[options.Parallel];
172+
_lastCompletionTimes = new TimeSpan[options.Parallel];
170173

171174
if (latency)
172175
{
173-
_latencies = new List<TimeSpan>[parallel];
174-
for (var i = 0; i < parallel; i++)
176+
_latencies = new List<TimeSpan>[options.Parallel];
177+
for (var i = 0; i < options.Parallel; i++)
175178
{
176179
_latencies[i] = new List<TimeSpan>();
177180
}
178181

179-
if (rate.HasValue)
182+
if (options.Rate.HasValue)
180183
{
181-
_correctedLatencies = new List<TimeSpan>[parallel];
182-
for (var i = 0; i < parallel; i++)
184+
_correctedLatencies = new List<TimeSpan>[options.Parallel];
185+
for (var i = 0; i < options.Parallel; i++)
183186
{
184187
_correctedLatencies[i] = new List<TimeSpan>();
185188
}
@@ -205,35 +208,35 @@ private static async Task RunTestsAsync(IPerfTest[] tests, bool sync, int parall
205208
},
206209
newLine: true,
207210
progressStatusCts.Token,
208-
statusIntervalSeconds
211+
options.StatusInterval
209212
);
210213

211214
Thread pendingOperationsThread = null;
212-
if (rate.HasValue)
215+
if (options.Rate.HasValue)
213216
{
214217
_pendingOperations = Channel.CreateUnbounded<ValueTuple<TimeSpan, Stopwatch>>();
215-
pendingOperationsThread = WritePendingOperations(rate.Value, cancellationToken);
218+
pendingOperationsThread = WritePendingOperations(options.Rate.Value, cancellationToken);
216219
}
217220

218-
if (sync)
221+
if (options.Sync)
219222
{
220-
var threads = new Thread[parallel];
223+
var threads = new Thread[options.Parallel];
221224

222-
for (var i = 0; i < parallel; i++)
225+
for (var i = 0; i < options.Parallel; i++)
223226
{
224227
var j = i;
225228
threads[i] = new Thread(() => RunLoop(tests[j], j, latency, cancellationToken));
226229
threads[i].Start();
227230
}
228-
for (var i = 0; i < parallel; i++)
231+
for (var i = 0; i < options.Parallel; i++)
229232
{
230233
threads[i].Join();
231234
}
232235
}
233236
else
234237
{
235-
var tasks = new Task[parallel];
236-
for (var i = 0; i < parallel; i++)
238+
var tasks = new Task[options.Parallel];
239+
for (var i = 0; i < options.Parallel; i++)
237240
{
238241
var j = i;
239242
// Call Task.Run() instead of directly calling RunLoopAsync(), to ensure the requested

common/Stress/Azure.Test.Stress/StressProgram.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private static async Task Run(Type testType, StressOptions options)
6868
setupStatusCts.Cancel();
6969
setupStatusThread.Join();
7070

71-
await RunTestAsync(test, options.Duration, options.StatusInterval, metrics);
71+
await RunTestAsync(test, options, metrics);
7272
}
7373
finally
7474
{
@@ -184,9 +184,9 @@ private static void WriteEvents(StressMetrics metrics, string header, StressOpti
184184
}
185185
}
186186

187-
private static async Task RunTestAsync(IStressTest test, int durationSeconds, int statusIntervalSeconds, StressMetrics metrics)
187+
private static async Task RunTestAsync(IStressTest test, StressOptions options, StressMetrics metrics)
188188
{
189-
var duration = TimeSpan.FromSeconds(durationSeconds);
189+
var duration = TimeSpan.FromSeconds(options.Duration);
190190
using var testCts = new CancellationTokenSource(duration);
191191
var cancellationToken = testCts.Token;
192192

@@ -198,7 +198,7 @@ private static async Task RunTestAsync(IStressTest test, int durationSeconds, in
198198
() => metrics.ToString(),
199199
newLine: true,
200200
progressStatusCts.Token,
201-
statusIntervalSeconds);
201+
options.StatusInterval);
202202

203203
try
204204
{

0 commit comments

Comments
 (0)