Skip to main content

Python module, to inject memory and CPU stress.

Project description

Pypi-version Pypi-py-version

docs pypi

Pypi-format Pypi-status

Maintained GitHub Repo created GitHub commit activity GitHub last commit

Stress Injector

Python module, to inject memory and CPU stress

Insights:

CPU Stress:

  • To achieve CPU stress, I have used multiprocess, looped for the # of logical cores, triggering an infinite loop on each core.
  • The infinite loop will run for a given # of seconds provided by user.
  • Mean-while the cpu_percent from psutil runs (dedicated thread) in an infinite loop with kill signal set to False calculating the current CPU utilization on each CPU core.
  • Once the given # of seconds have passed, the kill_signal is set to True and some painful steps to gracefully stop the multiprocess and multi-thread.

Memory Stress:

  • In this script, I have used numpy.random.bytes which are sampled from uniform distribution.
  • Generating these random bytes induces a stress on the machine's memory 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.

Pypi Module

https://pypi.org/project/gmail-connector/

Usage

pip install stress-injector


CPU Stress

from stressinjector.cpu import cpu_stress

cpu_stress()

Memory Stress

from stressinjector.memory import memory_stress

memory_stress()

Coding Standards:

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

Pre-Commit

pre-commit will run flake8 and isort to ensure proper coding standards along with docs_generator to update the runbook

pre-commit run --all-files

Runbook:

https://thevickypedia.github.io/stress_injector/

Generated using sphinx-autogen

License & copyright

© Vignesh Sivanandha Rao

Licensed under the MIT License

Change Log

0.0.1 (08/04/2021)

  • Onboard stress-injector to pypi

0.0.2 (08/04/2021)

  • Update docs
  • Change module name
  • Fix broken references

0.0.3 (08/04/2021)

  • Roll back module name
  • Update badges in README.md

0.0.4 (08/04/2021)

  • Mark methods as internal
  • Update dependencies and readme

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-injector-0.0.4.tar.gz (7.2 kB view hashes)

Uploaded Source

Built Distribution

stress_injector-0.0.4-py2.py3-none-any.whl (7.1 kB view hashes)

Uploaded Python 2 Python 3

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