Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Onboarding workload Apachebench for Apache Httpserver #251

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/VirtualClient/TestResources/Results_ApacheBench.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
This is ApacheBench, Version 2.3 <$Revision: 1903618 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://localhost:80/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.holisticseo.digital (be patient).....done


Server Software: cloudflare
Server Hostname: www.holisticseo.digital
Server Port: 80

Document Path: /
Document Length: 0 bytes

Concurrency Level: 100
Time taken for tests: 0.578 seconds
Complete requests: 100
Failed requests: 0
Non-2xx responses: 100
Keep-Alive requests: 0
Total transferred: 65006 bytes
HTML transferred: 0 bytes
Requests per second: 172.97 [#/sec] (mean)
Time per request: 578.124 [ms] (mean)
Time per request: 5.781 [ms] (mean, across all concurrent requests)
Transfer rate: 109.81 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 5 7.5 0 16
Processing: 16 268 155.8 266 547
Waiting: 0 263 155.6 266 531
Total: 16 274 156.0 281 562

Percentage of the requests served within a certain time (ms)
50% 281
66% 359
75% 406
80% 437
90% 484
95% 516
98% 531
99% 562
100% 562 (longest request)
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace VirtualClient.Actions
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
using VirtualClient.Common;
using VirtualClient.Contracts;

[TestFixture]
[Category("Functional")]
public class ApacheBenchProfileTests
{
private DependencyFixture mockFixture;

[OneTimeSetUp]
public void SetupFixture()
{
this.mockFixture = new DependencyFixture();
ComponentTypeCache.Instance.LoadComponentTypes(TestDependencies.TestDirectory);
}

[Test]
[TestCase("PERF-APACHEBENCH.json")]
public void ApacheBenchWorkloadProfileParametersAreInlinedCorrectly(string profile)
{
this.mockFixture.Setup(PlatformID.Unix);

using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies))
{
WorkloadAssert.ParameterReferencesInlined(executor.Profile);
}
}

[Test]
[TestCase("PERF-APACHEBENCH.json")]
public async Task ApacheBenchWorkloadProfileInstallsTheExpectedDependenciesOnLinuxPlatform(string profile)
{
this.mockFixture.Setup(PlatformID.Unix);

using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies, dependenciesOnly: true))
{
await executor.ExecuteAsync(ProfileTiming.OneIteration(), CancellationToken.None).ConfigureAwait(false);
WorkloadAssert.AptPackageInstalled(this.mockFixture, "unzip");
WorkloadAssert.AptPackageInstalled(this.mockFixture, "apache2");
}
}

[Test]
[TestCase("PERF-APACHEBENCH.json")]
public async Task ApacheBenchWorkloadProfileInstallsTheExpectedDependenciesOnWindowsPlatform(string profile)
{
this.mockFixture.Setup(PlatformID.Win32NT);

using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies, dependenciesOnly: true))
{
await executor.ExecuteAsync(ProfileTiming.OneIteration(), CancellationToken.None).ConfigureAwait(false);
WorkloadAssert.WorkloadPackageInstalled(this.mockFixture, "apachehttpserver");
}
}

[Test]
[TestCase("PERF-APACHEBENCH.json", PlatformID.Unix, Architecture.X64)]
[TestCase("PERF-APACHEBENCH.json", PlatformID.Unix, Architecture.Arm64)]
public async Task ApacheBenchWorkloadProfileExecutesTheExpectedWorkloadsOnUnixPlatform(string profile, PlatformID platform, Architecture architecture)
{
IEnumerable<string> expectedCommands = new List<string>
{
"ufw allow 'Apache'",
"systemctl start apache2"
};

// Setup the expectations for the workload
// - Workload package is installed and exists.
// - The workload generates valid results.
this.mockFixture.Setup(platform, architecture);
this.mockFixture.SetupWorkloadPackage("apachehttpserver");

this.mockFixture.ProcessManager.OnCreateProcess = (command, arguments, workingDir) =>
{
IProcessProxy process = this.mockFixture.CreateProcess(command, arguments, workingDir);

if (arguments.Contains("/usr/bin/ab -k -n", StringComparison.OrdinalIgnoreCase))
{
process.StandardOutput.Append(TestDependencies.GetResourceFileContents("Results_ApacheBench.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());
}
}

[Test]
[TestCase("PERF-APACHEBENCH.json", PlatformID.Win32NT, Architecture.X64)]
[TestCase("PERF-APACHEBENCH.json", PlatformID.Win32NT, Architecture.Arm64)]
public async Task ApacheBenchWorkloadProfileExecutesTheExpectedWorkloadsOnWindowsPlatform(string profile, PlatformID platform, Architecture architecture)
{
IEnumerable<string> expectedCommands = new List<string>
{
"-k install"
};

// Setup the expectations for the workload
// - Workload package is installed and exists.
// - The workload generates valid results.
this.mockFixture.Setup(platform, architecture);
this.mockFixture.SetupWorkloadPackage("apachehttpserver");

this.mockFixture
.SetupFile(this.mockFixture.PlatformSpecifics.Combine(
this.mockFixture.PlatformSpecifics.PackagesDirectory,
"apachehttpserver",
$"win-{architecture.ToString().ToLower()}",
"Apache24",
"conf",
"httpd.conf"));

this.mockFixture.ProcessManager.OnCreateProcess = (command, arguments, workingDir) =>
{
IProcessProxy process = this.mockFixture.CreateProcess(command, arguments, workingDir);

if (command.Contains("ab.exe") && arguments.Contains("-k -n", StringComparison.OrdinalIgnoreCase))
{
process.StandardOutput.Append(TestDependencies.GetResourceFileContents("Results_ApacheBench.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());
}
}

[Test]
[TestCase("PERF-APACHEBENCH.json", PlatformID.Win32NT)]
public void ApacheBenchWorkloadProfileActionsWillNotBeExecutedIfTheWorkloadPackageDoesNotExist(string profile, PlatformID platform)
{
this.mockFixture.Setup(platform);

this.mockFixture.ProcessManager.OnCreateProcess = (command, arguments, workingDir) =>
{
IProcessProxy process = this.mockFixture.CreateProcess(command, arguments, workingDir);
process.StandardOutput.Append(TestDependencies.GetResourceFileContents("Results_ApacheBench.txt"));

return process;
};

// We ensure the workload package does not exist.
this.mockFixture.PackageManager.Clear();

using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies))
{
executor.ExecuteDependencies = false;
DependencyException error = Assert.ThrowsAsync<DependencyException>(() => executor.ExecuteAsync(ProfileTiming.OneIteration(), CancellationToken.None));

Assert.AreEqual(ErrorReason.WorkloadDependencyMissing, error.Reason);
Assert.IsFalse(this.mockFixture.ProcessManager.Commands.Contains("apachehttpserver"));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<Content Include="..\TestResources\Results_Coremark.txt" Link="Resources\Results_Coremark.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\TestResources\Results_ApacheBench.txt" Link="Resources\Results_ApacheBench.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\TestResources\Results_CoremarkPro.txt" Link="Resources\Results_CoremarkPro.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down Expand Up @@ -127,6 +130,9 @@
<Content Include="..\VirtualClient.Main\profiles\MONITORS-NONE.json" Link="Profiles\MONITORS-NONE.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\VirtualClient.Main\profiles\PERF-APACHEBENCH.json" Link="Profiles\PERF-APACHEBENCH.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\VirtualClient.Main\profiles\PERF-ASPNETBENCH.json" Link="Profiles\PERF-ASPNETBENCH.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down
Loading
Loading