Skip to content

Commit 4e98196

Browse files
authored
mysql minor changes and sysbench cleanup addition (#454)
* adding sysbench version * adding cleanup for sysbench * fixing command line and metadata * fixing unittests * mysql version and adding sysbench updated scripts to git * resolving build errors * fixing issue in set global variables action * fixing unittest * fixed build errors * Create directory if it doesn't exists * fixed build errors
1 parent ccca75c commit 4e98196

16 files changed

Lines changed: 402 additions & 49 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
sysbench 1.1.0 (using bundled LuaJIT 2.1.0-beta3)
2+
3+
Running the test with following options:
4+
Number of threads: 8
5+
Initializing random number generator from current time
6+
7+
8+
Initializing worker threads...
9+
10+
Threads started!
11+
12+
SQL statistics:
13+
queries performed:
14+
read: 9720106
15+
write: 0
16+
other: 0
17+
total: 9720106
18+
transactions: 9720106 (32400.24 per sec.)
19+
queries: 9720106 (32400.24 per sec.)
20+
ignored errors: 0 (0.00 per sec.)
21+
reconnects: 0 (0.00 per sec.)
22+
23+
Throughput:
24+
events/s (eps): 32400.2399
25+
time elapsed: 300.0011s
26+
total number of events: 9720106
27+
28+
Latency (ms):
29+
min: 0.16
30+
avg: 0.25
31+
max: 13.68
32+
95th percentile: 0.28
33+
sum: 2389444.97
34+
35+
Threads fairness:
36+
events (avg/stddev): 1215013.2500/22596.17
37+
execution time (avg/stddev): 298.6806/0.05
38+

src/VirtualClient/VirtualClient.Actions.UnitTests/Sysbench/SysbenchClientExecutorTests.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ public async Task SysbenchClientExecutorRunsTheExpectedWorkloadCommand()
100100
commandExecuted = true;
101101
}
102102

103-
Assert.IsTrue(commandExecuted);
104-
105103
InMemoryProcess process = new InMemoryProcess
106104
{
107105
StartInfo = new ProcessStartInfo
@@ -124,6 +122,8 @@ public async Task SysbenchClientExecutorRunsTheExpectedWorkloadCommand()
124122
{
125123
await SysbenchExecutor.ExecuteAsync(CancellationToken.None);
126124
}
125+
126+
Assert.IsTrue(commandExecuted);
127127
}
128128

129129
[Test]
@@ -146,8 +146,6 @@ public async Task SysbenchClientExecutorUsesDefinedParametersWhenRunningTheWorkl
146146
commandExecuted = true;
147147
}
148148

149-
Assert.IsTrue(commandExecuted);
150-
151149
InMemoryProcess process = new InMemoryProcess
152150
{
153151
StartInfo = new ProcessStartInfo
@@ -170,6 +168,8 @@ public async Task SysbenchClientExecutorUsesDefinedParametersWhenRunningTheWorkl
170168
{
171169
await SysbenchExecutor.ExecuteAsync(CancellationToken.None);
172170
}
171+
172+
Assert.IsTrue(commandExecuted);
173173
}
174174

175175
[Test]
@@ -189,8 +189,6 @@ public async Task SysbenchClientExecutorRunsTheExpectedBalancedScenario()
189189
commandExecuted = true;
190190
}
191191

192-
Assert.IsTrue(commandExecuted);
193-
194192
InMemoryProcess process = new InMemoryProcess
195193
{
196194
StartInfo = new ProcessStartInfo
@@ -213,6 +211,8 @@ public async Task SysbenchClientExecutorRunsTheExpectedBalancedScenario()
213211
{
214212
await SysbenchExecutor.ExecuteAsync(CancellationToken.None);
215213
}
214+
215+
Assert.IsTrue(commandExecuted);
216216
}
217217

