You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Draft multiproc support
* Improve barrier reliability
* Spelling
* Run global setup per proc
* Update cspell
* Add parameters to SleepTest
- Aligns with .NET and supports more scenarios
* Add LogTest to help observe and debug the framework
* Subprocess spawn instead of fork
* Fix status reporting
* Improved error handling
* Updated docs
* Apply suggestions from code review
Co-authored-by: Paul Van Eck <[email protected]>
* Cspell fixes
* Typo
Co-authored-by: Mike Harder <[email protected]>
Co-authored-by: Paul Van Eck <[email protected]>
The perfstress framework has been added to azure-devtools module. The code can be found [here](https://github.com/Azure/azure-sdk-for-python/tree/main/tools/azure-devtools/src/azure_devtools/perfstress_tests).
@@ -22,52 +26,69 @@ the tests. To start using the framework, make sure that `azure-devtools` is incl
22
26
```
23
27
The perfstress framework offers the following:
24
28
- The `perfstress` commandline tool.
25
-
- The `PerfStressTest` baseclass.
26
-
- The `BatchPerfTest` baseclass.
29
+
- The `PerfStressTest` baseclass (each test run counted as a single data point).
30
+
- The `BatchPerfTest` baseclass (each test run counted as 1 or more data points).
31
+
- The `EventPerfTest` baseclass (supports a callback based event handler).
27
32
- Stream utilities for uploading/downloading without storing in memory: `RandomStream`, `AsyncRandomStream`, `WriteStream`.
28
33
- A `get_random_bytes` utility for returning randomly generated data.
29
34
- A series of "system tests" to test the perfstress framework along with the performance of the raw transport layers (requests, aiohttp, etc).
30
35
31
-
## The PerfStressTest base
32
-
The `PerfStressTest` base class is what will be used for all perf test implementations. It provides the following API:
36
+
## The provided baseclasses:
37
+
The perf framework provides three baseclasses to accommodate testing different SDK scenarios. Depending on which baseclass you select, different
38
+
methods will need to be implemented. All of them have a common base API (`_PerfTestBase`), defined below:
39
+
33
40
```python
34
-
classPerfStressTest:
41
+
class_PerfTestBase:
35
42
args = {} # Command line arguments
36
43
44
+
@property
45
+
defcompleted_operations(self) -> int:
46
+
# Total number of operations completed by run_all(). Reset after warmup.
47
+
48
+
@property
49
+
deflast_completion_time(self) -> float:
50
+
# Elapsed time between start of warmup/run and last completed operation. Reset after warmup.
51
+
37
52
def__init__(self, arguments):
38
53
# The command line args can be accessed on construction.
39
54
40
-
asyncdefglobal_setup(self):
41
-
# Can be optionally defined. Only run once, regardless of parallelism.
55
+
asyncdefglobal_setup(self) -> None:
56
+
# Can be optionally defined. Only run once per process, regardless of multi-threading.
57
+
# The baseclasses will also define logic here, so if you override this method, make sure you include a call to super().
42
58
43
-
asyncdefglobal_cleanup(self):
44
-
# Can be optionally defined. Only run once, regardless of parallelism.
59
+
asyncdefglobal_cleanup(self) -> None:
60
+
# Can be optionally defined. Only run once per process, regardless of multi-threading.
61
+
# The baseclasses will also define logic here, so if you override this method, make sure you include a call to super().
45
62
46
-
asyncdefpost_setup(self):
63
+
asyncdefpost_setup(self) -> None:
47
64
# Post-setup called once per parallel test instance.
48
65
# Used by base classes to setup state (like test-proxy) after all derived class setup is complete.
49
66
# There should be no need to overwrite this function.
50
67
51
-
asyncdefpre_cleanup(self):
68
+
asyncdefpre_cleanup(self) -> None:
52
69
# Pre-cleanup called once per parallel test instance.
53
70
# Used by base classes to cleanup state (like test-proxy) before all derived class cleanup runs.
54
71
# There should be no need to overwrite this function.
55
72
56
-
asyncdefsetup(self):
73
+
asyncdefsetup(self) -> None:
57
74
# Can be optionally defined. Run once per test instance, after global_setup.
75
+
# The baseclasses will also define logic here, so if you override this method, make sure you include a call to super().
58
76
59
-
asyncdefcleanup(self):
77
+
asyncdefcleanup(self) -> None:
60
78
# Can be optionally defined. Run once per test instance, before global_cleanup.
79
+
# The baseclasses will also define logic here, so if you override this method, make sure you include a call to super().
61
80
62
-
asyncdefclose(self):
81
+
asyncdefclose(self) -> None:
63
82
# Can be optionally defined. Run once per test instance, after cleanup and global_cleanup.
83
+
# The baseclasses will also define logic here, so if you override this method, make sure you include a call to super().
64
84
65
-
defrun_sync(self):
66
-
# Must be implemented. This will be the perf test to be run synchronously.
85
+
defrun_all_sync(self, duration: int) -> None:
86
+
# Run all sync tests, including both warmup and duration. This method is implemented by the provided base
87
+
# classes, there should be no need to overwrite this function.
67
88
68
-
asyncdefrun_async(self):
69
-
#Must be implemented. This will be the perf test to be run asynchronously.
70
-
#If writing a test for a T1 legacy SDK with no async, implement this method and raise an exception.
#Run all async tests, including both warmup and duration. This method is implemented by the provided base
91
+
#classes, there should be no need to overwrite this function.
71
92
72
93
@staticmethod
73
94
defadd_arguments(parser):
@@ -78,17 +99,92 @@ class PerfStressTest:
78
99
defget_from_env(variable):
79
100
# Get the value of an env var. If empty or not found, a ValueError will be raised.
80
101
```
102
+
### The PerfStressTest baseclass
103
+
This is probably the most common test baseclass, and should be used where each test run represents 1 logical successful result.
104
+
For example, 1 successful service request, 1 file uploaded, 1 output downloaded, etc.
105
+
Along with the above base API, the following methods will need to be implemented:
106
+
107
+
```python
108
+
classPerfStressTest:
109
+
defrun_sync(self) -> None:
110
+
# Must be implemented. This will be the perf test to be run synchronously.
111
+
112
+
asyncdefrun_async(self) -> None:
113
+
# Must be implemented. This will be the perf test to be run asynchronously.
114
+
# If writing a test for an SDK without async support (e.g. a T1 legacy SDK), implement this method and raise an exception.
115
+
116
+
```
117
+
### The BatchPerfTest baseclass
118
+
The `BatchPerfTest` class is the parent class of the above `PerfStressTest` class that is further abstracted to allow for more flexible testing of SDKs that don't conform to a 1:1 ratio of operations to results.
119
+
This baseclass should be used where each test run represent a more than a single result. For example, results that are uploaded
120
+
or downloaded in batches.
121
+
Along with the above base API, the following methods will need to be implemented:
122
+
123
+
```python
124
+
classBatchPerfTest:
125
+
defrun_batch_sync(self) -> int:
126
+
# Run cumulative operation(s) synchronously - i.e. an operation that results in more than a single logical result.
127
+
# When inheriting from BatchPerfTest, this method will need to be implemented.
128
+
# Must return the number of completed results represented by a single successful test run.
129
+
130
+
asyncdefrun_batch_async(self) -> int:
131
+
# Run cumulative operation(s) asynchronously - i.e. an operation that results in more than a single logical result.
132
+
# When inheriting from BatchPerfTest, this method will need to be implemented.
133
+
# Must return the number of completed results represented by a single successful test run.
134
+
# If writing a test for an SDK without async support (e.g. a T1 legacy SDK), implement this method and raise an exception.
135
+
136
+
```
137
+
### The EventPerfTest baseclass
138
+
This baseclass should be used when SDK operation to be tested requires starting up a process that acts on events via callback.
139
+
Along with the above base API, the following methods will need to be implemented:
140
+
```python
141
+
classEventPerfTest:
142
+
defevent_raised_sync(self) -> None:
143
+
# This method should not be overwritten, instead it should be called in your sync callback implementation
144
+
# to register a single successful event.
145
+
146
+
deferror_raised_sync(self, error):
147
+
# This method should not be overwritten, instead it should be called in your sync callback implementation
148
+
# to register a failure in the event handler. This will result in the test being shutdown.
149
+
150
+
asyncdefevent_raised_async(self):
151
+
# This method should not be overwritten, instead it should be called in your async callback implementation
152
+
# to register a single successful event.
153
+
154
+
asyncdeferror_raised_async(self, error):
155
+
# This method should not be overwritten, instead it should be called in your async callback implementation
156
+
# to register a failure in the event handler. This will result in the test being shutdown.
157
+
158
+
defstart_events_sync(self) -> None:
159
+
# Must be implemented - starts the synchronous process for receiving events.
160
+
# This can be blocking for the duration of the test as it will be run during setup() in a thread.
161
+
162
+
defstop_events_sync(self) -> None:
163
+
# Stop the synchronous process for receiving events. Must be implemented. Will be called during cleanup.
164
+
165
+
asyncdefstart_events_async(self) -> None:
166
+
# Must be implemented - starts the asynchronous process for receiving events.
167
+
# This can be blocking for the duration of the test as it will be scheduled in the eventloop during setup().
168
+
169
+
asyncdefstop_events_async(self) -> None:
170
+
# Stop the asynchronous process for receiving events. Must be implemented. Will be called during cleanup.
171
+
172
+
```
173
+
81
174
## Default command options
82
175
The framework has a series of common command line options built in:
83
176
-`-d --duration=10` Number of seconds to run as many operations (the "run" function) as possible. Default is 10.
84
-
-`-i --iterations=1` Number of test iterations to run. Default is 1.
85
177
-`-p --parallel=1` Number of tests to run in parallel. Default is 1.
178
+
-`--processes=multiprocessing.cpu_count()` Number of concurrent processes that the parallel test runs should be distributed over. This is used
179
+
together with `--parallel` to distribute the number of concurrent tests first between available processes, then between threads within each
180
+
process. For example if `--parallel=16 --processes=4`, 4 processes will be started, each running 4 concurrent threaded test instances.
181
+
Best effort will be made to distribute evenly, for example if `--parallel=10 --processes=4`, 4 processes will be start, two of which run 3 threads, and two that run 2 threads. It's therefore recommended that the value of `parallel` be less than, or a multiple of, the value of `processes`.
86
182
-`-w --warm-up=5` Number of seconds to spend warming up the connection before measuring begins. Default is 5.
87
183
-`--sync` Whether to run the tests in sync or async. Default is False (async).
88
184
-`--no-cleanup` Whether to keep newly created resources after test run. Default is False (resources will be deleted).
89
185
-`--insecure` Whether to run without SSL validation. Default is False.
90
186
-`-x --test-proxies` Whether to run the tests against the test proxy server. Specify the URL(s) for the proxy endpoint(s) (e.g. "https://localhost:5001"). Multiple values should be semi-colon-separated.
91
-
-`--profile` Whether to run the perftest with cProfile. If enabled (default is False), the output file of a single iteration will be written to the current working directory in the format `"cProfile-<TestClassName>-<TestID>-<sync|async>.pstats"`.
187
+
-`--profile` Whether to run the perftest with cProfile. If enabled (default is False), the output file of a single iteration will be written to the current working directory in the format `"cProfile-<TestClassName>-<TestID>-<sync|async>.pstats"`.**Note:** The profiler is not currently supported for the `EventPerfTest` baseclass.
92
188
93
189
## Running with the test proxy
94
190
Follow the instructions here to install and run the test proxy server:
@@ -98,29 +194,6 @@ Once running, in a separate process run the perf test in question, combined with
The `BatchPerfTest` class is the parent class of the above `PerfStressTest` class that is further abstracted to allow for more flexible testing of SDKs that don't conform to a 1:1 ratio of operations to results.
103
-
An example of this is a messaging SDK that streams multiple messages for a period of time.
104
-
This base class uses the same setup/cleanup/close functions described above, however instead of `run_sync` and `run_async`, it has `run_batch_sync` and `run_batch_async`:
105
-
```python
106
-
classBatchPerfTest:
107
-
108
-
defrun_batch_sync(self) -> int:
109
-
"""
110
-
Run cumultive operation(s) - i.e. an operation that results in more than a single logical result.
111
-
:returns: The number of completed results.
112
-
:rtype: int
113
-
"""
114
-
115
-
asyncdefrun_batch_async(self) -> int:
116
-
"""
117
-
Run cumultive operation(s) - i.e. an operation that results in more than a single logical result.
118
-
:returns: The number of completed results.
119
-
:rtype: int
120
-
"""
121
-
122
-
```
123
-
An example test case using the `BatchPerfTest` base can be found below.
124
197
125
198
# Adding performance tests to an SDK
126
199
The performance tests will be in a submodule called `perfstress_tests` within the `tests` directory in an SDK project.
0 commit comments