Skip to content

Commit

Permalink
adding new parameter while database population and some code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
nmalkapuram committed Feb 3, 2025
1 parent 1982cf4 commit a6d5691
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void MySQLSysbenchOLTPWorkloadProfileActionsWillNotBeExecutedIfTheWorkloa

[Test]
[TestCase("PERF-MYSQL-SYSBENCH-OLTP.json", PlatformID.Unix, Architecture.X64)]
// [Ignore("This functional test takes more than a minute to run. There is likely a Task.Delay somewhere that needs to be designed better to avoid long blocking behavior")]
[Ignore("This functional test takes more than a minute to run. There is likely a Task.Delay somewhere that needs to be designed better to avoid long blocking behavior")]
public async Task MySQLSysbenchOLTPWorkloadProfileExecutesTheExpectedWorkloadsOnUnixPlatform(string profile, PlatformID platform, Architecture architecture)
{
this.fixture.Setup(platform, architecture, this.clientAgentId).SetupLayout(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ namespace VirtualClient.Actions
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using MathNet.Numerics;
using Microsoft.Extensions.DependencyInjection;
using Polly;
using VirtualClient.Common;
Expand All @@ -26,7 +28,6 @@ namespace VirtualClient.Actions
/// </summary>
public class SysbenchClientExecutor : SysbenchExecutor
{
private const string PythonCommand = "python3";
private string sysbenchExecutionArguments;
private string sysbenchLoggingArguments;
private string sysbenchPrepareArguments;
Expand Down Expand Up @@ -218,7 +219,7 @@ private async Task RunOLTPWorkloadAsync(EventContext telemetryContext, Cancellat
string script = $"{this.SysbenchPackagePath}/run-workload.py ";

using (IProcessProxy process = await this.ExecuteCommandAsync(
SysbenchClientExecutor.PythonCommand,
SysbenchExecutor.PythonCommand,
script + this.sysbenchExecutionArguments,
this.SysbenchPackagePath,
telemetryContext,
Expand Down Expand Up @@ -246,7 +247,7 @@ private async Task RunTPCCWorkloadAsync(EventContext telemetryContext, Cancellat
string script = $"{this.SysbenchPackagePath}/run-workload.py ";

using (IProcessProxy process = await this.ExecuteCommandAsync(
SysbenchClientExecutor.PythonCommand,
SysbenchExecutor.PythonCommand,
script + this.sysbenchExecutionArguments,
this.SysbenchPackagePath,
telemetryContext,
Expand All @@ -266,15 +267,18 @@ private async Task TruncateMySQLDatabaseAsync(EventContext telemetryContext, Can
{
string arguments = $"{this.packageDirectory}/truncate-tables.py --dbName {this.DatabaseName}";

string serverIps = "localhost";

if (this.IsMultiRoleLayout())
{
ClientInstance instance = this.Layout.GetClientInstance(this.AgentId);
string serverIps = (instance.Role == ClientRole.Server) ? "localhost" : this.GetServerIpAddress();
arguments += $" --clientIps \"{serverIps}\"";
serverIps = (instance.Role == ClientRole.Server) ? "localhost" : this.GetLayoutClientInstances(ClientRole.Server).First().IPAddress;
}

arguments += $" --clientIps \"{serverIps}\"";

using (IProcessProxy process = await this.ExecuteCommandAsync(
SysbenchClientExecutor.PythonCommand,
SysbenchExecutor.PythonCommand,
arguments,
Environment.CurrentDirectory,
telemetryContext,
Expand All @@ -294,19 +298,23 @@ private async Task PrepareOLTPMySQLDatabase(EventContext telemetryContext, Cance
int threadCount = GetThreadCount(this.SystemManager, this.DatabaseScenario, this.Threads);
int recordCount = GetRecordCount(this.SystemManager, this.DatabaseScenario, this.RecordCount);

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

string serverIp = "localhost";

if (this.IsMultiRoleLayout())
{
ClientInstance instance = this.Layout.GetClientInstance(this.AgentId);
string serverIp = (instance.Role == ClientRole.Server) ? "localhost" : this.GetServerIpAddress();
this.sysbenchPrepareArguments += $" --host \"{serverIp}\"";
serverIp = (instance.Role == ClientRole.Server) ? "localhost" : this.GetLayoutClientInstances(ClientRole.Server).First().IPAddress;
}

this.sysbenchPrepareArguments += $" --host \"{serverIp}\"";

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

using (IProcessProxy process = await this.ExecuteCommandAsync(
SysbenchClientExecutor.PythonCommand,
SysbenchExecutor.PythonCommand,
arguments + this.sysbenchPrepareArguments,
this.SysbenchPackagePath,
telemetryContext,
Expand All @@ -316,6 +324,8 @@ private async Task PrepareOLTPMySQLDatabase(EventContext telemetryContext, Cance
{
await this.LogProcessDetailsAsync(process, telemetryContext, "Sysbench", logToFile: true);
process.ThrowIfErrored<WorkloadException>(process.StandardError.ToString(), ErrorReason.WorkloadUnexpectedAnomaly);

this.AddMetric(this.sysbenchLoggingArguments, process, telemetryContext, cancellationToken);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,23 @@ private async Task PrepareOLTPMySQLDatabase(EventContext telemetryContext, Cance
int threadCount = GetThreadCount(this.SystemManager, this.DatabaseScenario, this.Threads);
int recordCount = GetRecordCount(this.SystemManager, this.DatabaseScenario, this.RecordCount);

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

string serverIp = "localhost";

if (this.IsMultiRoleLayout())
{
ClientInstance instance = this.Layout.GetClientInstance(this.AgentId);
string serverIp = (instance.Role == ClientRole.Server) ? "localhost" : this.GetServerIpAddress();
this.sysbenchPrepareArguments += $" --host \"{serverIp}\"";
serverIp = (instance.Role == ClientRole.Server) ? "localhost" : this.GetLayoutClientInstances(ClientRole.Server).First().IPAddress;
}

string command = $"python3";
this.sysbenchPrepareArguments += $" --host \"{serverIp}\"";

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

using (IProcessProxy process = await this.ExecuteCommandAsync(
command,
SysbenchExecutor.PythonCommand,
arguments + this.sysbenchPrepareArguments,
this.SysbenchPackagePath,
telemetryContext,
Expand All @@ -105,6 +108,8 @@ private async Task PrepareOLTPMySQLDatabase(EventContext telemetryContext, Cance
{
await this.LogProcessDetailsAsync(process, telemetryContext, "Sysbench", logToFile: true);
process.ThrowIfErrored<WorkloadException>(process.StandardError.ToString(), ErrorReason.WorkloadUnexpectedAnomaly);

this.AddMetric(sysbenchLoggingArguments, process, telemetryContext, cancellationToken);
}
}
}
Expand All @@ -115,13 +120,13 @@ private async Task PrepareTPCCMySQLDatabase(EventContext telemetryContext, Cance
int threadCount = GetThreadCount(this.SystemManager, this.DatabaseScenario, this.Threads);
int warehouseCount = GetWarehouseCount(this.DatabaseScenario, this.WarehouseCount);

this.sysbenchPrepareArguments = $"--dbName {this.DatabaseName} --databaseSystem {this.DatabaseSystem} --benchmark {this.Benchmark} --tableCount {tableCount} --warehouses {warehouseCount} --threadCount {threadCount} --password {this.SuperUserPassword}";
string sysbenchLoggingArguments = $"--dbName {this.DatabaseName} --databaseSystem {this.DatabaseSystem} --benchmark {this.Benchmark} --tableCount {tableCount} --warehouses {warehouseCount} --threadCount {threadCount}";
this.sysbenchPrepareArguments = $"{sysbenchLoggingArguments} --password {this.SuperUserPassword}";

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

using (IProcessProxy process = await this.ExecuteCommandAsync(
command,
SysbenchExecutor.PythonCommand,
arguments + this.sysbenchPrepareArguments,
this.SysbenchPackagePath,
telemetryContext,
Expand All @@ -131,6 +136,8 @@ private async Task PrepareTPCCMySQLDatabase(EventContext telemetryContext, Cance
{
await this.LogProcessDetailsAsync(process, telemetryContext, "Sysbench", logToFile: true);
process.ThrowIfErrored<WorkloadException>(process.StandardError.ToString(), ErrorReason.WorkloadUnexpectedAnomaly);

this.AddMetric(sysbenchLoggingArguments, process, telemetryContext, cancellationToken);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace VirtualClient.Actions
using VirtualClient.Common.Extensions;
using VirtualClient.Common.Telemetry;
using VirtualClient.Contracts;
using VirtualClient.Contracts.Metadata;

/// <summary>
/// The Sysbench workload executor.
Expand All @@ -35,6 +36,11 @@ public class SysbenchExecutor : VirtualClientComponent
/// </summary>
public const int SelectWorkloadDefaultTableCount = 1;

/// <summary>
/// const for python command.
/// </summary>
protected const string PythonCommand = "python3";

private readonly IStateManager stateManager;
private static readonly string[] SelectWorkloads =
{
Expand Down Expand Up @@ -393,20 +399,40 @@ protected async Task InitializeExecutablesAsync(EventContext telemetryContext, C
}

/// <summary>
///
/// Add metrics to telemtry.
/// </summary>
/// <returns></returns>
protected string GetServerIpAddress()
/// <param name="arguments"></param>
/// <param name="process"></param>
/// <param name="telemetryContext"></param>
/// <param name="cancellationToken"></param>
protected void AddMetric(string arguments, IProcessProxy process, EventContext telemetryContext, CancellationToken cancellationToken)
{
string serverIPAddress = IPAddress.Loopback.ToString();

if (this.IsMultiRoleLayout())
if (!cancellationToken.IsCancellationRequested)
{
ClientInstance serverInstance = this.GetLayoutClientInstances(ClientRole.Server).First();
serverIPAddress = serverInstance.IPAddress;
this.MetadataContract.AddForScenario(
"Sysbench",
process.FullCommand(),
toolVersion: null);

this.MetadataContract.Apply(telemetryContext);

string text = process.StandardOutput.ToString();

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

this.Logger.LogMetrics(
toolName: "Sysbench",
scenarioName: this.MetricScenario ?? this.Scenario,
process.StartTime,
process.ExitTime,
metrics,
null,
scenarioArguments: arguments,
this.Tags,
telemetryContext);
}

return serverIPAddress;
}

private async Task CheckDistroSupportAsync(EventContext telemetryContext, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,6 @@ public async Task ExecuteAsync(CancellationToken cancellationToken)

if (this.Parameters?.Any() == true)
{
Console.WriteLine("before adding parameters to dictonary");
this.MetadataContract.Add(
this.Parameters.Keys.ToDictionary(key => key, entry => this.Parameters[entry] as object).ObscureSecrets(),
MetadataContractCategory.Scenario,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,6 @@ public async Task ProfileExpressionEvaluatorSupportsFunctionReferences()

Dictionary<string, string> expressions = new Dictionary<string, string>
{
{"{calculate(67419566080 * 800000 / 100)}", "23456"},
{ "{calculate(512 + 2)}", "514" },
{ "{calculate(512 - 2)}", "510" },
{ "{calculate(512 * 2)}", "1024" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,16 +440,12 @@ public class ProfileExpressionEvaluator : IExpressionEvaluator

if (matches?.Any() == true)
{
Console.WriteLine($"just before c# script");
isMatched = true;
foreach (Match match in matches)
{
string function = match.Groups[1].Value;
Console.WriteLine($"just before c# script");
long result = await Microsoft.CodeAnalysis.CSharp.Scripting.CSharpScript.EvaluateAsync<long>(function);
Console.WriteLine($"the result after csharpscript is {result}");
evaluatedExpression = evaluatedExpression.Replace(match.Value, result.ToString());
Console.WriteLine($"evaluated expression {evaluatedExpression}");
}
}

Expand Down Expand Up @@ -645,7 +641,6 @@ private static async Task<EvaluationResult> EvaluateExpressionAsync(IServiceColl
{
isMatched = true;
evaluatedExpression = evaluation.Outcome;
Console.WriteLine($"Evaluated expression in evaluateexpressionasync {evaluatedExpression}");
}
}
}
Expand Down Expand Up @@ -732,9 +727,7 @@ private static async Task<bool> EvaluateWellKnownExpressionsAsync(IServiceCollec
EvaluationResult evaluation = await ProfileExpressionEvaluator.EvaluateExpressionAsync(dependencies, parameters, parameter.Value.ToString(), cancellationToken);
if (evaluation.IsMatched)
{
Console.WriteLine($"After evaluation in runtime {evaluation.Outcome}");
parameters[parameter.Key] = evaluation.Outcome;
Console.WriteLine($"After assigning it to parameter key in runtime {evaluation.Outcome}");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace VirtualClient.Dependencies.MySqlServer
using VirtualClient.Common.Extensions;
using VirtualClient.Common.Telemetry;
using VirtualClient.Contracts;
using YamlDotNet.Core.Tokens;

/// <summary>
/// Installation component for MySQL
Expand Down Expand Up @@ -64,13 +65,18 @@ public bool SkipInitialize
}

/// <summary>
/// stripeddisk mount point.
/// stripedisk mount point.
/// </summary>
public string StripeDiskMountPoint
{
get
{
return this.Parameters.GetValue<string>(nameof(this.StripeDiskMountPoint), null);
if (this.Parameters.TryGetValue(nameof(this.StripeDiskMountPoint), out IConvertible stripediskmountpoint) && stripediskmountpoint != null)
{
return stripediskmountpoint.ToString();
}

return string.Empty;
}
}

Expand Down Expand Up @@ -175,7 +181,7 @@ await this.SetMySQLGlobalVariableAsync(telemetryContext, cancellationToken)
private async Task ConfigureMySQLServerAsync(EventContext telemetryContext, CancellationToken cancellationToken)
{
string serverIp = this.GetServerIpAddress();
string innoDbDirs = this.StripeDiskMountPoint != null ? this.StripeDiskMountPoint : await this.GetMySQLInnodbDirectoriesAsync(cancellationToken);
string innoDbDirs = !string.IsNullOrEmpty(this.StripeDiskMountPoint) ? this.StripeDiskMountPoint : await this.GetMySQLInnodbDirectoriesAsync(cancellationToken);

string arguments = $"{this.packageDirectory}/configure.py --serverIp {serverIp} --innoDbDirs \"{innoDbDirs}\"";

Expand Down

0 comments on commit a6d5691

Please sign in to comment.