-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathIncreaseInflightSendsExperiment.cs
60 lines (52 loc) · 2.2 KB
/
IncreaseInflightSendsExperiment.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//---------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
//---------------------------------------------------------------------------------
namespace ThroughputTest
{
using System;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
class IncreaseInflightSendsExperiment : Experiment
{
private int count;
public IncreaseInflightSendsExperiment(int count, Metrics metrics, Settings settings) : base(metrics, settings)
{
this.count = count;
}
public override async Task<Experiment> Run()
{
if (Settings.SenderCount == 0)
{
return null;
}
await Task.Delay(10).ConfigureAwait(false); // 10 seconds to meter
var firstObservation = await ((IObservable<SendMetrics>)Metrics).Buffer(TimeSpan.FromSeconds(5)).FirstAsync();
var firstMessageCount = firstObservation.Sum(i => i.Messages);
if ((Settings.MaxInflightSends.Value + count) < 1)
{
Settings.MaxInflightSends.Value = 1;
count = 1;
}
{
Settings.MaxInflightSends.Value += count;
}
await Task.Delay(20).ConfigureAwait(false); // 20 seconds to settle
var secondObservation = await ((IObservable<SendMetrics>)Metrics).Buffer(TimeSpan.FromSeconds(5)).FirstAsync();
var secondMessageCount = secondObservation.Sum(i => i.Messages);
if (secondMessageCount > firstMessageCount)
{
return new IncreaseInflightSendsExperiment(this.count, this.Metrics, this.Settings);
}
else
{
Settings.MaxInflightSends.Value -= count;
return new IncreaseInflightSendsExperiment(this.count, this.Metrics, this.Settings);
}
}
}
}