Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public async Task SysbenchConfigurationProperlyExecutesTPCCConfigurablePreparati

string[] expectedCommands =
{
$"python3 {this.mockPackagePath}/populate-database.py --dbName sbtest --databaseSystem MySQL --benchmark TPCC --threadCount 16 --tableCount 40 --warehouses 999 --password [A-Za-z0-9+/=]+ --hostIpAddress \"1.2.3.5\""
$"python3 {this.mockPackagePath}/populate-database.py --dbName sbtest --databaseSystem MySQL --benchmark TPCC --threadCount 16 --tableCount 40 --warehouses 1000 --password [A-Za-z0-9+/=]+ --hostIpAddress \"1.2.3.5\""
};

int commandNumber = 0;
Expand Down Expand Up @@ -446,7 +446,7 @@ public async Task SysbenchConfigurationProperlyExecutesPostgreSQLTPCCConfigurabl

string[] expectedCommands =
{
$"python3 {this.mockPackagePath}/populate-database.py --dbName sbtest --databaseSystem PostgreSQL --benchmark TPCC --threadCount 16 --tableCount 40 --warehouses 999 --password [A-Za-z0-9+/=]+ --hostIpAddress \"1.2.3.5\""
$"python3 {this.mockPackagePath}/populate-database.py --dbName sbtest --databaseSystem PostgreSQL --benchmark TPCC --threadCount 16 --tableCount 40 --warehouses 1000 --password [A-Za-z0-9+/=]+ --hostIpAddress \"1.2.3.5\""
};

int commandNumber = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace VirtualClient.Actions
/// </summary>
public class HammerDBClientExecutor : HammerDBExecutor
{
private static string runTransactionsTclName = "runTransactions.tcl";

/// <summary>
/// Initializes a new instance of the <see cref="HammerDBClientExecutor"/> class.
/// </summary>
Expand Down Expand Up @@ -154,7 +156,7 @@ private Task ExecuteWorkloadAsync(EventContext telemetryContext, CancellationTok

using (IProcessProxy process = await this.ExecuteCommandAsync(
command,
$"{script} --runTransactionsTCLFilePath {this.RunTransactionsTclName}",
$"{script} --runTransactionsTCLFilePath {runTransactionsTclName}",
this.HammerDBPackagePath,
telemetryContext,
cancellationToken))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace VirtualClient.Actions
[SupportedPlatforms("linux-x64")]
public class HammerDBExecutor : VirtualClientComponent
{
private static string createDBTclName = "createDB.tcl";
private readonly IStateManager stateManager;
private static readonly List<int> Factors = new List<int> { 1, 10, 30, 100, 300, 1000, 3000, 10000, 30000, 100000 };

Expand Down Expand Up @@ -57,28 +58,6 @@ public string Action
}
}

/// <summary>
/// Defines the name of the createDB TCL file.
/// </summary>
public string CreateDBTclName
{
get
{
return "createDB.tcl";
}
}

/// <summary>
/// Defines the name of the runTransactions TCL file.
/// </summary>
public string RunTransactionsTclName
{
get
{
return "runTransactions.tcl";
}
}

/// <summary>
/// Defines the name of the PostgreSQL database to create/use for the transactions.
/// </summary>
Expand Down Expand Up @@ -137,18 +116,6 @@ public string WarehouseCount
}
}

/// <summary>
/// Disk filter specified
/// </summary>
public string DiskFilter
{
get
{
// and 256G
return this.Parameters.GetValue<string>(nameof(this.DiskFilter), "osdisk:false&sizegreaterthan:256g");
}
}

