Stress test tool with statistical TPS reports based on Worker Dispatcher in Python
Project description
Python Stress Tool
Stress test tool with statistical TPS reports based on Worker Dispatcher in Python
Features
-
Based on Worker Dispatcher to managed workers
-
Statistical TPS Report in Excel sheets
-
Customized Config for the report
OUTLINE
DEMONSTRATION
Just write your own callback functions based on the Worker Dispatcher library, then run it and generate the report file:
import stress_test
def each_task(id: int, config, task, metadata):
response = requests.get('https://your.name/reserve-api/')
return response
def main():
results = stress_test.start({
'task': {
'list': 1000,
'function': each_task,
}
})
# Generate the TPS report if the stress test completes successfully.
if results != False:
file_path = stress_test.generate_report(file_path='./tps-report.xlsx')
print("Report has been successfully generated at {}".format(file_path))
if __name__ == '__main__':
main()
INTRODUCTION
This tool generates professional TPS report based on the execution result from the Worker Dispatcher library.
Dependencies:
- worker-dispatcher
- openpyxl
INSTALLATION
To install the current release:
$ pip install stress-tool
Import it in your Pythone code:
import stress_test
USAGE
By calling the start() method with the configuration parameters, the package will invoke Worker Dispatcher to dispatch tasks, managing threading or processing based on the provided settings. Once the tasks are completed, generate_report() can be called to produce a TPS report based on the result of Worker Dispatcher.
generate_report()
An example configuration setting with all options is as follows:
def generate_report(config: dict={}, worker_dispatcher: object=None, file_path: str='./tps-report.xlsx', display_intervals: bool=True, interval: float=0, use_processing: bool=False, verbose: bool=False, debug: bool=False):
config
| Option | Type | Deafult | Description |
|---|---|---|---|
| raw_logs.fields | dict | None | Customized field setting for the Raw Logs sheet. Each key represents the field name, and the corresponding value supports two types: - String: Treated as a key to look up in log.metadata (from the Worker Dispatcher) to retrieve the value. - Lambda function: A function that receives log.metadata as input and returns a computed value. |
Sample config
import stress_tool
import requests
# task.callback function
def task(id: int, config, task, metadata):
try:
response = metadata['response'] = requests.get('https://your.name/path/')
try:
api_return_code = metadata['api_return_code'] = response.json().get('returnCode')
return True if api_return_code == "0000" else False
except Exception as e:
return False
except requests.exceptions.ConnectionError:
metadata['error'] = 'ConnectionError'
return False
# Start stress test
results = stress_tool.start({
# 'debug': True,
'task': {
'list': 60,
'function': task,
},
})
# Generate the report
file_path = stress_test.generate_report(config={
'raw_logs': {
'fields': {
'Customized Field - HTTP code': lambda metadata: metadata.get('response').status_code,
'Customized Field - API Return code': 'api_return_code',
'Customized Field - Response Body': lambda metadata: metadata.get('response').text,
}
},
})
display_intervals
Indicates whether to generate Intervals sheet.
interval
Based on Intervals sheet, specifies the number of seconds for each split.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stress_tool-1.2.0.tar.gz.
File metadata
- Download URL: stress_tool-1.2.0.tar.gz
- Upload date:
- Size: 486.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ba4f35d1599bcd84b8eafabea2e8cb1fef499cc6b83ea64e79f91cef861fdac
|
|
| MD5 |
7777905402556d7ee6dc9ef70890c9df
|
|
| BLAKE2b-256 |
ddcfb7172fbade34cb2fd339d537248b6e20091577aa310e99f94d29f0f183f4
|
File details
Details for the file stress_tool-1.2.0-py3-none-any.whl.
File metadata
- Download URL: stress_tool-1.2.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d91c7c537425117a95c90128f7fba55cc6c56b783ea695c5a15bf4989014cd7b
|
|
| MD5 |
839274311ce3f25fbe92ec1b2b92ca0e
|
|
| BLAKE2b-256 |
dc95ef75c3be48b0b5cc779875b075a409cee81aff8a40ac23f7011f71a5eb9e
|