-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultiRunBenchmark.cs
217 lines (198 loc) · 8.76 KB
/
MultiRunBenchmark.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MongoBench.Benchmarks;
namespace MongoBench {
/// <summary>
///
/// </summary>
public class MultiRunBenchmark {
/// <summary>
/// Gets or sets the num of runs.
/// </summary>
/// <value>The num of runs.</value>
public int NumOfRuns { get; private set; }
/// <summary>
/// Gets the benchmarks.
/// </summary>
/// <value>The benchmarks.</value>
public BenchmarkServer[] ServerBenchmark { get; private set; }
private List<BenchmarkBase> _Results;
/// <summary>
/// Gets the results.
/// </summary>
/// <value>The results.</value>
public List<BenchmarkBase> Results {
get {
if (null == _Results) {
_Results = new List<BenchmarkBase>();
foreach (var b in this.ServerBenchmark) {
_Results.AddRange(b.Results);
}
}
return _Results;
}
}
#region Statistics
/// <summary>
/// Gets the avg inserts per thread second.
/// </summary>
/// <value>The avg inserts per thread second.</value>
public double AvgInsertsPerThreadSecond {
get {
return this.Results
.Where(b => null != b && b.GetType() == typeof(Insert))
.Average(b => (double)((Insert)b).NumOfRecords / ((double)b.Time.ElapsedMilliseconds / 1000.0));
}
}
/// <summary>
/// Gets the avg inserts per second.
/// </summary>
/// <value>The avg inserts per second.</value>
public double AvgInsertsPerSecond {
get {
return this.AvgInsertsPerThreadSecond * this.ServerBenchmark[0].NumOfThreads;
}
}
/// <summary>
/// Gets the duration of the avg simple select.
/// </summary>
/// <value>The duration of the avg simple select.</value>
public double AvgSimpleSelectDuration {
get {
return this.Results
.Where(b => b.GetType() == typeof(CompositeQueries))
.Average(b => ((CompositeQueries)b).SimpleQuery.Time.ElapsedMilliseconds) / 1000.0;
}
}
/// <summary>
/// Gets the duration of the avg simple filter.
/// </summary>
/// <value>The duration of the avg simple filter.</value>
public double AvgSimpleFilterDuration {
get {
return this.Results
.Where(b => b.GetType() == typeof(CompositeQueries))
.Average(b => ((CompositeQueries)b).FilterQuery.Time.ElapsedMilliseconds) / 1000.0;
}
}
/// <summary>
/// Gets the duration of the avg map reduce tags.
/// </summary>
/// <value>The duration of the avg map reduce tags.</value>
public double AvgMapReduceTagsDuration {
get {
return this.Results
.Where(b => b.GetType() == typeof(CompositeQueries))
.Average(b => ((CompositeQueries)b).TagCountMapReduce.Time.ElapsedMilliseconds) / 1000.0;
}
}
/// <summary>
/// Gets the duration of the avg map reduce comments.
/// </summary>
/// <value>The duration of the avg map reduce comments.</value>
public double AvgMapReduceCommentsDuration {
get {
return this.Results
.Where(b => b.GetType() == typeof(CompositeQueries))
.Average(b => ((CompositeQueries)b).CommentAuthorMapReduce.Time.ElapsedMilliseconds) / 1000.0;
}
}
/// <summary>
/// Gets the duration of the create index.
/// </summary>
/// <value>The duration of the create index.</value>
public double AvgCreateIndexDuration {
get {
return this.Results
.Where(b => b.GetType() == typeof(CreateIndex))
.Average(b => b.Time.ElapsedMilliseconds) / 1000.0;
}
}
/// <summary>
/// Gets the avg duration of the indexed simple select.
/// </summary>
/// <value>The avg duration of the indexed simple select.</value>
public double AvgIndexedSimpleSelectDuration {
get {
return this.Results
.Where(b => b.GetType() == typeof(CompositeQueries) && b.Type.StartsWith("Indexed"))
.Average(b => ((CompositeQueries)b).SimpleQuery.Time.ElapsedMilliseconds) / 1000.0;
}
}
/// <summary>
/// Gets the avg duration of the indexed simple filter.
/// </summary>
/// <value>The avg duration of the indexed simple filter.</value>
public double AvgIndexedSimpleFilterDuration {
get {
return this.Results
.Where(b => b.GetType() == typeof(CompositeQueries) && b.Type.StartsWith("Indexed"))
.Average(b => ((CompositeQueries)b).FilterQuery.Time.ElapsedMilliseconds) / 1000.0;
}
}
/// <summary>
/// Gets the avg duration of the indexed map reduce tags.
/// </summary>
/// <value>The avg duration of the indexed map reduce tags.</value>
public double AvgIndexedMapReduceTagsDuration {
get {
return this.Results
.Where(b => b.GetType() == typeof(CompositeQueries) && b.Type.StartsWith("Indexed"))
.Average(b => ((CompositeQueries)b).TagCountMapReduce.Time.ElapsedMilliseconds) / 1000.0;
}
}
/// <summary>
/// Gets the avg duration of the indexed map reduce comments.
/// </summary>
/// <value>The avg duration of the indexed map reduce comments.</value>
public double AvgIndexedMapReduceCommentsDuration {
get {
return this.Results
.Where(b => b.GetType() == typeof(CompositeQueries) && b.Type.StartsWith("Indexed"))
.Average(b => ((CompositeQueries)b).CommentAuthorMapReduce.Time.ElapsedMilliseconds) / 1000.0;
}
}
#endregion
/// <summary>
/// Initializes a new instance of the <see cref="MultiRunBenchmark"/> class.
/// </summary>
/// <param name="numOfRuns">The num of runs.</param>
/// <param name="serverName">Name of the server.</param>
/// <param name="connectionString">The connection string.</param>
/// <param name="numOfThreads">The num of threads.</param>
/// <param name="numOfRecrods">The num of recrods.</param>
/// <param name="databaseName">Name of the database.</param>
/// <param name="collectionName">Name of the collection.</param>
/// <param name="mutexName">Name of the mutex.</param>
/// <param name="indexFields">The index fields.</param>
public MultiRunBenchmark(int numOfRuns, string serverName, string connectionString, int numOfThreads, int numOfRecrods, string databaseName, string collectionName, string mutexName, string[] indexFields) {
this.NumOfRuns = numOfRuns;
this.ServerBenchmark = new BenchmarkServer[numOfRuns];
for (int i = 0; i < numOfRuns; i++) {
this.ServerBenchmark[i] = new BenchmarkServer(serverName,
connectionString,
numOfThreads,
numOfRecrods,
databaseName,
collectionName,
mutexName,
indexFields);
}
}
/// <summary>
/// Runs this instance.
/// </summary>
/// <returns></returns>
public bool Run() {
bool status = true;
Log.Info("Starting multi-run [{0}] benchmarks", this.NumOfRuns);
for (int i = 0; i < this.NumOfRuns; i++) {
status &= this.ServerBenchmark[i].Run();
}
Log.Info("Completed multi-run benchmarks");
return status;
}
}
}