Clean up stress test (#2422)
This commit is contained in:
parent
dc24fe1485
commit
9ed51e1060
|
|
@ -218,9 +218,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "getting-started", "docs\met
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "extending-the-sdk", "docs\metrics\extending-the-sdk\extending-the-sdk.csproj", "{1F9D7748-D099-4E25-97F5-9C969D6FF969}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StressTestMetrics", "test\StressTestMetrics\StressTestMetrics.csproj", "{A885DBE2-4B82-432C-A77B-19844D7BBC96}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Tests.Stress.Metrics", "test\OpenTelemetry.Tests.Stress.Metrics\OpenTelemetry.Tests.Stress.Metrics.csproj", "{A885DBE2-4B82-432C-A77B-19844D7BBC96}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "customizing-the-sdk", "docs\metrics\customizing-the-sdk\customizing-the-sdk.csproj", "{81234AFA-B4E7-4D0D-AB97-FD559C78EDA2}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "customizing-the-sdk", "docs\metrics\customizing-the-sdk\customizing-the-sdk.csproj", "{81234AFA-B4E7-4D0D-AB97-FD559C78EDA2}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Tests.Stress", "test\OpenTelemetry.Tests.Stress\OpenTelemetry.Tests.Stress.csproj", "{2770158A-D220-414B-ABC6-179371323579}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
|
@ -448,6 +450,10 @@ Global
|
|||
{81234AFA-B4E7-4D0D-AB97-FD559C78EDA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{81234AFA-B4E7-4D0D-AB97-FD559C78EDA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{81234AFA-B4E7-4D0D-AB97-FD559C78EDA2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2770158A-D220-414B-ABC6-179371323579}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2770158A-D220-414B-ABC6-179371323579}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2770158A-D220-414B-ABC6-179371323579}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2770158A-D220-414B-ABC6-179371323579}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
@ -484,6 +490,7 @@ Global
|
|||
{1F9D7748-D099-4E25-97F5-9C969D6FF969} = {3277B1C0-BDFE-4460-9B0D-D9A661FB48DB}
|
||||
{A885DBE2-4B82-432C-A77B-19844D7BBC96} = {0169B149-FB8B-46F4-9EF7-8A0E69F8FAAF}
|
||||
{81234AFA-B4E7-4D0D-AB97-FD559C78EDA2} = {3277B1C0-BDFE-4460-9B0D-D9A661FB48DB}
|
||||
{2770158A-D220-414B-ABC6-179371323579} = {0169B149-FB8B-46F4-9EF7-8A0E69F8FAAF}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {55639B5C-0770-4A22-AB56-859604650521}
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@
|
|||
<CodeAnalysisRuleSet>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'OpenTelemetry.sln'))\build\OpenTelemetry.test.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="$(MSBuildProjectName.Contains('.Tests'))">
|
||||
<PropertyGroup Condition="$(MSBuildProjectName.EndsWith('.Tests'))">
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="$(MSBuildProjectName.Contains('.Tests'))">
|
||||
<ItemGroup Condition="$(MSBuildProjectName.EndsWith('.Tests'))">
|
||||
<Content Include="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'OpenTelemetry.sln'))\build\xunit.runner.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
|
|
|||
|
|
@ -29,9 +29,7 @@
|
|||
{
|
||||
"files": [
|
||||
".editorconfig",
|
||||
"docs/**.cs",
|
||||
"examples/**.cs",
|
||||
"src/**.cs"
|
||||
"**.cs"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public partial class Program
|
|||
{
|
||||
public static void Main()
|
||||
{
|
||||
Stress(1);
|
||||
Stress(concurrency: 1);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,93 @@
|
|||
# OpenTelemetry Stress Tests
|
||||
|
||||
* [Why would you need stress test](#why-would-you-need-stress-test)
|
||||
* [Running the demo](#running-the-demo)
|
||||
* [Writing your own stress test](#writing-your-own-stress-test)
|
||||
* [Understanding the results](#understanding-the-results)
|
||||
|
||||
## Why would you need stress test
|
||||
|
||||
* It helps you to understand performance.
|
||||
* You can keep it running for days and nights to verify stability.
|
||||
* You can use it to generate lots of load to your backend system.
|
||||
* You can use it with other stress tools (e.g. a memory limiter) to verify how
|
||||
your code reacts to certain resource constraints.
|
||||
|
||||
## Running the demo
|
||||
|
||||
Open a console, run the following command from the current folder:
|
||||
|
||||
```sh
|
||||
dotnet run --framework net5.0 --configuration Release
|
||||
```
|
||||
|
||||
Once the application started, you will see the performance number updates from
|
||||
the console window title.
|
||||
|
||||
Use the `SPACE` key to toggle the console output, which is off by default.
|
||||
|
||||
Use the `ENTER` key to print the latest performance statistics.
|
||||
|
||||
Use the `ESC` key to exit the stress test.
|
||||
|
||||
<!-- markdownlint-disable MD013 -->
|
||||
```text
|
||||
Running (concurrency = 1), press <Esc> to stop...
|
||||
2021-09-28T18:47:17.6807622Z Loops: 17,549,732,467, Loops/Second: 738,682,519, CPU Cycles/Loop: 3
|
||||
2021-09-28T18:47:17.8846348Z Loops: 17,699,532,304, Loops/Second: 731,866,438, CPU Cycles/Loop: 3
|
||||
2021-09-28T18:47:18.0914577Z Loops: 17,850,498,225, Loops/Second: 730,931,752, CPU Cycles/Loop: 3
|
||||
2021-09-28T18:47:18.2992864Z Loops: 18,000,133,808, Loops/Second: 724,029,883, CPU Cycles/Loop: 3
|
||||
2021-09-28T18:47:18.5052989Z Loops: 18,150,598,194, Loops/Second: 733,026,161, CPU Cycles/Loop: 3
|
||||
2021-09-28T18:47:18.7116733Z Loops: 18,299,461,007, Loops/Second: 724,950,210, CPU Cycles/Loop: 3
|
||||
```
|
||||
<!-- markdownlint-enable MD013 -->
|
||||
|
||||
## Writing your own stress test
|
||||
|
||||
Create a simple console application with the following code:
|
||||
|
||||
```csharp
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
public partial class Program
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
Stress(concurrency: 10);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected static void Run()
|
||||
{
|
||||
// add your logic here
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Add the [`Skeleton.cs`](./Skeleton.cs) file to your `*.csproj` file:
|
||||
|
||||
```xml
|
||||
<ItemGroup>
|
||||
<Compile Include="Skeleton.cs" />
|
||||
</ItemGroup>
|
||||
```
|
||||
|
||||
Now you are ready to run your own stress test.
|
||||
|
||||
Some useful notes:
|
||||
|
||||
* You can specify the concurrency using `Stress(concurrency)`, the default value
|
||||
is the number of CPU cores. Keep in mind that concurrency level does not equal
|
||||
to the number of threads.
|
||||
* You want to put `[MethodImpl(MethodImplOptions.AggressiveInlining)]` on
|
||||
`Run()`, this helps to reduce extra flushes on the CPU instruction cache.
|
||||
* You might want to run the stress test under `Release` mode rather than `Debug`
|
||||
mode.
|
||||
|
||||
## Understanding the results
|
||||
|
||||
* `Loops` represent the total number of `Run()` invocations that are completed.
|
||||
* `Loops/Second` represents the rate of `Run()` invocations based on a small
|
||||
sliding window of few hundreds of milliseconds.
|
||||
* `CPU Cycles/Loop` represents the average CPU cycles for each `Run()`
|
||||
invocation, based on a small sliding window of few hundreds of milliseconds.
|
||||
|
|
@ -101,8 +101,8 @@ public partial class Program
|
|||
statistics[i] = 0;
|
||||
while (bContinue)
|
||||
{
|
||||
statistics[i]++;
|
||||
Run();
|
||||
statistics[i]++;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -116,7 +116,11 @@ public partial class Program
|
|||
|
||||
private static ulong GetCpuCycles()
|
||||
{
|
||||
#if NET462
|
||||
if (Environment.OSVersion.Platform != PlatformID.Win32NT)
|
||||
#else
|
||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
#endif
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
# OpenTelemetry Metrics Stress Run
|
||||
|
||||
Use the following example to run Stress test from command line:
|
||||
|
||||
Navigate to `./test/StressTestMetrics` directory and run the following command:
|
||||
|
||||
`dotnet run --framework netcoreapp3.1 --configuration Release`
|
||||
|
||||
The program shows the writes/sec on the console window title
|
||||
and updates it every second.
|
||||
|
||||
At the end of the run, it also shows the overall writes/sec.
|
||||
Loading…
Reference in New Issue