/// <summary>
/// Workload duration.
/// </summary>
Expand Down Expand Up @@ -341,7 +308,7 @@ protected async Task InitializeExecutablesAsync(EventContext telemetryContext, C
private async Task PrepareSQLDatabase(EventContext telemetryContext, CancellationToken cancellationToken)
{
string command = "python3";
string arguments = $"{this.PlatformSpecifics.Combine(this.HammerDBPackagePath, "populate-database.py")} --createDBTCLPath {this.CreateDBTclName}";
string arguments = $"{this.PlatformSpecifics.Combine(this.HammerDBPackagePath, "populate-database.py")} --createDBTCLPath {createDBTclName}";

using (IProcessProxy process = await this.ExecuteCommandAsync(
command,
Expand Down Expand Up @@ -378,17 +345,11 @@ private async Task ConfigureCreateHammerDBFile(EventContext telemetryContext, Ca
}
}

private async Task GenerateCommandLineArguments(CancellationToken cancellationToken)
private Task GenerateCommandLineArguments(CancellationToken cancellationToken)
{
string arguments = $"{this.PlatformSpecifics.Combine(this.HammerDBPackagePath, "configure-workload-generator.py")} --workload {this.Workload} --sqlServer {this.SQLServer} --port {this.Port}" +
$" --virtualUsers {this.VirtualUsers} --password {this.SuperUserPassword} --dbName {this.DatabaseName} --hostIPAddress {this.ServerIpAddress}";

if (this.IsMultiRoleLayout() && this.GetLayoutClientInstance().Role == ClientRole.Server)
{
string directories = await this.GetDataDirectoriesAsync(cancellationToken);
arguments = $"{arguments} --directories {directories}";
}

if (this.Workload.Equals("tpcc", StringComparison.OrdinalIgnoreCase))
{
arguments = $"{arguments} --warehouseCount {this.WarehouseCount} --duration {this.Duration.TotalMinutes}";
Expand All @@ -407,50 +368,8 @@ private async Task GenerateCommandLineArguments(CancellationToken cancellationTo
}

this.HammerDBScenarioArguments = arguments;
}

private async Task<string> GetDataDirectoriesAsync(CancellationToken cancellationToken)
{
string diskPaths = string.Empty;

if (!cancellationToken.IsCancellationRequested)
{
IEnumerable<Disk> disks = await this.SystemManager.DiskManager.GetDisksAsync(cancellationToken)
.ConfigureAwait(false);

if (disks?.Any() != true)
{
throw new WorkloadException(
"Unexpected scenario. The disks defined for the system could not be properly enumerated.",
ErrorReason.WorkloadUnexpectedAnomaly);
}

IEnumerable<Disk> disksToTest = DiskFilters.FilterDisks(disks, this.DiskFilter, this.Platform).ToList();

if (disksToTest?.Any() != true)
{
throw new WorkloadException(
"Expected disks to test not found. Given the parameters defined for the profile action/step or those passed " +
"in on the command line, the requisite disks do not exist on the system or could not be identified based on the properties " +
"of the existing disks.",
ErrorReason.DependencyNotFound);
}

foreach (Disk disk in disksToTest)
{
string path = this.Combine(disk.GetPreferredAccessPath(this.Platform), $"{this.SQLServer.ToLower()}");

// Create the directory if it doesn't exist
if (!this.SystemManager.FileSystem.Directory.Exists(path))
{
this.SystemManager.FileSystem.Directory.CreateDirectory(path);
}

diskPaths += $"{path}:";
}
}

return diskPaths;
return Task.CompletedTask;
}

private static Task OpenFirewallPortsAsync(int port, IFirewallManager firewallManager, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private Task ExecuteWorkloadAsync(EventContext telemetryContext, CancellationTok
{
using (BackgroundOperations profiling = BackgroundOperations.BeginProfiling(this, cancellationToken))
{
this.sysbenchLoggingArguments = this.BuildSysbenchLoggingArguments(SysbenchMode.Run);
this.sysbenchLoggingArguments = this.BuildSysbenchLoggingArguments();
this.sysbenchExecutionArguments = $"{this.sysbenchLoggingArguments} --workload {this.Workload} --hostIpAddress {this.ServerIpAddress} --durationSecs {this.Duration.TotalSeconds} --password {this.SuperUserPassword}";

string script = $"{this.SysbenchPackagePath}/run-workload.py ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,12 @@ protected override async Task ExecuteAsync(EventContext telemetryContext, Cancel
case ConfigurationAction.Cleanup:
await this.CleanUpDatabase(telemetryContext, cancellationToken);
break;
case ConfigurationAction.CreateTables:
await this.PrepareDatabase(telemetryContext, cancellationToken);
break;
case ConfigurationAction.PopulateTables:
await this.PopulateDatabase(telemetryContext, cancellationToken);
break;
default:
throw new DependencyException(
$"The specified Sysbench action '{this.Action}' is not supported. Supported actions include: \"{ConfigurationAction.PopulateTables}, {ConfigurationAction.Cleanup}, {ConfigurationAction.CreateTables}\".",
$"The specified Sysbench action '{this.Action}' is not supported. Supported actions include: \"{ConfigurationAction.PopulateTables}, {ConfigurationAction.Cleanup}\".",
ErrorReason.NotSupported);
}
}
Expand Down Expand Up @@ -106,41 +103,6 @@ private async Task CleanUpDatabase(EventContext telemetryContext, CancellationTo
await this.stateManager.SaveStateAsync<SysbenchState>(nameof(SysbenchState), state, cancellationToken);
}

private async Task PrepareDatabase(EventContext telemetryContext, CancellationToken cancellationToken)
{
SysbenchState state = await this.stateManager.GetStateAsync<SysbenchState>(nameof(SysbenchState), cancellationToken)
?? new SysbenchState();

if (!state.DatabasePopulated)
{
string serverIp = (this.IsMultiRoleLayout() && this.IsInRole(ClientRole.Client)) ? this.ServerIpAddress : "localhost";
string sysbenchPrepareArguments = $"{this.BuildSysbenchLoggingArguments(SysbenchMode.Prepare)} --password {this.SuperUserPassword} --hostIpAddress \"{serverIp}\"";

string command = $"{this.SysbenchPackagePath}/populate-database.py";

using (IProcessProxy process = await this.ExecuteCommandAsync(
SysbenchExecutor.PythonCommand,
$"{command} {sysbenchPrepareArguments}",
this.SysbenchPackagePath,
telemetryContext,
cancellationToken))
{
if (!cancellationToken.IsCancellationRequested)
{
await this.LogProcessDetailsAsync(process, telemetryContext, "Sysbench", logToFile: true);
process.ThrowIfErrored<WorkloadException>(process.StandardError.ToString(), ErrorReason.WorkloadUnexpectedAnomaly);
}
}
}
else
{
throw new DependencyException(
$"Database preparation failed. A database has already been populated on the system. Please drop the tables, or run \"{ConfigurationAction.Cleanup}\" Action" +
$"before attempting to create new tables on this database.",
ErrorReason.NotSupported);
}
}

private async Task PopulateDatabase(EventContext telemetryContext, CancellationToken cancellationToken)
{
SysbenchState state = await this.stateManager.GetStateAsync<SysbenchState>(nameof(SysbenchState), cancellationToken)
Expand All @@ -152,7 +114,7 @@ await this.Logger.LogMessageAsync($"{this.TypeName}.PopulateDatabase", telemetry
{
string serverIp = (this.IsMultiRoleLayout() && this.IsInRole(ClientRole.Client)) ? this.ServerIpAddress : "localhost";

string sysbenchLoggingArguments = this.BuildSysbenchLoggingArguments(SysbenchMode.Populate);
string sysbenchLoggingArguments = this.BuildSysbenchLoggingArguments();
this.sysbenchPopulationArguments = $"{sysbenchLoggingArguments} --password {this.SuperUserPassword} --hostIpAddress \"{serverIp}\"";

string script = $"{this.SysbenchPackagePath}/populate-database.py";
Expand Down Expand Up @@ -227,11 +189,6 @@ private void AddPopulationDurationMetric(string arguments, IProcessProxy process
/// </summary>
internal class ConfigurationAction
{
/// <summary>
/// Initializes the tables on the database.
/// </summary>
public const string CreateTables = nameof(CreateTables);

/// <summary>
/// Creates Database on MySQL server and Users on Server and any Clients.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,6 @@ public SysbenchExecutor(IServiceCollection dependencies, IDictionary<string, ICo
};
}

/// <summary>
/// Defines the mode in which Sysbench is operating.
/// </summary>
protected internal enum SysbenchMode
{
/// <summary>
/// Creates the database schema with minimal data.
/// </summary>
Prepare,

/// <summary>
/// Populates the database with the full dataset.
/// </summary>
Populate,

/// <summary>
/// Runs the benchmark workload.
/// </summary>
Run
}

/// <summary>
/// The benchmark (e.g. OLTP, TPCC).
/// </summary>
Expand Down Expand Up @@ -409,7 +388,7 @@ protected async Task InitializeExecutablesAsync(EventContext telemetryContext, C
/// dbName, databaseSystem, benchmark and tableCount.
/// </summary>
/// <returns></returns>
protected string BuildSysbenchLoggingArguments(SysbenchMode mode)
protected string BuildSysbenchLoggingArguments()
{
int tableCount = GetTableCount(this.DatabaseScenario, this.TableCount, this.Workload);
int threadCount = GetThreadCount(this.SystemManager, this.DatabaseScenario, this.Threads);
Expand All @@ -419,19 +398,11 @@ protected string BuildSysbenchLoggingArguments(SysbenchMode mode)
switch (this.Benchmark)
{
case BenchmarkName.OLTP:
int recordCount = mode == SysbenchMode.Prepare ? 1 : GetRecordCount(this.SystemManager, this.DatabaseScenario, this.RecordCount);
int recordCount = GetRecordCount(this.SystemManager, this.DatabaseScenario, this.RecordCount);
loggingArguments = $"{loggingArguments} --recordCount {recordCount}";
break;
case BenchmarkName.TPCC:
int warehouseEstimate = GetWarehouseCount(this.SystemManager, this.DatabaseScenario, this.WarehouseCount);
int warehouseCount = mode switch
{
SysbenchMode.Prepare => 1,
SysbenchMode.Populate => Math.Max(1, warehouseEstimate - 1),
SysbenchMode.Run => warehouseEstimate,
_ => warehouseEstimate
};

int warehouseCount = GetWarehouseCount(this.SystemManager, this.DatabaseScenario, this.WarehouseCount);
loggingArguments = $"{loggingArguments} --warehouses {warehouseCount}";
break;
default:
Expand Down
Loading
Loading