diff --git a/src/VirtualClient/VirtualClient.Actions.FunctionalTests/SysbenchOLTP/SysbenchOLTPClientProfileTests.cs b/src/VirtualClient/VirtualClient.Actions.FunctionalTests/SysbenchOLTP/SysbenchOLTPClientProfileTests.cs index de8a340752..a6e87dd6ae 100644 --- a/src/VirtualClient/VirtualClient.Actions.FunctionalTests/SysbenchOLTP/SysbenchOLTPClientProfileTests.cs +++ b/src/VirtualClient/VirtualClient.Actions.FunctionalTests/SysbenchOLTP/SysbenchOLTPClientProfileTests.cs @@ -10,11 +10,12 @@ namespace VirtualClient.Actions using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis.Scripting; using Moq; using NUnit.Framework; using VirtualClient.Common; + using VirtualClient.Common.Contracts; using VirtualClient.Contracts; + using static VirtualClient.Actions.SysbenchOLTPExecutor; [TestFixture] [Category("Functional")] @@ -54,8 +55,13 @@ public void SysbenchOLTPWorkloadProfileActionsWillNotBeExecutedIfTheWorkloadPack [TestCase("PERF-MYSQL-SYSBENCH-OLTP.json", PlatformID.Unix, Architecture.X64)] public async Task SysbenchOLTPWorkloadProfileExecutesTheExpectedWorkloadsOnUnixPlatform(string profile, PlatformID platform, Architecture architecture) { - IEnumerable expectedCommands = this.GetProfileExpectedCommands(platform, architecture); + IEnumerable expectedCommands = this.GetProfileExpectedCommands(singleVM: false); this.SetupDefaultMockBehaviors(platform, architecture); + + this.mockFixture.Setup(PlatformID.Unix, architecture, this.clientAgentId).SetupLayout( + new ClientInstance(this.clientAgentId, "1.2.3.4", "Client"), + new ClientInstance(this.serverAgentId, "1.2.3.5", "Server")); + this.SetupApiClient(this.serverAgentId, serverIPAddress: "1.2.3.5"); string scriptPath = this.mockFixture.PlatformSpecifics.GetScriptPath("sysbencholtp"); @@ -86,44 +92,106 @@ public async Task SysbenchOLTPWorkloadProfileExecutesTheExpectedWorkloadsOnUnixP } } - private IEnumerable GetProfileExpectedCommands(PlatformID platform, Architecture architecture) + [Test] + [TestCase("PERF-MYSQL-SYSBENCH-OLTP.json", PlatformID.Unix, Architecture.X64)] + public async Task SysbenchOLTPWorkloadProfileExecutesTheExpectedWorkloadsOnSingleVMUnixPlatform(string profile, PlatformID platform, Architecture architecture) { - return new List() + IEnumerable expectedCommands = this.GetProfileExpectedCommands(singleVM: true); + this.SetupDefaultMockBehaviors(platform, architecture); + + this.mockFixture.Setup(PlatformID.Unix, architecture, this.clientAgentId).SetupLayout( + new ClientInstance(this.serverAgentId, "1.2.3.5", "Server")); + + this.SetupApiClient(this.serverAgentId, serverIPAddress: "1.2.3.5"); + + string scriptPath = this.mockFixture.PlatformSpecifics.GetScriptPath("sysbencholtp"); + + string balancedClientScript = this.mockFixture.PlatformSpecifics.Combine(scriptPath, "balanced-client.sh"); + string balancedServerScript = this.mockFixture.PlatformSpecifics.Combine(scriptPath, "balanced-server.sh"); + string inMemoryScript = this.mockFixture.PlatformSpecifics.Combine(scriptPath, "in-memory.sh"); + + this.mockFixture.SetupFile(balancedServerScript); + this.mockFixture.SetupFile(balancedClientScript); + this.mockFixture.SetupFile(inMemoryScript); + + this.mockFixture.ProcessManager.OnCreateProcess = (command, arguments, workingDir) => { - "git clone https://github.com/akopytov/sysbench.git /home/user/tools/VirtualClient/packages/sysbench", - - "sudo ./autogen.sh", - "sudo ./configure", - "sudo make -j", - "sudo make install", - - $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=64 --tables=10 --table-size=10000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=1200 cleanup", - $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_common --tables=10 --table-size=10000 --mysql-db=sbtest --mysql-host=1.2.3.5 prepare", - $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=64 --tables=10 --table-size=10000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=1200 run", - $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_only --threads=64 --tables=10 --table-size=10000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=1200 run", - $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_delete --threads=64 --tables=10 --table-size=10000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=1200 run", - $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_insert --threads=64 --tables=10 --table-size=10000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=1200 run", - $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_update_index --threads=64 --tables=10 --table-size=10000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=1200 run", - $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_update_non_index --threads=64 --tables=10 --table-size=10000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=1200 run", - $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench select_random_points --threads=64 --tables=1 --table-size=10000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=1200 run", - $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench select_random_ranges --threads=64 --tables=1 --table-size=10000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=1200 run" + IProcessProxy process = this.mockFixture.CreateProcess(command, arguments, workingDir); + if (arguments.Contains("run", StringComparison.OrdinalIgnoreCase)) + { + process.StandardOutput.Append(TestDependencies.GetResourceFileContents("Results_SysbenchOLTP.txt")); + } + + return process; }; + + using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies)) + { + await executor.ExecuteAsync(ProfileTiming.OneIteration(), CancellationToken.None).ConfigureAwait(false); + WorkloadAssert.CommandsExecuted(this.mockFixture, expectedCommands.ToArray()); + } + } + + private IEnumerable GetProfileExpectedCommands(bool singleVM) + { + if (singleVM) + { + return new List() + { + "git clone https://github.com/akopytov/sysbench.git /home/user/tools/VirtualClient/packages/sysbench", + + "sudo ./autogen.sh", + "sudo ./configure", + "sudo make -j", + "sudo make install", + + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=64 --tables=10 --table-size=10000 --mysql-db=sbtest --mysql-host=127.0.0.1 --time=1200 cleanup", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_common --tables=10 --table-size=10000 --mysql-db=sbtest --mysql-host=127.0.0.1 prepare", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=64 --tables=10 --table-size=10000 --mysql-db=sbtest --mysql-host=127.0.0.1 --time=1200 run", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_only --threads=64 --tables=10 --table-size=10000 --mysql-db=sbtest --mysql-host=127.0.0.1 --time=1200 run", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_delete --threads=64 --tables=10 --table-size=10000 --mysql-db=sbtest --mysql-host=127.0.0.1 --time=1200 run", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_insert --threads=64 --tables=10 --table-size=10000 --mysql-db=sbtest --mysql-host=127.0.0.1 --time=1200 run", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_update_index --threads=64 --tables=10 --table-size=10000 --mysql-db=sbtest --mysql-host=127.0.0.1 --time=1200 run", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_update_non_index --threads=64 --tables=10 --table-size=10000 --mysql-db=sbtest --mysql-host=127.0.0.1 --time=1200 run", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench select_random_points --threads=64 --tables=1 --table-size=10000 --mysql-db=sbtest --mysql-host=127.0.0.1 --time=1200 run", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench select_random_ranges --threads=64 --tables=1 --table-size=10000 --mysql-db=sbtest --mysql-host=127.0.0.1 --time=1200 run" + }; + } + else + { + return new List() + { + "git clone https://github.com/akopytov/sysbench.git /home/user/tools/VirtualClient/packages/sysbench", + + "sudo ./autogen.sh", + "sudo ./configure", + "sudo make -j", + "sudo make install", + + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=64 --tables=10 --table-size=10000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=1200 cleanup", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_common --tables=10 --table-size=10000 --mysql-db=sbtest --mysql-host=1.2.3.5 prepare", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=64 --tables=10 --table-size=10000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=1200 run", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_only --threads=64 --tables=10 --table-size=10000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=1200 run", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_delete --threads=64 --tables=10 --table-size=10000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=1200 run", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_insert --threads=64 --tables=10 --table-size=10000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=1200 run", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_update_index --threads=64 --tables=10 --table-size=10000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=1200 run", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_update_non_index --threads=64 --tables=10 --table-size=10000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=1200 run", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench select_random_points --threads=64 --tables=1 --table-size=10000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=1200 run", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench select_random_ranges --threads=64 --tables=1 --table-size=10000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=1200 run" + }; + } } private void SetupApiClient(string serverName, string serverIPAddress) { IPAddress.TryParse(serverIPAddress, out IPAddress ipAddress); - IApiClient apiClient = this.mockFixture.ApiClientManager.GetOrCreateApiClient(serverName, ipAddress); + IApiClient apiClient = this.mockFixture.ApiClientManager.GetOrCreateApiClient(serverIPAddress, ipAddress); } private void SetupDefaultMockBehaviors(PlatformID platform, Architecture architecture) { this.mockFixture.Setup(platform, architecture); this.mockFixture.SetupWorkloadPackage("sysbench", expectedFiles: "sysbench"); - this.mockFixture.Setup(PlatformID.Unix, architecture, this.clientAgentId).SetupLayout( - new ClientInstance(this.clientAgentId, "1.2.3.4", "Client"), - new ClientInstance(this.serverAgentId, "1.2.3.5", "Server")); - this.mockFixture.SystemManagement.Setup(mgr => mgr.GetCpuInfoAsync(It.IsAny())) .ReturnsAsync(new CpuInfo("cpu", "description", 4, 8, 4, 4, false)); } diff --git a/src/VirtualClient/VirtualClient.Actions.UnitTests/SysbenchOLTP/SysbenchOLTPClientExecutorTests.cs b/src/VirtualClient/VirtualClient.Actions.UnitTests/SysbenchOLTP/SysbenchOLTPClientExecutorTests.cs index 603499aa03..87d959f771 100644 --- a/src/VirtualClient/VirtualClient.Actions.UnitTests/SysbenchOLTP/SysbenchOLTPClientExecutorTests.cs +++ b/src/VirtualClient/VirtualClient.Actions.UnitTests/SysbenchOLTP/SysbenchOLTPClientExecutorTests.cs @@ -7,6 +7,7 @@ namespace VirtualClient.Actions using Moq; using Newtonsoft.Json.Linq; using NUnit.Framework; + using NUnit.Framework.Interfaces; using Polly; using System; using System.Collections.Generic; @@ -86,9 +87,7 @@ public async Task SysbenchOLTPClientExecutorRunsTheExpectedWorkloadCommand() this.mockFixture.StateManager.OnGetState().ReturnsAsync(JObject.FromObject(new SysbenchOLTPExecutor.SysbenchOLTPState() { - SysbenchInitialized = false, - NumTables = -1, - RecordCount = -1 + SysbenchInitialized = false })); string[] expectedCommands = @@ -97,6 +96,8 @@ public async Task SysbenchOLTPClientExecutorRunsTheExpectedWorkloadCommand() "sudo ./configure", "sudo make -j", "sudo make install", + $"sudo mysql -u sbtest -h 1.2.3.5 sbtest --execute=\"USE sbtest; SHOW tables; SELECT FOUND_ROWS();\"", + $"sudo mysql -u sbtest -h 1.2.3.5 sbtest --execute=\"USE sbtest; SELECT COUNT(*) FROM sbtest1;\"", $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=64 --tables=10 --table-size=100000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=10 cleanup", $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_common --tables=10 --table-size=100000 --mysql-db=sbtest --mysql-host=1.2.3.5 prepare", $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=64 --tables=10 --table-size=100000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=10 run" @@ -141,14 +142,10 @@ public async Task SysbenchOLTPClientExecutorRunsTheExpectedWorkloadCommand() } [Test] - public async Task SysbenchOLTPClientExecutorUsesDefinedParameters() + public async Task SysbenchOLTPClientExecutorPreparesDatabaseIfTableCountIncreased() { SetupDefaultBehavior(); - this.mockFixture.Parameters[nameof(SysbenchOLTPClientExecutor.Threads)] = "8"; - this.mockFixture.Parameters[nameof(SysbenchOLTPClientExecutor.RecordCount)] = "1000"; - this.mockFixture.Parameters[nameof(SysbenchOLTPClientExecutor.NumTables)] = "40"; - this.mockFixture.StateManager.OnGetState().ReturnsAsync(JObject.FromObject(new SysbenchOLTPExecutor.SysbenchOLTPState() { SysbenchInitialized = false @@ -160,9 +157,11 @@ public async Task SysbenchOLTPClientExecutorUsesDefinedParameters() "sudo ./configure", "sudo make -j", "sudo make install", - $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=8 --tables=40 --table-size=1000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=10 cleanup", - $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_common --tables=40 --table-size=1000 --mysql-db=sbtest --mysql-host=1.2.3.5 prepare", - $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=8 --tables=40 --table-size=1000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=10 run" + $"sudo mysql -u sbtest -h 1.2.3.5 sbtest --execute=\"USE sbtest; SHOW tables; SELECT FOUND_ROWS();\"", + $"sudo mysql -u sbtest -h 1.2.3.5 sbtest --execute=\"USE sbtest; SELECT COUNT(*) FROM sbtest1;\"", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=64 --tables=10 --table-size=100000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=10 cleanup", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_common --tables=10 --table-size=100000 --mysql-db=sbtest --mysql-host=1.2.3.5 prepare", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=64 --tables=10 --table-size=100000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=10 run" }; int commandNumber = 0; @@ -191,8 +190,33 @@ public async Task SysbenchOLTPClientExecutorUsesDefinedParameters() OnHasExited = () => true }; - string resultsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Examples", "SysbenchOLTP", "SysbenchOLTPExample.txt"); - process.StandardOutput.Append(File.ReadAllText(resultsPath)); + if (arguments.Contains("run")) + { + string resultsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Examples", "SysbenchOLTP", "SysbenchOLTPExample.txt"); + process.StandardOutput.Append(File.ReadAllText(resultsPath)); + } + + if (arguments.Contains("FOUND_ROWS()")) + { + string numRows = + "+--------------+" + + "| FOUND_ROWS() |" + + "+--------------+" + + "| 4 |" + + "+--------------+"; + process.StandardOutput.Append(numRows); + } + + if (arguments.Contains("COUNT(*)")) + { + string tableCount = + "+----------+" + + "| COUNT(*) |" + + "+----------+" + + "| 2000000 |" + + "+----------+"; + process.StandardOutput.Append(tableCount); + } return process; }; @@ -204,36 +228,26 @@ public async Task SysbenchOLTPClientExecutorUsesDefinedParameters() } [Test] - public async Task SysbenchOLTPClientExecutorRunsTheExpectedWorkloadCommandBalancedScenario() + public async Task SysbenchOLTPClientExecutorPreparesDatabaseIfRecordCountIncreased() { SetupDefaultBehavior(); - SysbenchOLTPState expectedState = new SysbenchOLTPState(new Dictionary - { - [nameof(SysbenchOLTPState.DiskPathsArgument)] = "/testdrive1 /testdrive2" - }); - - this.mockFixture.ApiClient.Setup(client => client.GetStateAsync(nameof(SysbenchOLTPState), It.IsAny(), It.IsAny>())) - .ReturnsAsync(this.mockFixture.CreateHttpResponse(HttpStatusCode.OK, expectedState)); - this.mockFixture.StateManager.OnGetState().ReturnsAsync(JObject.FromObject(new SysbenchOLTPExecutor.SysbenchOLTPState() { SysbenchInitialized = false })); - this.mockFixture.Parameters["DatabaseScenario"] = "Balanced"; - string[] expectedCommands = { - $"sudo chmod -R 2777 \"/home/user/tools/VirtualClient/scripts/sysbencholtp\"", "sudo ./autogen.sh", "sudo ./configure", "sudo make -j", "sudo make install", - $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=1 --tables=10 --table-size=1000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=10 cleanup", - $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_common --tables=10 --table-size=1000 --mysql-db=sbtest --mysql-host=1.2.3.5 prepare", - $"sudo {this.scriptPath}/balanced-client.sh 1.2.3.5 10 sbtest /testdrive1 /testdrive2", - $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=1 --tables=10 --table-size=1000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=10 run" + $"sudo mysql -u sbtest -h 1.2.3.5 sbtest --execute=\"USE sbtest; SHOW tables; SELECT FOUND_ROWS();\"", + $"sudo mysql -u sbtest -h 1.2.3.5 sbtest --execute=\"USE sbtest; SELECT COUNT(*) FROM sbtest1;\"", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=64 --tables=10 --table-size=100000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=10 cleanup", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_common --tables=10 --table-size=100000 --mysql-db=sbtest --mysql-host=1.2.3.5 prepare", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=64 --tables=10 --table-size=100000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=10 run" }; int commandNumber = 0; @@ -262,8 +276,27 @@ public async Task SysbenchOLTPClientExecutorRunsTheExpectedWorkloadCommandBalanc OnHasExited = () => true }; - string resultsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Examples", "SysbenchOLTP", "SysbenchOLTPExample.txt"); - process.StandardOutput.Append(File.ReadAllText(resultsPath)); + if (arguments.Contains("FOUND_ROWS()")) + { + string numRows = + "+--------------+" + + "| FOUND_ROWS() |" + + "+--------------+" + + "| 10 |" + + "+--------------+"; + process.StandardOutput.Append(numRows); + } + + if (arguments.Contains("COUNT(*)")) + { + string tableCount = + "+----------+" + + "| COUNT(*) |" + + "+----------+" + + "| 0 |" + + "+----------+"; + process.StandardOutput.Append(tableCount); + } return process; }; @@ -275,15 +308,30 @@ public async Task SysbenchOLTPClientExecutorRunsTheExpectedWorkloadCommandBalanc } [Test] - public async Task SysbenchOLTPClientExecutorSkipsInitializationOfTheBenchmarkForExecutionAfterTheFirstRun() + public async Task SysbenchOLTPClientExecutorUsesDefinedParameters() { SetupDefaultBehavior(); + this.mockFixture.Parameters[nameof(SysbenchOLTPClientExecutor.Threads)] = "8"; + this.mockFixture.Parameters[nameof(SysbenchOLTPClientExecutor.RecordCount)] = "1000"; + this.mockFixture.Parameters[nameof(SysbenchOLTPClientExecutor.NumTables)] = "40"; + + this.mockFixture.StateManager.OnGetState().ReturnsAsync(JObject.FromObject(new SysbenchOLTPExecutor.SysbenchOLTPState() + { + SysbenchInitialized = false + })); + string[] expectedCommands = { - $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=64 --tables=10 --table-size=100000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=10 cleanup", - $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_common --tables=10 --table-size=100000 --mysql-db=sbtest --mysql-host=1.2.3.5 prepare", - $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=64 --tables=10 --table-size=100000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=10 run" + "sudo ./autogen.sh", + "sudo ./configure", + "sudo make -j", + "sudo make install", + $"sudo mysql -u sbtest -h 1.2.3.5 sbtest --execute=\"USE sbtest; SHOW tables; SELECT FOUND_ROWS();\"", + $"sudo mysql -u sbtest -h 1.2.3.5 sbtest --execute=\"USE sbtest; SELECT COUNT(*) FROM sbtest1;\"", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=8 --tables=40 --table-size=1000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=10 cleanup", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_common --tables=40 --table-size=1000 --mysql-db=sbtest --mysql-host=1.2.3.5 prepare", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=8 --tables=40 --table-size=1000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=10 run" }; int commandNumber = 0; @@ -318,37 +366,45 @@ public async Task SysbenchOLTPClientExecutorSkipsInitializationOfTheBenchmarkFor return process; }; - this.mockFixture.StateManager.OnGetState().ReturnsAsync(JObject.FromObject(new SysbenchOLTPExecutor.SysbenchOLTPState() - { - SysbenchInitialized = true, - NumTables = -1, - RecordCount = -1 - })); - using (TestSysbenchOLTPClientExecutor SysbenchExecutor = new TestSysbenchOLTPClientExecutor(this.mockFixture.Dependencies, this.mockFixture.Parameters)) { - await SysbenchExecutor.ExecuteAsync(CancellationToken.None).ConfigureAwait(false); + await SysbenchExecutor.ExecuteAsync(CancellationToken.None); } } [Test] - public async Task SysbenchOLTPClientExecutorSkipsPrepareAndCleanupSteps() + public async Task SysbenchOLTPClientExecutorRunsTheExpectedWorkloadCommandBalancedScenario() { SetupDefaultBehavior(); - this.mockFixture.Parameters["SkipInitialize"] = true; + SysbenchOLTPState expectedState = new SysbenchOLTPState(new Dictionary + { + [nameof(SysbenchOLTPState.DiskPathsArgument)] = "/testdrive1 /testdrive2" + }); + + this.mockFixture.ApiClient.Setup(client => client.GetStateAsync(nameof(SysbenchOLTPState), It.IsAny(), It.IsAny>())) + .ReturnsAsync(this.mockFixture.CreateHttpResponse(HttpStatusCode.OK, expectedState)); this.mockFixture.StateManager.OnGetState().ReturnsAsync(JObject.FromObject(new SysbenchOLTPExecutor.SysbenchOLTPState() { - SysbenchInitialized = true, - DatabaseScenarioInitialized = true, - NumTables = 10, - RecordCount = 100000 + SysbenchInitialized = false })); + this.mockFixture.Parameters["DatabaseScenario"] = "Balanced"; + string[] expectedCommands = { - $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=64 --tables=10 --table-size=100000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=10 run", + $"sudo chmod -R 2777 \"/home/user/tools/VirtualClient/scripts/sysbencholtp\"", + "sudo ./autogen.sh", + "sudo ./configure", + "sudo make -j", + "sudo make install", + $"sudo mysql -u sbtest -h 1.2.3.5 sbtest --execute=\"USE sbtest; SHOW tables; SELECT FOUND_ROWS();\"", + $"sudo mysql -u sbtest -h 1.2.3.5 sbtest --execute=\"USE sbtest; SELECT COUNT(*) FROM sbtest1;\"", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=1 --tables=10 --table-size=1000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=10 cleanup", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_common --tables=10 --table-size=1000 --mysql-db=sbtest --mysql-host=1.2.3.5 prepare", + $"sudo {this.scriptPath}/balanced-client.sh 1.2.3.5 10 sbtest /testdrive1 /testdrive2", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=1 --tables=10 --table-size=1000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=10 run" }; int commandNumber = 0; @@ -385,29 +441,82 @@ public async Task SysbenchOLTPClientExecutorSkipsPrepareAndCleanupSteps() using (TestSysbenchOLTPClientExecutor SysbenchExecutor = new TestSysbenchOLTPClientExecutor(this.mockFixture.Dependencies, this.mockFixture.Parameters)) { - await SysbenchExecutor.ExecuteAsync(CancellationToken.None).ConfigureAwait(false); + await SysbenchExecutor.ExecuteAsync(CancellationToken.None); } } [Test] - public async Task SysbenchOLTPClientExecutorPreparesWhenSkipInitializeIsFalse() + public async Task SysbenchOLTPClientExecutorSkipsInitializationOfTheBenchmarkForExecutionAfterTheFirstRun() { SetupDefaultBehavior(); - this.mockFixture.Parameters["SkipInitialize"] = false; + string[] expectedCommands = + { + $"sudo mysql -u sbtest -h 1.2.3.5 sbtest --execute=\"USE sbtest; SHOW tables; SELECT FOUND_ROWS();\"", + $"sudo mysql -u sbtest -h 1.2.3.5 sbtest --execute=\"USE sbtest; SELECT COUNT(*) FROM sbtest1;\"", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=64 --tables=10 --table-size=100000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=10 cleanup", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_common --tables=10 --table-size=100000 --mysql-db=sbtest --mysql-host=1.2.3.5 prepare", + $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=64 --tables=10 --table-size=100000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=10 run" + }; + + int commandNumber = 0; + bool commandExecuted = false; + this.mockFixture.ProcessManager.OnCreateProcess = (exe, arguments, workingDir) => + { + + string expectedCommand = expectedCommands[commandNumber]; + if (expectedCommand == $"{exe} {arguments}") + { + commandExecuted = true; + } + Assert.IsTrue(commandExecuted); + commandExecuted = false; + commandNumber += 1; + + InMemoryProcess process = new InMemoryProcess + { + StartInfo = new ProcessStartInfo + { + FileName = exe, + Arguments = arguments + }, + ExitCode = 0, + OnStart = () => true, + OnHasExited = () => true + }; + + string resultsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Examples", "SysbenchOLTP", "SysbenchOLTPExample.txt"); + process.StandardOutput.Append(File.ReadAllText(resultsPath)); + + return process; + }; + + this.mockFixture.StateManager.OnGetState().ReturnsAsync(JObject.FromObject(new SysbenchOLTPExecutor.SysbenchOLTPState() + { + SysbenchInitialized = true + })); + + using (TestSysbenchOLTPClientExecutor SysbenchExecutor = new TestSysbenchOLTPClientExecutor(this.mockFixture.Dependencies, this.mockFixture.Parameters)) + { + await SysbenchExecutor.ExecuteAsync(CancellationToken.None).ConfigureAwait(false); + } + } + + [Test] + public async Task SysbenchOLTPClientExecutorSkipsPrepareAndCleanupSteps() + { + SetupDefaultBehavior(); this.mockFixture.StateManager.OnGetState().ReturnsAsync(JObject.FromObject(new SysbenchOLTPExecutor.SysbenchOLTPState() { SysbenchInitialized = true, - DatabaseScenarioInitialized = true, - NumTables = 10, - RecordCount = 100000 + DatabaseScenarioInitialized = true })); string[] expectedCommands = { - $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=64 --tables=10 --table-size=100000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=10 cleanup", - $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_common --tables=10 --table-size=100000 --mysql-db=sbtest --mysql-host=1.2.3.5 prepare", + $"sudo mysql -u sbtest -h 1.2.3.5 sbtest --execute=\"USE sbtest; SHOW tables; SELECT FOUND_ROWS();\"", + $"sudo mysql -u sbtest -h 1.2.3.5 sbtest --execute=\"USE sbtest; SELECT COUNT(*) FROM sbtest1;\"", $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=64 --tables=10 --table-size=100000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=10 run", }; @@ -417,6 +526,7 @@ public async Task SysbenchOLTPClientExecutorPreparesWhenSkipInitializeIsFalse() { string expectedCommand = expectedCommands[commandNumber]; + if (expectedCommand == $"{exe} {arguments}") { commandExecuted = true; @@ -437,8 +547,33 @@ public async Task SysbenchOLTPClientExecutorPreparesWhenSkipInitializeIsFalse() OnHasExited = () => true }; - string resultsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Examples", "SysbenchOLTP", "SysbenchOLTPExample.txt"); - process.StandardOutput.Append(File.ReadAllText(resultsPath)); + if (arguments.Contains("run")) + { + string resultsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Examples", "SysbenchOLTP", "SysbenchOLTPExample.txt"); + process.StandardOutput.Append(File.ReadAllText(resultsPath)); + } + + if (arguments.Contains("FOUND_ROWS()")) + { + string numRows = + "+--------------+" + + "| FOUND_ROWS() |" + + "+--------------+" + + "| 10 |" + + "+--------------+"; + process.StandardOutput.Append(numRows); + } + + if (arguments.Contains("COUNT(*)")) + { + string tableCount = + "+----------+" + + "| COUNT(*) |" + + "+----------+" + + "| 100000 |" + + "+----------+"; + process.StandardOutput.Append(tableCount); + } return process; }; @@ -454,18 +589,16 @@ public async Task SysbenchOLTPClientExecutorPreparesWhenDatabaseStateUninitializ { SetupDefaultBehavior(); - this.mockFixture.Parameters["SkipInitialize"] = true; - this.mockFixture.StateManager.OnGetState().ReturnsAsync(JObject.FromObject(new SysbenchOLTPExecutor.SysbenchOLTPState() { SysbenchInitialized = true, - DatabaseScenarioInitialized = true, - NumTables = -1, - RecordCount = -1 + DatabaseScenarioInitialized = true })); string[] expectedCommands = { + $"sudo mysql -u sbtest -h 1.2.3.5 sbtest --execute=\"USE sbtest; SHOW tables; SELECT FOUND_ROWS();\"", + $"sudo mysql -u sbtest -h 1.2.3.5 sbtest --execute=\"USE sbtest; SELECT COUNT(*) FROM sbtest1;\"", $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=64 --tables=10 --table-size=100000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=10 cleanup", $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_common --tables=10 --table-size=100000 --mysql-db=sbtest --mysql-host=1.2.3.5 prepare", $"sudo /home/user/tools/VirtualClient/packages/sysbench/src/sysbench oltp_read_write --threads=64 --tables=10 --table-size=100000 --mysql-db=sbtest --mysql-host=1.2.3.5 --time=10 run", diff --git a/src/VirtualClient/VirtualClient.Actions.UnitTests/SysbenchOLTP/SysbenchOLTPServerExecutorTests.cs b/src/VirtualClient/VirtualClient.Actions.UnitTests/SysbenchOLTP/SysbenchOLTPServerExecutorTests.cs index 88f844486e..4c3b9d96bd 100644 --- a/src/VirtualClient/VirtualClient.Actions.UnitTests/SysbenchOLTP/SysbenchOLTPServerExecutorTests.cs +++ b/src/VirtualClient/VirtualClient.Actions.UnitTests/SysbenchOLTP/SysbenchOLTPServerExecutorTests.cs @@ -22,6 +22,7 @@ namespace VirtualClient.Actions using VirtualClient.Common.Contracts; using VirtualClient.Common.Telemetry; using VirtualClient.Contracts; + using static VirtualClient.Actions.SysbenchOLTPExecutor; [TestFixture] [Category("Unit")] @@ -60,7 +61,11 @@ public async Task SysbenchOLTPServerExecutorExcutesExpectedProcessInMemoryScenar using TestSysbenchOLTPServerExecutor executor = new TestSysbenchOLTPServerExecutor(this.mockFixture.Dependencies, this.mockFixture.Parameters); string scriptPath = this.mockFixture.PlatformSpecifics.GetScriptPath("sysbencholtp"); - + + this.mockFixture.ApiClient.Setup(client => client.UpdateStateAsync(nameof(SysbenchOLTPState), It.IsAny>(), + It.IsAny(), It.IsAny>())) + .ReturnsAsync(this.mockFixture.CreateHttpResponse(HttpStatusCode.OK)); + // Mocking 8GB of memory this.mockFixture.SystemManagement.Setup(mgr => mgr.GetMemoryInfoAsync(It.IsAny())) .ReturnsAsync(new MemoryInfo(1024 * 1024 * 8)); @@ -122,6 +127,10 @@ public async Task SysbenchOLTPServerExecutorExcutesExpectedProcessBalancedScenar $"{Path.Combine(MockFixture.TestAssemblyDirectory, "vcmnt_dev_sde1")} " + $"{Path.Combine(MockFixture.TestAssemblyDirectory, "vcmnt_dev_sdf1")}"; + this.mockFixture.ApiClient.Setup(client => client.UpdateStateAsync(nameof(SysbenchOLTPState), It.IsAny>(), + It.IsAny(), It.IsAny>())) + .ReturnsAsync(this.mockFixture.CreateHttpResponse(HttpStatusCode.OK)); + string[] expectedCommands = { $"sudo chmod -R 2777 \"/home/user/tools/VirtualClient/scripts/sysbencholtp\"", diff --git a/src/VirtualClient/VirtualClient.Actions/SysbenchOLTP/SysbenchOLTPClientExecutor.cs b/src/VirtualClient/VirtualClient.Actions/SysbenchOLTP/SysbenchOLTPClientExecutor.cs index 6375256319..233e75932a 100644 --- a/src/VirtualClient/VirtualClient.Actions/SysbenchOLTP/SysbenchOLTPClientExecutor.cs +++ b/src/VirtualClient/VirtualClient.Actions/SysbenchOLTP/SysbenchOLTPClientExecutor.cs @@ -8,16 +8,14 @@ namespace VirtualClient.Actions using System.Globalization; using System.Linq; using System.Net.Http; - using System.Runtime.InteropServices; + using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; - using Newtonsoft.Json.Linq; using Polly; using VirtualClient.Common; using VirtualClient.Common.Contracts; using VirtualClient.Common.Extensions; - using VirtualClient.Common.Rest; using VirtualClient.Common.Telemetry; using VirtualClient.Contracts; using VirtualClient.Contracts.Metadata; @@ -141,17 +139,6 @@ public int RecordCount } } - /// - /// Skips initialization of the tables and records in the database - /// - public bool SkipInitialize - { - get - { - return this.Parameters.GetValue(nameof(SysbenchOLTPClientExecutor.SkipInitialize), true); - } - } - /// /// Number of threads. /// @@ -250,7 +237,6 @@ await this.ExecuteWorkloadAsync(telemetryContext, cancellationToken) protected override async Task InitializeAsync(EventContext telemetryContext, CancellationToken cancellationToken) { await base.InitializeAsync(telemetryContext, cancellationToken).ConfigureAwait(false); - this.InitializeApiClients(); // get sysbench workload path @@ -363,9 +349,47 @@ await this.ExecuteCommandAsync(makeInstallCommand, n private async Task PrepareMySQLDatabase(EventContext telemetryContext, CancellationToken cancellationToken) { - SysbenchOLTPState state = await this.stateManager.GetStateAsync(nameof(SysbenchOLTPState), cancellationToken); + int numTables = -1; + int recordCount = -1; + + // use mysql-client tool to get table/record counts from the mysql server + // table count output is like so: + // +--------------+ + // | FOUND_ROWS() | + // +--------------+ + // | 0 | + // +--------------+ + // + // record count output is like so: + // +----------+ + // | COUNT(*) | + // +----------+ + // | 0 | + // +----------+ + + string getMySQLTableCountCommand = $"mysql -u {this.DatabaseName} -h {this.ServerIpAddress} {this.DatabaseName} --execute=\"USE {this.DatabaseName}; SHOW tables; SELECT FOUND_ROWS();\""; + + // note that sysbench standardizes table names; database name is up to the user, but each table name will always be "sbtest1, sbtest2, ..." + // if at least one table exists, we can take a look at its record count to reliably obtain the record counts for all tables + string getMySQLRecordCountCommand = $"mysql -u {this.DatabaseName} -h {this.ServerIpAddress} {this.DatabaseName} --execute=\"USE {this.DatabaseName}; SELECT COUNT(*) FROM sbtest1;\""; + + string result = await this.ExecuteCommandAsync(getMySQLTableCountCommand, null, Environment.CurrentDirectory, cancellationToken) + .ConfigureAwait(false); + + Match match = Regex.Match(result, "[1-9][0-9]*"); - if (!this.SkipInitialize || this.NumTables > state.NumTables || this.RecordCount > state.RecordCount) + if (match.Success) + { + numTables = Convert.ToInt32(match.Value); + + result = await this.ExecuteCommandAsync(getMySQLRecordCountCommand, null, Environment.CurrentDirectory, cancellationToken) + .ConfigureAwait(false); + + match = Regex.Match(result, "[1-9][0-9]*|0"); + recordCount = match.Success ? Convert.ToInt32(match.Value) : -1; + } + + if (this.NumTables > numTables || this.RecordCount > recordCount) { // only cleanup & prepare it if needed -- ie. if the state table/record counts are different than current @@ -374,13 +398,6 @@ await this.ExecuteCommandAsync(this.sysbenchPath, th await this.ExecuteCommandAsync(this.sysbenchPath, this.sysbenchPrepareArguments, this.sysbenchDirectory, cancellationToken) .ConfigureAwait(false); - - state.Properties[nameof(SysbenchOLTPState.NumTables)] = this.NumTables; - state.Properties[nameof(SysbenchOLTPState.RecordCount)] = this.RecordCount; - - // save the updated state configuration - - await this.stateManager.SaveStateAsync(nameof(SysbenchOLTPState), state, cancellationToken); } if (this.DatabaseScenario == SysbenchOLTPScenario.Balanced) @@ -395,7 +412,7 @@ await this.ExecuteCommandAsync(this.sysbenchPath, th SysbenchOLTPState serverState = responseContent.FromJson(); - string diskPaths = serverState.Properties[nameof(SysbenchOLTPState.DiskPathsArgument)].ToString(); + string diskPaths = serverState.DiskPathsArgument; await this.PrepareBalancedScenarioAsync(diskPaths, telemetryContext, cancellationToken); } diff --git a/src/VirtualClient/VirtualClient.Actions/SysbenchOLTP/SysbenchOLTPExecutor.cs b/src/VirtualClient/VirtualClient.Actions/SysbenchOLTP/SysbenchOLTPExecutor.cs index ecf92e18a8..70609a8c11 100644 --- a/src/VirtualClient/VirtualClient.Actions/SysbenchOLTP/SysbenchOLTPExecutor.cs +++ b/src/VirtualClient/VirtualClient.Actions/SysbenchOLTP/SysbenchOLTPExecutor.cs @@ -95,6 +95,7 @@ await this.CheckDistroSupportAsync(telemetryContext, cancellationToken) .ConfigureAwait(false); await this.InitializeExecutablesAsync(cancellationToken); + this.InitializeApiClients(telemetryContext, cancellationToken); if (this.IsMultiRoleLayout()) { @@ -109,29 +110,31 @@ await this.CheckDistroSupportAsync(telemetryContext, cancellationToken) /// /// Initializes API client. /// - protected void InitializeApiClients() + protected void InitializeApiClients(EventContext telemetryContext, CancellationToken cancellationToken) { - IApiClientManager clientManager = this.Dependencies.GetService(); - bool isSingleVM = !this.IsMultiRoleLayout(); - - if (isSingleVM) - { - this.ServerIpAddress = IPAddress.Loopback.ToString(); - this.ServerApiClient = clientManager.GetOrCreateApiClient(this.ServerIpAddress, IPAddress.Loopback); - } - else + if (!cancellationToken.IsCancellationRequested) { - ClientInstance serverInstance = this.GetLayoutClientInstances(ClientRole.Server).First(); - IPAddress.TryParse(serverInstance.IPAddress, out IPAddress serverIPAddress); + IApiClientManager clientManager = this.Dependencies.GetService(); + + if (!this.IsMultiRoleLayout()) + { + this.ServerIpAddress = IPAddress.Loopback.ToString(); + this.ServerApiClient = clientManager.GetOrCreateApiClient(this.ServerIpAddress, IPAddress.Loopback); + } + else + { + ClientInstance serverInstance = this.GetLayoutClientInstances(ClientRole.Server).First(); + IPAddress.TryParse(serverInstance.IPAddress, out IPAddress serverIPAddress); - this.ServerIpAddress = serverIPAddress.ToString(); - this.ServerApiClient = clientManager.GetOrCreateApiClient(serverIPAddress.ToString(), serverIPAddress); - this.RegisterToSendExitNotifications($"{this.TypeName}.ExitNotification", this.ServerApiClient); + this.ServerIpAddress = serverIPAddress.ToString(); + this.ServerApiClient = clientManager.GetOrCreateApiClient(this.ServerIpAddress, serverIPAddress); + this.RegisterToSendExitNotifications($"{this.TypeName}.ExitNotification", this.ServerApiClient); - ClientInstance clientInstance = this.GetLayoutClientInstances(ClientRole.Client).First(); - IPAddress.TryParse(clientInstance.IPAddress, out IPAddress clientIPAddress); + ClientInstance clientInstance = this.GetLayoutClientInstances(ClientRole.Client).First(); + IPAddress.TryParse(clientInstance.IPAddress, out IPAddress clientIPAddress); - this.ClientIpAddress = clientIPAddress.ToString(); + this.ClientIpAddress = clientIPAddress.ToString(); + } } } @@ -308,32 +311,6 @@ public string DiskPathsArgument this.Properties[nameof(SysbenchOLTPState.DiskPathsArgument)] = value; } } - - public int NumTables - { - get - { - return this.Properties.GetValue(nameof(SysbenchOLTPState.NumTables), -1); - } - - set - { - this.Properties[nameof(SysbenchOLTPState.NumTables)] = value; - } - } - - public int RecordCount - { - get - { - return this.Properties.GetValue(nameof(SysbenchOLTPState.RecordCount), -1); - } - - set - { - this.Properties[nameof(SysbenchOLTPState.RecordCount)] = value; - } - } } /// diff --git a/src/VirtualClient/VirtualClient.Actions/SysbenchOLTP/SysbenchOLTPMetricsParser.cs b/src/VirtualClient/VirtualClient.Actions/SysbenchOLTP/SysbenchOLTPMetricsParser.cs index 255877db19..38f73efb64 100644 --- a/src/VirtualClient/VirtualClient.Actions/SysbenchOLTP/SysbenchOLTPMetricsParser.cs +++ b/src/VirtualClient/VirtualClient.Actions/SysbenchOLTP/SysbenchOLTPMetricsParser.cs @@ -59,11 +59,8 @@ public override IList Parse() if (!string.IsNullOrEmpty(this.PreprocessedText)) { - // Split Standard Output to only consider SQL statistics - string stats = Regex.Split(this.PreprocessedText, "SQL statistics:")[1]; - // Get all ints and decimals - MatchCollection mc = Regex.Matches(stats, "-?\\d+(\\.\\d+)?"); + MatchCollection mc = Regex.Matches(this.PreprocessedText, "-?\\d+(\\.\\d+)?"); // list of indices to skip in MatchCollection MC (Total Queries, Events/s, Total Number of Events, Thread Fairness averages and stddevs, and 95) List dropIndices = new List() @@ -101,7 +98,10 @@ public override IList Parse() /// protected override void Preprocess() { - this.PreprocessedText = this.RawText; + const string MetricsStart = "SQL statistics:"; + // Split Standard Output to only consider SQL statistics + Match match = Regex.Match(this.RawText, MetricsStart); + this.PreprocessedText = match.Success ? Regex.Split(this.RawText, MetricsStart)[1] : string.Empty; } // helper class that contains Metric Name, Unit, and Relativity diff --git a/src/VirtualClient/VirtualClient.Actions/SysbenchOLTP/SysbenchOLTPServerExecutor.cs b/src/VirtualClient/VirtualClient.Actions/SysbenchOLTP/SysbenchOLTPServerExecutor.cs index fdcd335b77..4dbb08de04 100644 --- a/src/VirtualClient/VirtualClient.Actions/SysbenchOLTP/SysbenchOLTPServerExecutor.cs +++ b/src/VirtualClient/VirtualClient.Actions/SysbenchOLTP/SysbenchOLTPServerExecutor.cs @@ -6,13 +6,12 @@ namespace VirtualClient.Actions using System; using System.Collections.Generic; using System.Linq; - using System.Net; using System.Net.Http; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; - using Newtonsoft.Json.Linq; using VirtualClient.Common; + using VirtualClient.Common.Contracts; using VirtualClient.Common.Extensions; using VirtualClient.Common.Telemetry; using VirtualClient.Contracts; @@ -44,12 +43,6 @@ public string DiskFilter } } - /// - /// Client used to communicate with the locally self-hosted instance of the - /// Virtual Client API. - /// - public IApiClient LocalApiClient { get; private set; } - /// /// Provides access to the local state management facilities. /// @@ -64,14 +57,14 @@ public string DiskFilter protected override async Task InitializeAsync(EventContext telemetryContext, CancellationToken cancellationToken) { await base.InitializeAsync(telemetryContext, cancellationToken).ConfigureAwait(false); - this.InitializeApiClients(); - IApiClientManager clientManager = this.Dependencies.GetService(); - this.LocalApiClient = clientManager.GetOrCreateApiClient(IPAddress.Loopback.ToString(), IPAddress.Loopback); + await this.WaitAsync(TimeSpan.FromSeconds(3), cancellationToken); SysbenchOLTPState state = await this.StateManager.GetStateAsync(nameof(SysbenchOLTPState), cancellationToken) ?? new SysbenchOLTPState(); + // prepare the server for a specific scenario + if (!state.DatabaseScenarioInitialized) { // only prepare if the scenario has not been initialized @@ -95,13 +88,15 @@ await this.PrepareInMemoryScenarioAsync(telemetryContext, cancellationToken) break; } - HttpResponseMessage response = await this.LocalApiClient.GetOrCreateStateAsync(nameof(SysbenchOLTPState), JObject.FromObject(state), cancellationToken) + Item stateUpdate = new Item(nameof(SysbenchOLTPState), state); + + HttpResponseMessage response = await this.ServerApiClient.UpdateStateAsync(nameof(SysbenchOLTPState), stateUpdate, cancellationToken) .ConfigureAwait(false); response.ThrowOnError(); await this.StateManager.SaveStateAsync(nameof(SysbenchOLTPState), state, cancellationToken) - .ConfigureAwait(false); + .ConfigureAwait(false); } } diff --git a/src/VirtualClient/VirtualClient.Main/profiles/PERF-MYSQL-SYSBENCH-OLTP.json b/src/VirtualClient/VirtualClient.Main/profiles/PERF-MYSQL-SYSBENCH-OLTP.json index 21c79418dd..1b052393a1 100644 --- a/src/VirtualClient/VirtualClient.Main/profiles/PERF-MYSQL-SYSBENCH-OLTP.json +++ b/src/VirtualClient/VirtualClient.Main/profiles/PERF-MYSQL-SYSBENCH-OLTP.json @@ -9,8 +9,6 @@ "Parameters": { "DatabaseName": "sbtest", "DatabaseScenario": "Default", - "SkipDatabaseInitialize": true, - "SkipServerInitialize": false }, "Actions": [ { @@ -31,8 +29,7 @@ "Duration": "00:20:00", "RecordCount": 10000, "Workload": "oltp_read_write", - "PackageName": "sysbench", - "SkipInitialize": "$.Parameters.SkipDatabaseInitialize" + "PackageName": "sysbench" } }, { @@ -45,8 +42,7 @@ "Duration": "00:20:00", "RecordCount": 10000, "Workload": "oltp_read_only", - "PackageName": "sysbench", - "SkipInitialize": "$.Parameters.SkipDatabaseInitialize" + "PackageName": "sysbench" } }, { @@ -59,8 +55,7 @@ "Duration": "00:20:00", "RecordCount": 10000, "Workload": "oltp_write_only", - "PackageName": "sysbench", - "SkipInitialize": "$.Parameters.SkipDatabaseInitialize" + "PackageName": "sysbench" } }, { @@ -73,8 +68,7 @@ "Duration": "00:20:00", "RecordCount": 10000, "Workload": "oltp_delete", - "PackageName": "sysbench", - "SkipInitialize": "$.Parameters.SkipDatabaseInitialize" + "PackageName": "sysbench" } }, { @@ -87,8 +81,7 @@ "Duration": "00:20:00", "RecordCount": 10000, "Workload": "oltp_insert", - "PackageName": "sysbench", - "SkipInitialize": "$.Parameters.SkipDatabaseInitialize" + "PackageName": "sysbench" } }, { @@ -101,8 +94,7 @@ "Duration": "00:20:00", "RecordCount": 10000, "Workload": "oltp_update_index", - "PackageName": "sysbench", - "SkipInitialize": "$.Parameters.SkipDatabaseInitialize" + "PackageName": "sysbench" } }, { @@ -115,8 +107,7 @@ "Duration": "00:20:00", "RecordCount": 10000, "Workload": "oltp_update_non_index", - "PackageName": "sysbench", - "SkipInitialize": "$.Parameters.SkipDatabaseInitialize" + "PackageName": "sysbench" } }, { @@ -129,8 +120,7 @@ "Duration": "00:20:00", "RecordCount": 10000, "Workload": "select_random_points", - "PackageName": "sysbench", - "SkipInitialize": "$.Parameters.SkipDatabaseInitialize" + "PackageName": "sysbench" } }, { @@ -143,8 +133,7 @@ "Duration": "00:20:00", "RecordCount": 10000, "Workload": "select_random_ranges", - "PackageName": "sysbench", - "SkipInitialize": "$.Parameters.SkipDatabaseInitialize" + "PackageName": "sysbench" } } ], @@ -182,7 +171,6 @@ "Scenario": "ConfigureMySQLServer", "Action": "StartServer", "DatabaseName": "$.Parameters.DatabaseName", - "SkipInitialize": "$.Parameters.SkipServerInitialize", "Role": "Server" } }, @@ -192,7 +180,6 @@ "Scenario": "CreateMySQLDatabase", "Action": "CreateDatabase", "DatabaseName": "$.Parameters.DatabaseName", - "SkipInitialize": "$.Parameters.SkipServerInitialize", "Role": "Server" } }, @@ -202,7 +189,6 @@ "Scenario": "ConfigureMySQLDatabase", "Action": "RaisedStatementCount", "DatabaseName": "$.Parameters.DatabaseName", - "SkipInitialize": "$.Parameters.SkipServerInitialize", "Role": "Server" } }, @@ -212,7 +198,6 @@ "Scenario": "ConfigureMySQLServer", "Action": "ConfigureNetwork", "DatabaseName": "$.Parameters.DatabaseName", - "SkipInitialize": "$.Parameters.SkipServerInitialize", "Role": "Server" } }, @@ -222,7 +207,6 @@ "Scenario": "ConfigureMySQLDatabase", "Action": "CreateUser", "DatabaseName": "$.Parameters.DatabaseName", - "SkipInitialize": "$.Parameters.SkipServerInitialize", "Role": "Server" } }, diff --git a/website/docs/workloads/sysbench-oltp/sysbench-oltp-profiles.md b/website/docs/workloads/sysbench-oltp/sysbench-oltp-profiles.md index 08de018447..3475b9ef1a 100644 --- a/website/docs/workloads/sysbench-oltp/sysbench-oltp-profiles.md +++ b/website/docs/workloads/sysbench-oltp/sysbench-oltp-profiles.md @@ -80,7 +80,7 @@ It is highly recommended to use the default thread and record count values when "Threads": "8", "NumTables": "16", "RecordCount": "500", - "DurationSecs": "1800", + "DurationSecs": "00:20:00", "Workload": "oltp_read_write", "PackageName": "sysbench" } @@ -118,7 +118,6 @@ Runs a system-intensive workload using the Sysbench Benchmark to test the bandwi | NumTables | Not Required. Number of tables created in the database. | 10 | | Duration | Required. Timespan duration of the workload. | N/A | | Workload | Required. Name of benchmark to run; options listed [here](./sysbench-oltp.md) | N/A | - | SkipInitialize | Not Required. If true, skips the initialization of the tables and records in the database. | True | * **Profile Runtimes** See the 'Metadata' section of the profile for estimated runtimes. These timings represent the length of time required to run a single round of profile