218218
[Test]
@@ -232,8 +232,6 @@ public async Task SysbenchClientExecutorRunsInMemoryScenario()
232232
commandExecuted = true;
233233
}
234234

235-
Assert.IsTrue(commandExecuted);
236-
237235
InMemoryProcess process = new InMemoryProcess
238236
{
239237
StartInfo = new ProcessStartInfo
@@ -256,6 +254,8 @@ public async Task SysbenchClientExecutorRunsInMemoryScenario()
256254
{
257255
await SysbenchExecutor.ExecuteAsync(CancellationToken.None).ConfigureAwait(false);
258256
}
257+
258+
Assert.IsTrue(commandExecuted);
259259
}
260260

261261
[Test]
@@ -275,8 +275,6 @@ public async Task SysbenchClientExecutorRunsTheExpectedTPCCWorkloadCommand()
275275
commandExecuted = true;
276276
}
277277

278-
Assert.IsTrue(commandExecuted);
279-
280278
InMemoryProcess process = new InMemoryProcess
281279
{
282280
StartInfo = new ProcessStartInfo
@@ -299,6 +297,8 @@ public async Task SysbenchClientExecutorRunsTheExpectedTPCCWorkloadCommand()
299297
{
300298
await SysbenchExecutor.ExecuteAsync(CancellationToken.None);
301299
}
300+
301+
Assert.IsTrue(commandExecuted);
302302
}
303303

304304
[Test]

src/VirtualClient/VirtualClient.Actions.UnitTests/Sysbench/SysbenchConfigurationTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public async Task SysbenchConfigurationSkipsSysbenchInitialization()
7777

7878
string[] expectedCommands =
7979
{
80-
$"python3 {this.mockPackagePath}/populate-database.py --dbName sbtest --databaseSystem MySQL --benchmark OLTP --tableCount 10 --recordCount 1000 --threadCount 8 --password [A-Za-z0-9+/=]+",
80+
$"python3 {this.mockPackagePath}/populate-database.py --dbName sbtest --databaseSystem MySQL --benchmark OLTP --threadCount 8 --tableCount 10 --recordCount 1000 --password [A-Za-z0-9+/=]+",
8181
};
8282

8383
int commandNumber = 0;
@@ -122,7 +122,7 @@ public async Task SysbenchConfigurationPreparesDatabase()
122122
string[] expectedCommands =
123123
{
124124
$"python3 {this.mockPackagePath}/configure-workload-generator.py --distro Ubuntu --databaseSystem MySQL --packagePath {this.mockPackagePath}",
125-
$"python3 {this.mockPackagePath}/populate-database.py --dbName sbtest --databaseSystem MySQL --benchmark OLTP --tableCount 10 --recordCount 1000 --threadCount 8 --password [A-Za-z0-9+/=]+",
125+
$"python3 {this.mockPackagePath}/populate-database.py --dbName sbtest --databaseSystem MySQL --benchmark OLTP --threadCount 8 --tableCount 10 --recordCount 1000 --password [A-Za-z0-9+/=]+",
126126
};
127127

128128
int commandNumber = 0;
@@ -173,7 +173,7 @@ public async Task SysbenchConfigurationUsesDefinedParametersWhenRunningTheWorklo
173173
string[] expectedCommands =
174174
{
175175
$"python3 {this.mockPackagePath}/configure-workload-generator.py --distro Ubuntu --databaseSystem MySQL --packagePath {this.mockPackagePath}",
176-
$"python3 {this.mockPackagePath}/populate-database.py --dbName sbtest --databaseSystem MySQL --benchmark OLTP --tableCount 40 --recordCount 1000 --threadCount 16 --password [A-Za-z0-9+/=]+",
176+
$"python3 {this.mockPackagePath}/populate-database.py --dbName sbtest --databaseSystem MySQL --benchmark OLTP --threadCount 16 --tableCount 40 --recordCount 1000 --password [A-Za-z0-9+/=]+",
177177
};
178178

