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_percentfrompsutilruns (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
multiprocessandthreadthat was initiated to monitor CPU usage are stopped.
Memory Stress
- In this script, I have used
numpy.random.byteswhich 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) forSELFto get the memory consumed only by the current script. - The
size_converterconverts the bytes from resource usage to a human understandable format.
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
Linting
PreCommit will ensure linting, and the doc creation are run on every commit.
Requirement
pip install --no-cache --upgrade sphinx 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
Change Log
0.2.7 (01/10/2022)
- Upgrade packages in requirements.txt
- Update maintenance year to 2022
- Generate CHANGELOG in LIFO manner
- Update docs big time
0.2.6 (08/14/2021)
- Stop the thread that measures CPU usage during a manual interrupt
- Previously CPUStress measurement used to run until the current time reaches 3 seconds in addition to the user input.
- Since the measurement runs in a dedicated thread this, stopping stress never stopped the usage display.
- Now CPUStress measurement will stop when a manual interrupt is received using a stop_flag variable.
- Update docs and README.md internal link.
0.2.5 (08/11/2021)
- Bug fix
- 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
0.2.4 (08/04/2021)
- Update README.md and docs
0.2.3 (08/04/2021)
- Mark methods as internal
- Update dependencies and readme
0.2.2 (08/04/2021)
- Roll back module name
- Update badges in README.md
0.2.1 (08/04/2021)
- Update docs
- Change module name
- Fix broken references
- Bump version
0.2.0 (08/04/2021)
- Onboard to pypi
0.1.9 (08/04/2021)
- auto upload to pypi when tagged a release version
0.1.8 (08/04/2021)
- auto gen docs
0.1.7 (07/18/2021)
- Add hyperlinks to docstrings
0.1.6 (07/18/2021)
- Onboard sphinx documentation generator
- Split
memoryandCPUstress into individual files - Add LICENSE
- Update README.md
0.1.5 (07/18/2021)
- Onboard sphinx documentation generator
- Split
memoryandCPUstress into individual files - Add LICENSE
- Update README.md
0.1.4 (07/17/2021)
- add LICENSE
0.1.3 (04/05/2021)
- show each core's max utilization and handle manual interrupts
0.1.2 (04/05/2021)
- update README.md
0.1.1 (02/20/2021)
- add CPU stress injector using multiprocessing and multithreading
- update README.md
- add requirements.txt
- update .gitignore
0.1.0 (10/19/2020)
- get user input for stress limit
0.0.9 (10/08/2020)
- add windows support for stress injector
0.0.8 (10/08/2020)
- use tqdm to add a progress bar
0.0.7 (10/07/2020)
- maintain coding standards
0.0.6 (10/07/2020)
- update README.md
0.0.5 (10/07/2020)
- convert to human readable format
0.0.4 (10/07/2020)
- get memory consumption in bytes
0.0.3 (10/07/2020)
- basic script to induce stress
0.0.2 (10/07/2020)
- initial commit
0.0.1 (10/07/2020)
- Initial commit
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stress-injector-0.0.7.tar.gz.
File metadata
- Download URL: stress-injector-0.0.7.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bad981f730bcbad1c8a4237d8157b2771a2445bb7219892a6b5fc449c9c04893
|
|
| MD5 |
57ce6160fc3a223f918d5eb8bbaf39d7
|
|
| BLAKE2b-256 |
45ebc906ae10822318359a0736a51bf9dba5d71cabf30331aca483e0d71aae98
|
File details
Details for the file stress_injector-0.0.7-py2.py3-none-any.whl.
File metadata
- Download URL: stress_injector-0.0.7-py2.py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7accb768f50fc2f87a020f6135ed5539abb3c04f59c3966691b1187eb8648e5
|
|
| MD5 |
15af229e15530a3e3c05767e54000cf5
|
|
| BLAKE2b-256 |
ae9d3f3feca91a1aee5ba541010547ca5fb131f67e14461323fbcb727d330756
|