Skip to main content

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

PyPI

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, log):
    response = requests.get(config['my_endpoint'] + task)
    return response

def main():
    results = stress_test.start({
        'task': {
            'list': ['ORD_AH001', 'ORD_KL502', '...' , 'ORD_GR393'],
            'callback': each_task,
            'config': {
                'my_endpoint': 'https://your.name/order-handler/'
            },
        }
    })
    # 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:


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=1):

config

Option Type Deafult Description
raw_logs.fields dict None Customized field setting for the Raw Logs sheet.
Key is field name, the value can be two types:
- String: Use the provided value as the log key name from Worker Dispatcher to retrieve the value.
- lambda function: Retrieve the return value from the lambda function.

Sample config

import stress_tool
import requests

# task.callback function
def task(id: int, config, task, log):
    try:
        response = log['response'] = requests.get('https://your.name/path/')
        try:
            api_return_code = log['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:
        log['error'] = 'ConnectionError'
    return False

# Start stress test
results = stress_tool.start({
    # 'debug': True,
    'task': {
        'list': 60,
        'callback': task,
    },
})

# Generate the report
file_path = stress_test.generate_report(config={
    'raw_logs': {
        'fields': {
            'Customized Field - HTTP code': lambda log: log.get('response').status_code,
            'Customized Field - API Return code': 'api_return_code',
            'Customized Field - Response Body': lambda log: log.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

stress_tool-1.0.2.tar.gz (486.6 kB view details)

Uploaded Source

Built Distribution

stress_tool-1.0.2-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file stress_tool-1.0.2.tar.gz.

File metadata

  • Download URL: stress_tool-1.0.2.tar.gz
  • Upload date:
  • Size: 486.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for stress_tool-1.0.2.tar.gz
Algorithm Hash digest
SHA256 d58034015a39a3d416c9eec4edf0808336a8faf4ad7ddf3363bfc30081bb4604
MD5 a0dbec0b7bb0fee9ec54939723369911
BLAKE2b-256 71fa812e6b73b49f00aa7860a077ad717c89e2e09c888b627be3088587b00a41

See more details on using hashes here.

File details

Details for the file stress_tool-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: stress_tool-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for stress_tool-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e413a05b296a5249a063ba1ed70b38553b7521ec105f099bf8d762ceed104149
MD5 8ac34bbab479e3b1ff3238ce22251ee5
BLAKE2b-256 2cedfdfa62cc07f03106e7f1e23a15cc9d88001fd81c6201d3bb613b4802eea6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page