Python script, to inject memory, CPU and URL stress
MIT License
Python module, to inject memory, CPU and URL stress.
cpu_percent
from psutil
runs (in a dedicated thread) in an infinite loop calculating the current CPUprocesses
and threads
initiated to monitor CPU usage are stopped.numpy.random.bytes
which are sampled from uniform distribution.getrusage
(get resource usage) for SELF
to get the memory consumed only by the current script.size_converter
converts the bytes from resource usage to a human understandable format.requests
module to make calls.requests
module.pip install stress-injector
import stressinjector as injector
if __name__ == '__main__':
injector.CPUStress(seconds=300)
import stressinjector as injector
if __name__ == '__main__':
injector.MemoryStress(gigabytes=2_000)
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
Docstring format: Google
Styling conventions: PEP 8
Clean code with pre-commit hooks: flake8
and
isort
Requirement
python -m pip install gitverse
Usage
gitverse-release reverse -f release_notes.rst -t 'Release Notes'
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
https://pypi.org/project/stress-injector/
https://thevickypedia.github.io/stress-injector/
© Vignesh Sivanandha Rao
Licensed under the MIT License