179179
int commandNumber = 0;
@@ -386,7 +386,7 @@ public async Task SysbenchConfigurationProperlyExecutesPostgreSQLOLTPConfigurabl
386386

387387
string[] expectedCommands =
388388
{
389-
$"python3 {this.mockPackagePath}/populate-database.py --dbName sbtest --databaseSystem PostgreSQL --benchmark OLTP --tableCount 40 --recordCount 1000 --threadCount 16 --password [A-Za-z0-9+/=]+"
389+
$"python3 {this.mockPackagePath}/populate-database.py --dbName sbtest --databaseSystem PostgreSQL --benchmark OLTP --threadCount 16 --tableCount 40 --recordCount 1000 --password [A-Za-z0-9+/=]+"
390390
};
391391

392392
int commandNumber = 0;

src/VirtualClient/VirtualClient.Actions.UnitTests/Sysbench/SysbenchMetricsParserTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,17 @@ public void SysbenchParserParsesCorrectly()
4646
MetricAssert.Exists(metrics, "latency p95", 68.05, "milliseconds");
4747
MetricAssert.Exists(metrics, "latency sum", 7458385.25, "milliseconds");
4848
}
49+
50+
[Test]
51+
public void SysbenchParserParsesMetricsMetadataCorrectly()
52+
{
53+
string rawText = File.ReadAllText(Path.Combine(examplesDirectory, "SysbenchExample1.txt"));
54+
SysbenchMetricsParser parser = new SysbenchMetricsParser(rawText);
55+
56+
IList<Metric> metrics = parser.Parse();
57+
Assert.AreEqual(17, metrics.Count);
58+
Assert.IsTrue(metrics[0].Metadata.ContainsKey("sysbench_version"));
59+
Assert.IsTrue(metrics[0].Metadata["sysbench_version"].Equals("1.1.0"));
60+
}
4961
}
5062
}

