Skip to content

Commit 4444a8f

Browse files
committed
adding cleanup for sysbench
1 parent d630c41 commit 4444a8f

2 files changed

Lines changed: 41 additions & 3 deletions

File tree

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ private Task ExecuteWorkloadAsync(EventContext telemetryContext, CancellationTok
182182
{
183183
await this.PrepareOLTPMySQLDatabase(telemetryContext, cancellationToken);
184184
}
185+
else if (this.Action == ClientAction.Cleanup)
186+
{
187+
await this.CleanUpDatabase(telemetryContext, cancellationToken);
188+
}
185189
else
186190
{
187191
await this.RunOLTPWorkloadAsync(telemetryContext, cancellationToken);
@@ -229,6 +233,35 @@ private async Task RunOLTPWorkloadAsync(EventContext telemetryContext, Cancellat
229233
}
230234
}
231235

236+
private async Task CleanUpDatabase(EventContext telemetryContext, CancellationToken cancellationToken)
237+
{
238+
int tableCount = GetTableCount(this.DatabaseScenario, this.TableCount, this.Workload);
239+
240+
string serverIp = (this.GetLayoutClientInstances(ClientRole.Server, false) ?? Enumerable.Empty<ClientInstance>())
241+
.FirstOrDefault()?.IPAddress
242+
?? "localhost";
243+
244+
string sysbenchCleanupArguments = $"--dbName {this.DatabaseName} --databaseSystem {this.DatabaseSystem} --benchmark {this.Benchmark} --tableCount {tableCount} --hostIpAddress {serverIp}";
245+
246+
string script = $"{this.SysbenchPackagePath}/cleanup-database.py ";
247+
248+
using (IProcessProxy process = await this.ExecuteCommandAsync(
249+
SysbenchExecutor.PythonCommand,
250+
script + this.sysbenchExecutionArguments,
251+
this.SysbenchPackagePath,
252+
telemetryContext,
253+
cancellationToken))
254+
{
255+
if (!cancellationToken.IsCancellationRequested)
256+
{
257+
await this.LogProcessDetailsAsync(process, telemetryContext, "Sysbench", logToFile: true);
258+
process.ThrowIfErrored<WorkloadException>(process.StandardError.ToString(), ErrorReason.WorkloadFailed);
259+
260+
this.CaptureMetrics(process, telemetryContext, cancellationToken);
261+
}
262+
}
263+
}
264+
232265
private async Task RunTPCCWorkloadAsync(EventContext telemetryContext, CancellationToken cancellationToken)
233266
{
234267
int tableCount = GetTableCount(this.Scenario, this.TableCount, this.Workload);
@@ -288,7 +321,7 @@ private async Task PrepareOLTPMySQLDatabase(EventContext telemetryContext, Cance
288321
int threadCount = GetThreadCount(this.SystemManager, this.DatabaseScenario, this.Threads);
289322
int recordCount = GetRecordCount(this.SystemManager, this.DatabaseScenario, this.RecordCount);
290323

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

294327
string serverIp = (this.GetLayoutClientInstances(ClientRole.Server, false) ?? Enumerable.Empty<ClientInstance>())

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

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

418418
List<Metric> metrics = new List<Metric>();
419419
double duration = (process.ExitTime - process.StartTime).TotalMinutes;
420-
metrics.Add(new Metric("PopulateDatabaseTime_Minutes ", duration, "minutes", MetricRelativity.LowerIsBetter));
420+
metrics.Add(new Metric("PopulateDatabaseTime_Minutes", duration, "minutes", MetricRelativity.LowerIsBetter));
421421

422422
this.Logger.LogMetrics(
423423
toolName: "Sysbench",
@@ -532,9 +532,14 @@ internal class ClientAction
532532
public const string TruncateDatabase = nameof(TruncateDatabase);
533533

534534
/// <summary>
535-
/// Truncates all tables existing in database
535+
/// Runs specified workload.
536536
/// </summary>
537537
public const string RunWorkload = nameof(RunWorkload);
538+
539+
/// <summary>
540+
/// Runs sysbench cleanup action.
541+
/// </summary>
542+
public const string Cleanup = nameof(Cleanup);
538543
}
539544
}
540545
}

0 commit comments

Comments
 (0)