Skip to content

Commit 24d52c4

Browse files
authored
[tools] Stress test README updates (#5388)
1 parent 73b6e30 commit 24d52c4

File tree

4 files changed

+166
-51
lines changed

4 files changed

+166
-51
lines changed

test/OpenTelemetry.Tests.Stress.Logs/README.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,23 @@ based on the [OpenTelemetry.Tests.Stress](../OpenTelemetry.Tests.Stress/README.m
1010
Open a console, run the following command from the current folder:
1111

1212
```sh
13-
dotnet run --framework net6.0 --configuration Release
13+
dotnet run --framework net8.0 --configuration Release
14+
```
15+
16+
To see command line options available, run the following command from the
17+
current folder:
18+
19+
```sh
20+
dotnet run --framework net8.0 --configuration Release -- --help
21+
```
22+
23+
The help output includes settings and their explanations:
24+
25+
```text
26+
-c, --concurrency The concurrency (maximum degree of parallelism) for the stress test. Default value: Environment.ProcessorCount.
27+
28+
-p, --internal_port The Prometheus http listener port where Prometheus will be exposed for retrieving internal metrics while the stress test is running. Set to '0' to
29+
disable. Default value: 9464.
30+
31+
-d, --duration The duration for the stress test to run in seconds. If set to '0' or a negative value the stress test will run until canceled. Default value: 0.
1432
```

test/OpenTelemetry.Tests.Stress.Metrics/README.md

+31-5
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,41 @@ This stress test is specifically for Metrics SDK, and is based on the
55

66
* [Running the stress test](#running-the-stress-test)
77

8-
> [!NOTE]
9-
> To run the stress tests for Histogram, comment out the `Run` method
10-
for `Counter` and uncomment everything related to `Histogram` in the
11-
[Program.cs](../OpenTelemetry.Tests.Stress.Metrics/Program.cs).
12-
138
## Running the stress test
149

1510
Open a console, run the following command from the current folder:
1611

1712
```sh
1813
dotnet run --framework net8.0 --configuration Release
1914
```
15+
16+
To see command line options available, run the following command from the
17+
current folder:
18+
19+
```sh
20+
dotnet run --framework net8.0 --configuration Release -- --help
21+
```
22+
23+
The help output includes settings and their explanations:
24+
25+
```text
26+
-t, --type The metrics stress test type to run. Valid values: [Histogram, Counter]. Default value: Histogram.
27+
28+
-m, --metrics_port The Prometheus http listener port where Prometheus will be exposed for retrieving test metrics while the stress test is running. Set to '0' to disable.
29+
Default value: 9185.
30+
31+
-v, --view Whether or not a view should be configured to filter tags for the stress test. Default value: False.
32+
33+
-o, --otlp Whether or not an OTLP exporter should be added for the stress test. Default value: False.
34+
35+
-i, --interval The OTLP exporter export interval in milliseconds. Default value: 5000.
36+
37+
-e, --exemplars Whether or not to enable exemplars for the stress test. Default value: False.
38+
39+
-c, --concurrency The concurrency (maximum degree of parallelism) for the stress test. Default value: Environment.ProcessorCount.
40+
41+
-p, --internal_port The Prometheus http listener port where Prometheus will be exposed for retrieving internal metrics while the stress test is running. Set to '0' to
42+
disable. Default value: 9464.
43+
44+
-d, --duration The duration for the stress test to run in seconds. If set to '0' or a negative value the stress test will run until canceled. Default value: 0.
45+
```

test/OpenTelemetry.Tests.Stress.Traces/README.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,23 @@ based on the [OpenTelemetry.Tests.Stress](../OpenTelemetry.Tests.Stress/README.m
1010
Open a console, run the following command from the current folder:
1111

1212
```sh
13-
dotnet run --framework net6.0 --configuration Release
13+
dotnet run --framework net8.0 --configuration Release
14+
```
15+
16+
To see command line options available, run the following command from the
17+
current folder:
18+
19+
```sh
20+
dotnet run --framework net8.0 --configuration Release -- --help
21+
```
22+
23+
The help output includes settings and their explanations:
24+
25+
```text
26+
-c, --concurrency The concurrency (maximum degree of parallelism) for the stress test. Default value: Environment.ProcessorCount.
27+
28+
-p, --internal_port The Prometheus http listener port where Prometheus will be exposed for retrieving internal metrics while the stress test is running. Set to '0' to
29+
disable. Default value: 9464.
30+
31+
-d, --duration The duration for the stress test to run in seconds. If set to '0' or a negative value the stress test will run until canceled. Default value: 0.
1432
```

test/OpenTelemetry.Tests.Stress/README.md

+97-44
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,45 @@
1818
Open a console, run the following command from the current folder:
1919

2020
```sh
21-
dotnet run --framework net6.0 --configuration Release
21+
dotnet run --framework net8.0 --configuration Release
22+
```
23+
24+
To see command line options available, run the following command from the
25+
current folder:
26+
27+
```sh
28+
dotnet run --framework net8.0 --configuration Release -- --help
29+
```
30+
31+
The help output includes settings and their explanations:
32+
33+
```text
34+
-c, --concurrency The concurrency (maximum degree of parallelism) for the stress test. Default value: Environment.ProcessorCount.
35+
36+
-p, --internal_port The Prometheus http listener port where Prometheus will be exposed for retrieving internal metrics while the stress test is running. Set to '0' to
37+
disable. Default value: 9464.
38+
39+
-d, --duration The duration for the stress test to run in seconds. If set to '0' or a negative value the stress test will run until canceled. Default value: 0.
2240
```
2341

2442
Once the application started, you will see the performance number updates from
25-
the console window title.
43+
the console window title and the console window itself.
44+
45+
While a test is running...
2646

27-
Use the `SPACE` key to toggle the console output, which is off by default.
47+
* Use the `SPACE` key to toggle the console output, which is on by default.
2848

29-
Use the `ENTER` key to print the latest performance statistics.
49+
* Use the `ENTER` key to print the latest performance statistics.
3050

31-
Use the `ESC` key to exit the stress test.
51+
* Use the `ESC` key to exit the stress test.
52+
53+
Example output while a test is running:
3254

3355
```text
34-
Running (concurrency = 1), press <Esc> to stop...
35-
2021-09-28T18:47:17.6807622Z Loops: 17,549,732,467, Loops/Second: 738,682,519, CPU Cycles/Loop: 3
36-
2021-09-28T18:47:17.8846348Z Loops: 17,699,532,304, Loops/Second: 731,866,438, CPU Cycles/Loop: 3
37-
2021-09-28T18:47:18.0914577Z Loops: 17,850,498,225, Loops/Second: 730,931,752, CPU Cycles/Loop: 3
38-
2021-09-28T18:47:18.2992864Z Loops: 18,000,133,808, Loops/Second: 724,029,883, CPU Cycles/Loop: 3
39-
2021-09-28T18:47:18.5052989Z Loops: 18,150,598,194, Loops/Second: 733,026,161, CPU Cycles/Loop: 3
40-
2021-09-28T18:47:18.7116733Z Loops: 18,299,461,007, Loops/Second: 724,950,210, CPU Cycles/Loop: 3
56+
Options: {"Concurrency":20,"PrometheusInternalMetricsPort":9464,"DurationSeconds":0}
57+
Run OpenTelemetry.Tests.Stress.exe --help to see available options.
58+
Running (concurrency = 20, internalPrometheusEndpoint = http://localhost:9464/metrics/), press <Esc> to stop, press <Spacebar> to toggle statistics in the console...
59+
Loops: 17,384,826,748, Loops/Second: 2,375,222,037, CPU Cycles/Loop: 24, RunningTime (Seconds): 7
4160
```
4261

4362
The stress test metrics are exposed via
@@ -73,59 +92,91 @@ process_runtime_dotnet_gc_allocations_size_bytes 5485192 1658950184752
7392

7493
## Writing your own stress test
7594

76-
> [!WARNING]
77-
> These instructions are out of date and should NOT be followed. They will be
78-
updated soon.
79-
8095
Create a simple console application with the following code:
8196

8297
```csharp
83-
using System.Runtime.CompilerServices;
98+
using OpenTelemetry.Tests.Stress;
8499

85-
public partial class Program
100+
public static class Program
86101
{
87-
public static void Main()
102+
public static int Main(string[] args)
88103
{
89-
Stress(concurrency: 10, prometheusPort: 9464);
104+
return StressTestFactory.RunSynchronously<MyStressTest>(args);
90105
}
91106

92-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
93-
protected static void Run()
107+
private sealed class MyStressTest : StressTest<StressTestOptions>
94108
{
95-
// add your logic here
109+
public MyStressTest(StressTestOptions options)
110+
: base(options)
111+
{
112+
}
113+
114+
protected override void RunWorkItemInParallel()
115+
{
116+
}
96117
}
97118
}
98119
```
99120

100-
Add the Skeleton.cs file to your `*.csproj` file:
121+
Add the following project reference to the project:
101122

102123
```xml
103-
<ItemGroup>
104-
<Compile Include="Skeleton.cs" />
105-
</ItemGroup>
124+
<ProjectReference Include="$(RepoRoot)\test\OpenTelemetry.Tests.Stress\OpenTelemetry.Tests.Stress.csproj" />
106125
```
107126

108-
Add the following packages to the project:
127+
Now you are ready to run your own stress test. Add test logic in the
128+
`RunWorkItemInParallel` method to measure performance.
109129

110-
```shell
111-
dotnet add package OpenTelemetry.Exporter.Prometheus --prerelease
112-
dotnet add package OpenTelemetry.Instrumentation.Runtime --prerelease
113-
```
130+
To define custom options create an options class which derives from
131+
`StressTestOptions`:
114132

115-
Now you are ready to run your own stress test.
133+
```csharp
134+
using CommandLine;
135+
using OpenTelemetry.Tests.Stress;
136+
137+
public static class Program
138+
{
139+
public static int Main(string[] args)
140+
{
141+
return StressTestFactory.RunSynchronously<MyStressTest, MyStressTestOptions>(args);
142+
}
143+
144+
private sealed class MyStressTest : StressTest<MyStressTestOptions>
145+
{
146+
public MyStressTest(MyStressTestOptions options)
147+
: base(options)
148+
{
149+
}
150+
151+
protected override void RunWorkItemInParallel()
152+
{
153+
// Use this.Options here to access options supplied
154+
// on the command line.
155+
}
156+
}
157+
158+
private sealed class MyStressTestOptions : StressTestOptions
159+
{
160+
[Option('r', "rate", HelpText = "Add help text here for the rate option. Default value: 0.", Required = false)]
161+
public int Rate { get; set; } = 0;
162+
}
163+
}
164+
```
116165

117166
Some useful notes:
118167

119-
* You can specify the concurrency using `Stress(concurrency: {concurrency
120-
number})`, the default value is the number of CPU cores. Keep in mind that
121-
concurrency level does not equal to the number of threads.
122-
* You can specify a local PrometheusExporter listening port using
123-
`Stress(prometheusPort: {port number})`, the default value is `0`, which will
124-
turn off the PrometheusExporter.
125-
* You want to put `[MethodImpl(MethodImplOptions.AggressiveInlining)]` on
126-
`Run()`, this helps to reduce extra flushes on the CPU instruction cache.
127-
* You might want to run the stress test under `Release` mode rather than `Debug`
128-
mode.
168+
* It is generally best practice to run the stress test for code compiled in
169+
`Release` configuration rather than `Debug` configuration. `Debug` builds
170+
typically are not optimized and contain extra code which will change the
171+
performance characteristics of the logic under test. The stress test will
172+
write a warning message to the console when starting if compiled with `Debug`
173+
configuration.
174+
* You can specify the concurrency using `-c` or `--concurrency` command line
175+
argument, the default value if not specified is the number of CPU cores. Keep
176+
in mind that concurrency level does not equal to the number of threads.
177+
* You can use the duration `-d` or `--duration` command line argument to run the
178+
stress test for a specific time period. This is useful when comparing changes
179+
across multiple runs.
129180

130181
## Understanding the results
131182

@@ -134,4 +185,6 @@ Some useful notes:
134185
sliding window of few hundreds of milliseconds.
135186
* `CPU Cycles/Loop` represents the average CPU cycles for each `Run()`
136187
invocation, based on a small sliding window of few hundreds of milliseconds.
137-
* `Runaway Time` represents the runaway time (seconds) since the test started.
188+
* `Total Running Time` represents the running time (seconds) since the test started.
189+
* `GC Total Allocated Bytes` (not available on .NET Framework) shows the total
190+
amount of memory allocated while the test was running.

0 commit comments

Comments
 (0)