src/VirtualClient/VirtualClient.Actions/Sysbench/SysbenchClientExecutor.cs

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace VirtualClient.Actions
66
using System;
77
using System.Collections.Generic;
88
using System.Linq;
9-
using System.Net;
9+
using System.Text.RegularExpressions;
1010
using System.Threading;
1111
using System.Threading.Tasks;
1212
using Microsoft.Extensions.DependencyInjection;
@@ -137,9 +137,23 @@ private void CaptureMetrics(IProcessProxy process, EventContext telemetryContext
137137
if (!string.IsNullOrEmpty(text))
138138
{
139139
try
140-
{
140+
{
141141
SysbenchMetricsParser parser = new SysbenchMetricsParser(text);
142142
IList<Metric> metrics = parser.Parse();
143+
string sysbenchVersion = null;
144+
145+
var sysbenchVersionMetric = metrics.FirstOrDefault();
146+
if (sysbenchVersionMetric != null && sysbenchVersionMetric.Metadata.TryGetValue("sysbench_version", out var versionValue))
147+
{
148+
sysbenchVersion = versionValue?.ToString();
149+
}
150+
151+
if (!string.IsNullOrEmpty(sysbenchVersion))
152+
{
153+
this.MetadataContract.Add("sysbench_version", sysbenchVersion, MetadataContract.DependenciesCategory);
154+
}
155+
156+
this.MetadataContract.Apply(telemetryContext);
143157

144158
this.Logger.LogMetrics(
145159
toolName: "Sysbench",
@@ -150,7 +164,8 @@ private void CaptureMetrics(IProcessProxy process, EventContext telemetryContext
150164
null,
151165
scenarioArguments: this.sysbenchLoggingArguments,
152166
this.Tags,
153-
telemetryContext);
167+
telemetryContext,
168+
toolVersion: sysbenchVersion);
154169
}
155170
catch (Exception exc)
156171
{
@@ -166,6 +181,14 @@ private Task ExecuteWorkloadAsync(EventContext telemetryContext, CancellationTok
166181
{
167182
using (BackgroundOperations profiling = BackgroundOperations.BeginProfiling(this, cancellationToken))
168183
{
184+
if (this.DatabaseSystem == "MySQL")
185+
{
186+
string mysqlVersion = await this.GetMySQLVersionAsync(telemetryContext, cancellationToken);
187+
188+
this.MetadataContract.Add("mysql_version", mysqlVersion, MetadataContract.DependenciesCategory);
189+
this.MetadataContract.Apply(telemetryContext);
190+
}
191+
169192
if (this.Benchmark == BenchmarkName.OLTP)
170193
{
171194
if (this.Action == ClientAction.TruncateDatabase)
@@ -182,6 +205,10 @@ private Task ExecuteWorkloadAsync(EventContext telemetryContext, CancellationTok
182205
{
183206
await this.PrepareOLTPMySQLDatabase(telemetryContext, cancellationToken);
184207
}
208+
else if (this.Action == ClientAction.Cleanup)
209+
{
210+
await this.CleanUpDatabase(telemetryContext, cancellationToken);
211+
}
185212
else
186213
{
187214
await this.RunOLTPWorkloadAsync(telemetryContext, cancellationToken);
@@ -229,6 +256,33 @@ private async Task RunOLTPWorkloadAsync(EventContext telemetryContext, Cancellat
229256
}
230257
}
231258

259+
private async Task CleanUpDatabase(EventContext telemetryContext, CancellationToken cancellationToken)
260+
{
261+
int tableCount = GetTableCount(this.DatabaseScenario, this.TableCount, this.Workload);
262+
263+
string serverIp = (this.GetLayoutClientInstances(ClientRole.Server, false) ?? Enumerable.Empty<ClientInstance>())
264+
.FirstOrDefault()?.IPAddress
265+
?? "localhost";
266+
267+
string sysbenchCleanupArguments = $"--dbName {this.DatabaseName} --databaseSystem {this.DatabaseSystem} --benchmark {this.Benchmark} --tableCount {tableCount} --hostIpAddress {serverIp}";
268+
269+
string script = $"{this.SysbenchPackagePath}/cleanup-database.py ";
270+
271+
using (IProcessProxy process = await this.ExecuteCommandAsync(
272+
SysbenchExecutor.PythonCommand,
273+
script + sysbenchCleanupArguments,
274+
this.SysbenchPackagePath,
275+
telemetryContext,
276+
cancellationToken))
277+
{
278+
if (!cancellationToken.IsCancellationRequested)
279+
{
280+
await this.LogProcessDetailsAsync(process, telemetryContext, "Sysbench", logToFile: true);
281+
process.ThrowIfErrored<WorkloadException>(process.StandardError.ToString(), ErrorReason.WorkloadFailed);
282+
}
283+
}
284+
}
285+
232286
private async Task RunTPCCWorkloadAsync(EventContext telemetryContext, CancellationToken cancellationToken)
233287
{
234288
int tableCount = GetTableCount(this.Scenario, this.TableCount, this.Workload);
@@ -288,7 +342,7 @@ private async Task PrepareOLTPMySQLDatabase(EventContext telemetryContext, Cance
288342
int threadCount = GetThreadCount(this.SystemManager, this.DatabaseScenario, this.Threads);
289343
int recordCount = GetRecordCount(this.SystemManager, this.DatabaseScenario, this.RecordCount);
290344

291-
this.sysbenchLoggingArguments = $"--dbName {this.DatabaseName} --databaseSystem {this.DatabaseSystem} --benchmark {this.Benchmark} --tableCount {tableCount} --recordCount {recordCount} --threadCount {threadCount}";
345+
this.sysbenchLoggingArguments = $"--dbName {this.DatabaseName} --databaseSystem {this.DatabaseSystem} --benchmark {this.Benchmark} --threadCount {threadCount} --tableCount {tableCount} --recordCount {recordCount}";
292346
this.sysbenchPrepareArguments = $"{this.sysbenchLoggingArguments} --password {this.SuperUserPassword}";
293347

294348
string serverIp = (this.GetLayoutClientInstances(ClientRole.Server, false) ?? Enumerable.Empty<ClientInstance>())
@@ -315,5 +369,28 @@ private async Task PrepareOLTPMySQLDatabase(EventContext telemetryContext, Cance
315369
}
316370
}
317371
}
372+
373+
/// <summary>
374+
/// Returns MySQL Version.
375+
/// </summary>
376+
/// <returns></returns>
377+
/// <exception cref="Exception"></exception>
378+
private async Task<string> GetMySQLVersionAsync(EventContext telemetryContext, CancellationToken cancellationToken)
379+
{
380+
try
381+
{
382+
IProcessProxy mysqlversionprocess = await this.ExecuteCommandAsync("sudo", $"mysql -u {this.DatabaseName} -h {this.ServerIpAddress} -e \"SELECT VERSION();\"", Environment.CurrentDirectory, telemetryContext, cancellationToken);
383+
string mysqlVersion = mysqlversionprocess.StandardOutput.ToString();
384+
385+
Regex regex = new Regex(@"(\d+\.\d+\.\d+)");
386+
Match match = regex.Match(mysqlVersion);
387+
388+
return match.Success ? match.Groups[1].Value : string.Empty;
389+
}
390+
catch (Exception)
391+
{
392+
return string.Empty;
393+
}
394+
}
318395
}
319396
}

src/VirtualClient/VirtualClient.Actions/Sysbench/SysbenchConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private async Task PrepareOLTPMySQLDatabase(EventContext telemetryContext, Cance
7979
int threadCount = GetThreadCount(this.SystemManager, this.DatabaseScenario, this.Threads);
8080
int recordCount = GetRecordCount(this.SystemManager, this.DatabaseScenario, this.RecordCount);
8181

82-
string sysbenchLoggingArguments = $"--dbName {this.DatabaseName} --databaseSystem {this.DatabaseSystem} --benchmark {this.Benchmark} --tableCount {tableCount} --recordCount {recordCount} --threadCount {threadCount}";
82+
string sysbenchLoggingArguments = $"--dbName {this.DatabaseName} --databaseSystem {this.DatabaseSystem} --benchmark {this.Benchmark} --threadCount {threadCount} --tableCount {tableCount} --recordCount {recordCount}";
8383
this.sysbenchPrepareArguments = $"{sysbenchLoggingArguments} --password {this.SuperUserPassword}";
8484

8585
string serverIp = "localhost";

src/VirtualClient/VirtualClient.Actions/Sysbench/SysbenchExecutor.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ protected void AddMetric(string arguments, IProcessProxy process, EventContext t
411411

412412
List<Metric> metrics = new List<Metric>();
413413
double duration = (process.ExitTime - process.StartTime).TotalMinutes;
414-
metrics.Add(new Metric("PopulateDatabaseTime_Minutes ", duration, "minutes", MetricRelativity.LowerIsBetter));
414+
metrics.Add(new Metric("PopulateDatabaseDuration", duration, "minutes", MetricRelativity.LowerIsBetter));
415415

416416
this.Logger.LogMetrics(
417417
toolName: "Sysbench",
@@ -526,9 +526,14 @@ internal class ClientAction
526526
public const string TruncateDatabase = nameof(TruncateDatabase);
527527

528528
/// <summary>
529-
/// Truncates all tables existing in database
529+
/// Runs specified workload.
530530
/// </summary>
531531
public const string RunWorkload = nameof(RunWorkload);
532+
533+
/// <summary>
534+
/// Runs sysbench cleanup action.
535+
/// </summary>
536+
public const string Cleanup = nameof(Cleanup);
532537
}
533538
}
534539
}

0 commit comments

Comments
 (0)