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('https://your.name/reserve-api/')
    return response

def main():
    results = stress_test.start({
        'task': {
            'list': 1000,
            'callback': 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:


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.
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.1.0.tar.gz (486.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stress_tool-1.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: stress_tool-1.1.0.tar.gz
  • Upload date:
  • Size: 486.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for stress_tool-1.1.0.tar.gz
Algorithm Hash digest
SHA256 6ac921ef34d00985025279780c249e5ba28f86eec6da7a44357bf9246bc53b0f
MD5 7fdc61ef81da388c7cc20f1ef9442dad
BLAKE2b-256 6cb8997eec2d931065af4e137c8001cf091f380ffc67b58817756f9ad20b5c73

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stress_tool-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for stress_tool-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba0cab25b0cc34bb6ea19a5b4ff7797b495d87060d8cf12a6c53d6945e224aa0
MD5 33ef4382d515c503170db04b2aeddc4e
BLAKE2b-256 ace689ca544bfb293422f1891465434a35ffe53acf7247ed886246c3fc7bf1ef

See more details on using hashes here.

Supported by

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