forked from microsoft/TelemetryLogsGeneratorAndBenchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
223 lines (204 loc) · 8.83 KB
/
Program.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
218
219
220
221
222
223
using Azure.Core;
using Azure.Storage.Blobs;
using BenchmarkLogGenerator.Utilities;
using System;
using System.Diagnostics;
using System.Threading.Tasks;
namespace BenchmarkLogGenerator
{
class Program
{
static CommandLineArgs m_args = new CommandLineArgs();
private static readonly string[] m_basicHelpHints = { "/?", "-?", "?", "/help", "-help", "help" };
static void Main(string[] args)
{
if (args.Length > 0)
{
if (m_basicHelpHints.SafeFastAny(h => string.Equals(h, args[0], StringComparison.OrdinalIgnoreCase)))
{
PrintUsage();
}
else
{
CommandLineArgsParser.Parse(args, m_args, null, true);
}
}
else
{
PrintUsage();
}
if (m_args.outputType == WriterType.LocalDisk && m_args.localPath == null
|| m_args.outputType == WriterType.EventHub && m_args.eventHubConnectionString == null
|| m_args.outputType == WriterType.AzureStorage && m_args.blobConnectionString == null)
{
CommandLineArgsParser.WriteHelpStringToConsoleAndQuit(new string[] { }, new CommandLineArgs(), $"The output type of {m_args.outputType} was specified without the corrosponding connection/path");
}
Console.WriteLine("Starting...");
string containerName = "";
string partitionName = "";
BlobContainerClient container = null;
if(m_args.outputType == WriterType.AzureStorage)
{
try
{
partitionName = $"-p{m_args.partition}";
var blobOptions = new BlobClientOptions();
blobOptions.Retry.MaxRetries = 3;
blobOptions.Retry.Mode = RetryMode.Exponential;
BlobServiceClient blobClient = new BlobServiceClient(m_args.blobConnectionString, blobOptions);
containerName = $"logsbenchmark-{m_args.size}{partitionName}".ToLower();
var response = blobClient.CreateBlobContainer(containerName);
container = response.Value;
}
catch (Exception ex)
{
var color = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Error creating container {containerName}. Please verify that the container does not exist");
Console.WriteLine($"Exception Message: {ex.Message}");
Console.ForegroundColor = color;
Environment.Exit(1);
}
}
if (m_args.outputType == WriterType.LocalDisk && m_args.size == BenchmarkDataSize.HundredTB)
{
Console.WriteLine("For 100TB data size, please use Azure storage outputType.");
Environment.Exit(0);
}
if (m_args.outputType == WriterType.EventHub && m_args.size != BenchmarkDataSize.OneGB)
{
Console.WriteLine("For event hub, data size is restricted to 1 GB.");
Environment.Exit(0);
}
Stopwatch sw = new Stopwatch();
sw.Start();
int logsPerSessionFactor = GetLogsPerSessionFactor(m_args.size);
int numSessionsFactor = GetNumSessionsFactor(m_args.size);
int start = GetStart(m_args.partition, m_args.size);
int end = GetEnd(m_args.partition, m_args.size);
var res = Parallel.For(start, end, index =>
{
Generator.Run(index, GetWriter($"iteration count: {index} ", container), logsPerSessionFactor, numSessionsFactor);
});
sw.Stop();
Console.WriteLine($"Total time {sw.ElapsedMilliseconds} ms");
}
//Factors:
//OneTB 6X more sessions, 100X more sources
//HundredTB 10X more sessions, 10X more logs per session, 10X more sources
//Expected timespan period for logs:
//~1 day for 1GB
//~9 days for 1TB
//~90 days for 100TB
private static int GetNumSessionsFactor(BenchmarkDataSize size)
{
switch (size)
{
case BenchmarkDataSize.OneGB:
return 1;
case BenchmarkDataSize.TenGB:
return 2;
case BenchmarkDataSize.OneTB:
return 6;
case BenchmarkDataSize.HundredTB:
return 60;
default:
return 1;
}
}
private static int GetLogsPerSessionFactor(BenchmarkDataSize size)
{
switch (size)
{
case BenchmarkDataSize.OneGB:
return 1;
case BenchmarkDataSize.TenGB:
return 1;
case BenchmarkDataSize.OneTB:
return 1;
case BenchmarkDataSize.HundredTB:
return 1;
default:
return 1;
}
}
private static int GetStart(int partition, BenchmarkDataSize size)
{
if (size == BenchmarkDataSize.HundredTB && partition > -1)
{
return partition * 100;
}
return 0;
}
private static int GetEnd(int partition, BenchmarkDataSize size)
{
if (size == BenchmarkDataSize.HundredTB && partition > -1)
{
return (partition + 1) * 100 - 1;
}
return NumThreads(size) * NumIterations(size);
}
private static int NumThreads(BenchmarkDataSize size)
{
switch (size)
{
case BenchmarkDataSize.OneGB:
return 1;
case BenchmarkDataSize.TenGB:
return 5;
case BenchmarkDataSize.OneTB:
return 100;
case BenchmarkDataSize.HundredTB:
return 100;
default:
return 100;
}
}
private static int NumIterations(BenchmarkDataSize size)
{
switch (size)
{
case BenchmarkDataSize.OneGB:
return 1;
case BenchmarkDataSize.TenGB:
return 1;
case BenchmarkDataSize.OneTB:
return 1;
case BenchmarkDataSize.HundredTB:
return 10;
default:
return 1;
}
}
private static void PrintUsage()
{
var esb = new ExtendedStringBuilder();
esb.AppendLine();
esb.AppendLine("The BenchmarkLogGenerator is a tool to generate logs for benchmark testing");
esb.AppendLine();
esb.AppendLine("It is invoked with the following parameters:");
esb.AppendLine("-output:Where the output should be written to. Possible values are: LocalDisk, AzureBlobStorage or EventHub");
esb.AppendLine("-localPath: The root folder");
esb.AppendLine("-azureStorageAccountConnections: A comma separated list of Azure storage account connections (can be single connection), containers will be created automaticly using the following template: logsBenchmark-{size}-p{partition}");
esb.AppendLine("-eventHubConnection: The connection string for Azure EventHub");
esb.AppendLine("-size: The output size, possible values are OneGB, TenGB, OneTB, HundredTB. Default is OneGB");
esb.AppendLine("-partition: The applicable partition, between -1 to 9, where -1 means single partition. Only relevant for HundredTB size. Default is -1");
esb.AppendLine();
CommandLineArgsParser.PrintUsage(esb);
}
private static LogWriter GetWriter(string writerId, BlobContainerClient container)
{
switch (m_args.outputType)
{
case WriterType.LocalDisk:
return new FileLogWriter(m_args.localPath, false, writerId, null);
case WriterType.AzureStorage:
return new FileLogWriter(m_args.blobConnectionString, true, writerId, container);
case WriterType.EventHub:
return new EventHubWriter(m_args.eventHubConnectionString);
default:
return null;
}
}
}
}