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 4, 2025
1 parent 1982cf4 commit b8b403f
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 91 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 @@ -100,8 +100,9 @@ await this.ServerApiClient.PollForExpectedStateAsync<CtsTrafficServerState>(
cancellationToken,
this.PollingInterval);

ClientInstance instance = this.Layout.GetClientInstance(this.AgentId);
string targetIPAddress = (instance.Role == ClientRole.Server) ? "localhost" : this.GetServerIpAddress();
string targetIPAddress = (this.GetLayoutClientInstances(ClientRole.Server, false) ?? Enumerable.Empty<ClientInstance>())
.FirstOrDefault()?.IPAddress
?? "localhost";

string ctsTrafficCommandArgs = $"-Target:{targetIPAddress} -Consoleverbosity:1 -StatusFilename:{this.StatusFileName} " +
$@"-ConnectionFilename:{this.ConnectionsFileName} -ErrorFileName:{this.ErrorFileName} -Port:{this.Port} " +
Expand Down Expand Up @@ -148,18 +149,5 @@ await this.ServerApiClient.PollForExpectedStateAsync<CtsTrafficServerState>(
}

}

private string GetServerIpAddress()
{
string serverIPAddress = IPAddress.Loopback.ToString();

if (this.IsMultiRoleLayout())
{
ClientInstance serverInstance = this.GetLayoutClientInstances(ClientRole.Server).First();
serverIPAddress = serverInstance.IPAddress;
}

return serverIPAddress;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ namespace VirtualClient.Actions
{
using System;
using System.Collections.Generic;
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 Microsoft.Extensions.DependencyInjection;
using Polly;
using VirtualClient.Common;
using VirtualClient.Common.Contracts;
using VirtualClient.Common.Extensions;
using VirtualClient.Common.Telemetry;
using VirtualClient.Contracts;
Expand All @@ -26,7 +22,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 +213,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 +241,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 +261,14 @@ private async Task TruncateMySQLDatabaseAsync(EventContext telemetryContext, Can
{
string arguments = $"{this.packageDirectory}/truncate-tables.py --dbName {this.DatabaseName}";

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

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

using (IProcessProxy process = await this.ExecuteCommandAsync(
SysbenchClientExecutor.PythonCommand,
SysbenchExecutor.PythonCommand,
arguments,
Environment.CurrentDirectory,
telemetryContext,
Expand All @@ -294,19 +288,19 @@ 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}";

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

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 +310,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,17 @@ 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}";

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

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

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 @@ -105,6 +102,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 +114,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 +130,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 @@ -6,7 +6,6 @@ namespace VirtualClient.Contracts
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;

/// <summary>
/// Extensions for <see cref="EnvironmentLayout"/> instances.
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
11 changes: 0 additions & 11 deletions src/VirtualClient/VirtualClient.Core/ProfileExpressionEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ public class ProfileExpressionEvaluator : IExpressionEvaluator
// e.g.
// {fn(512 / 16)]}
// {fn(512 / {LogicalThreadCount})}
/*private static readonly Regex CalculateExpression = new Regex(
@"\{calculate\(([0-9\*\/\+\-\(\)\s]+)\)\}",
RegexOptions.Compiled | RegexOptions.IgnoreCase);*/

private static readonly Regex CalculateExpression = new Regex(
@"\{calculate\(([0-9L\*\/\+\-\(\)\s]+)\)\}",
RegexOptions.Compiled | RegexOptions.IgnoreCase);
Expand Down Expand Up @@ -440,16 +436,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 +637,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 +723,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
Loading

0 comments on commit b8b403f

Please sign in to comment.