Skip to main content

Pypi-version Pypi-py-version

pages-build-deployment pypi-publish

Pypi-format Pypi-status

Maintained GitHub Repo created GitHub commit activity GitHub last commit

Stress Injector

Python module, to inject memory, CPU and URL stress.

Insights about CPU Stress
  • To achieve CPU stress, I have used multiprocess, looped for the number of logical cores, triggering an infinite loop on each core.
  • The infinite loop will run for a given number of seconds (provided by the user)
  • Mean-while the cpu_percent from psutil runs (in a dedicated thread) in an infinite loop calculating the current CPU utilization on each CPU core.
  • The dedicated thread runs for 3 seconds in addition to the number of seconds provided by the user.
  • Once the given number of seconds have passed, the processes and threads initiated to monitor CPU usage are stopped.

Insights about Memory Stress
  • In this script, I have used numpy.random.bytes which are sampled from uniform distribution.
  • These random bytes are collected from the machine's physical memory increasing the program's usage.
  • I have then used getrusage (get resource usage) for SELF to get the memory consumed only by the current script.
  • The size_converter converts the bytes from resource usage to a human understandable format.

Insights about URL Stress
  • In this script, I have used threadpools to make concurrent requests.
  • The script uses requests module to make calls.
  • Takes arguments
    • rate: Number of calls to make. Defaults to 100K
    • timeout: Timeout for each request. Defaults to 0.5
    • retry_limit: Retry limit if the system is unable to spinup more threads. Defaults to 5
    • circuit_break: Wait time in seconds between retries. Defaults to 5
    • request_type: Function from requests module.

Usage

pip install stress-injector

CPU Stress

import stressinjector as injector


if __name__ == '__main__':
    injector.CPUStress(seconds=300)

Memory Stress

import stressinjector as injector


if __name__ == '__main__':
    injector.MemoryStress(gigabytes=2_000)

URL Stress

import os
import stressinjector as injector


if __name__ == '__main__':
    injector.URLStress(url='http://0.0.0.0:5002/')  # Stress test GET calls

    # Stress test POST calls, also supports PUT, and DELETE
    sample_data = {'headers': {'Authorization': 'Bearer %s' % os.environ.get('TOKEN')}}
    injector.URLStress(
      url='http://0.0.0.0:5002/',
      request_type=injector.RequestType.post,
      **sample_data
    )

This module can only induce stress on a given URL by making N number of calls. Suitable for APIs running on localhost.

To perform a real-time load test, refer locust.io

Coding Standards

Docstring format: Google
Styling conventions: PEP 8
Clean code with pre-commit hooks: flake8 and isort

Release Notes

Requirement

python -m pip install gitverse

Usage

gitverse-release reverse -f release_notes.rst -t 'Release Notes'

Linting

PreCommit will ensure linting, and the doc creation are run on every commit.

Requirement

pip install --no-cache sphinx==5.1.1 pre-commit recommonmark

Usage

pre-commit run --all-files

Pypi Package

pypi-module

https://pypi.org/project/stress-injector/

Runbook

made-with-sphinx-doc

https://thevickypedia.github.io/stress-injector/

© Vignesh Sivanandha Rao

Licensed under the MIT License

Metadata

Release files for stress-injector 0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for stress-injector 0.9
File Interpreter ABI Platform
stress_injector-0.9-py3-none-any.whl Python 3 none any Details

Release files / stress_injector-0.9-py3-none-any.whl

Download URL stress_injector-0.9-py3-none-any.whl
Size 12.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc0200a153362cde6ef2b8e68d71290c491275c5478b078f8b8eb28dfd8f13b2
BLAKE2b-256 checksum
How to use checksums
141f3be120b004f4169b38e23823231263b1f5d19afb9bf5e91694703b811e3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release history Release notifications | RSS feed

This release

0.9 This release

1 release file

0.8

1 release file

0.7

1 release file

0.5

1 release file

0.4

1 release file

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page