Python module, to inject memory and CPU stress.
Project description
Stress Injector
Python module, to inject memory and CPU stress
Insights:
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.
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.
Pypi Module
https://pypi.org/project/stress-injector/
Usage
pip install stress-injector
from stressinjector.cpu import CPUStress
CPUStress().run() # will trigger a prompt asking for the number of seconds to be stressed.
# OR
CPUStress(seconds=60).run() # will run stress on all available logical cores for 60 seconds without a prompt.
from stressinjector.memory import MemoryStress
MemoryStress().run() # will trigger a prompt asking for the number of gigabytes to be stressed.
# OR
MemoryStress(gigabytes=10).run() # will run stress on the memory unit with 10 GigaBytes without a prompt.
Coding Standards:
Docstring format: Google
Styling conventions: PEP 8
Clean code with pre-commit hooks: flake8
and
isort
Pre-Commit
python3 -m pip install sphinx 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
0.0.5 (08/11/2021)
- Fix broken CPU stress because of global variable
- Wrap everything inside a class
- Add an option to pass the user input when the class is initialized
- Update dependencies, docs and readme
- Update variable names to right convention
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 Distribution
stress-injector-0.0.5.tar.gz
(7.8 kB
view hashes)
Built Distribution
Close
Hashes for stress_injector-0.0.5-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d24a66179d51a5de5bb3d2bf0fe53a27101eb55c36855ac4eb810f1dec179289 |
|
MD5 | c4721a4738d3a5216f63df7e727f11a1 |
|
BLAKE2b-256 | 8757c43415b4277b700a6186b4ebc5530ad58bef5f32478da097abe688a9015b |