Python module, to inject memory and CPU stress, and URL load test
Project description
Stress Injector
Python module, to inject memory and CPU 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 user.
- Mean-while the
cpu_percent
frompsutil
runs (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
multiprocess
andthread
that was 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. - Generating these random bytes induces a stress on the machine's memory usage.
- I have then used
getrusage
(get resource usage) forSELF
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 GET requests.
- The script uses builtin library
urllib
to make the GET 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
Usage
pip install stress-injector
import stressinjector as injector
if __name__ == '__main__':
injector.CPUStress(seconds=300).run()
injector.MemoryStress(gigabytes=2_000).run()
injector.URLStress(url='http://0.0.0.0:5002/').run()
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 changelog-generator
Usage
changelog 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
https://pypi.org/project/stress-injector/
Runbook
https://thevickypedia.github.io/stress-injector/
License & copyright
© Vignesh Sivanandha Rao
Licensed under the MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for stress_injector-0.4a0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 553d74571f8f7ef753443d89aa438f2421cbd29b42175b95a5b21f8e53392141 |
|
MD5 | aebd4b37397d8ac962911d115eaf1699 |
|
BLAKE2b-256 | 931678145c01c4f04ac577cb156d636bd0ad7147afe9903d15a1181cd22a8ed6 |