stress-injector


Namestress-injector JSON
Version 0.9 PyPI version JSON
download
home_page
SummaryPython module, to inject memory and CPU stress, and URL load test
upload_time2023-08-31 03:32:49
maintainer
docs_urlNone
author
requires_python>=3.8
licenseMIT License Copyright (c) 2021 Vignesh Sivanandha Rao Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords stress-test numpy-arrays cpu-stress memory-stress url-stress multiprocessing multithreading
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Pypi-version](https://img.shields.io/pypi/v/stress-injector)](https://pypi.org/project/stress-injector)
[![Pypi-py-version](https://img.shields.io/pypi/pyversions/stress-injector)](https://pypi.org/project/stress-injector)

[![pages-build-deployment](https://github.com/thevickypedia/stress-injector/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/thevickypedia/stress-injector/actions/workflows/pages/pages-build-deployment)
[![pypi-publish](https://github.com/thevickypedia/stress-injector/actions/workflows/python-publish.yml/badge.svg)](https://github.com/thevickypedia/stress-injector/actions/workflows/python-publish.yml)

[![Pypi-format](https://img.shields.io/pypi/format/stress-injector)](https://pypi.org/project/stress-injector/#files)
[![Pypi-status](https://img.shields.io/pypi/status/stress-injector)](https://pypi.org/project/stress-injector)

![Maintained](https://img.shields.io/maintenance/yes/2023)
[![GitHub Repo created](https://img.shields.io/date/1599432310)](https://api.github.com/repos/thevickypedia/stress-injector)
[![GitHub commit activity](https://img.shields.io/github/commit-activity/y/thevickypedia/stress-injector)](https://api.github.com/repos/thevickypedia/stress-injector)
[![GitHub last commit](https://img.shields.io/github/last-commit/thevickypedia/stress-injector)](https://api.github.com/repos/thevickypedia/stress-injector)

# Stress Injector
Python module, to inject memory, CPU and URL stress.

<details>
<summary><strong>Insights about <a href="https://github.com/thevickypedia/stress-injector/blob/main/stressinjector/cpu.py">CPU Stress</a></strong></summary>

* 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 the user)
* Mean-while the `cpu_percent` from `psutil` runs (in a 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 `processes` and `threads` initiated to monitor CPU usage are stopped.
</details>
<br>
<details>
<summary><strong>Insights about <a href="https://github.com/thevickypedia/stress-injector/blob/main/stressinjector/memory.py">Memory Stress</a></strong></summary>

* In this script, I have used `numpy.random.bytes` which are sampled from uniform distribution.
* These random bytes are collected from the machine's physical memory increasing the program's 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.
</details>
<br>
<details>
<summary><strong>Insights about <a href="https://github.com/thevickypedia/stress-injector/blob/main/stressinjector/onus.py">URL Stress</a></strong></summary>

* In this script, I have used threadpools to make concurrent requests.
* The script uses `requests` module to make 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_
  * **request_type**: Function from `requests` module.

</details>

### Usage
`pip install stress-injector`

[CPU Stress](https://github.com/thevickypedia/stress-injector/blob/main/stressinjector/cpu.py)
```python
import stressinjector as injector


if __name__ == '__main__':
    injector.CPUStress(seconds=300)
```

[Memory Stress](https://github.com/thevickypedia/stress-injector/blob/main/stressinjector/memory.py)
```python
import stressinjector as injector


if __name__ == '__main__':
    injector.MemoryStress(gigabytes=2_000)
```

[URL Stress](https://github.com/thevickypedia/stress-injector/blob/main/stressinjector/url.py)
```python
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](https://locust.io/)

#### Coding Standards
Docstring format: [`Google`](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) <br>
Styling conventions: [`PEP 8`](https://www.python.org/dev/peps/pep-0008/) <br>
Clean code with pre-commit hooks: [`flake8`](https://flake8.pycqa.org/en/latest/) and 
[`isort`](https://pycqa.github.io/isort/)

#### [Release Notes](https://github.com/thevickypedia/stress-injector/blob/main/release_notes.rst)
**Requirement**
```shell
python -m pip install gitverse
```

**Usage**
```shell
gitverse-release reverse -f release_notes.rst -t 'Release Notes'
```

#### Linting
`PreCommit` will ensure linting, and the doc creation are run on every commit.

**Requirement**
<br>
```bash
pip install --no-cache sphinx==5.1.1 pre-commit recommonmark
```

**Usage**
<br>
```bash
pre-commit run --all-files
```

### Pypi Package
[![pypi-module](https://img.shields.io/badge/Software%20Repository-pypi-1f425f.svg)](https://packaging.python.org/tutorials/packaging-projects/)

[https://pypi.org/project/stress-injector/](https://pypi.org/project/stress-injector/)

### Runbook
[![made-with-sphinx-doc](https://img.shields.io/badge/Code%20Docs-Sphinx-1f425f.svg)](https://www.sphinx-doc.org/en/master/man/sphinx-autogen.html)

[https://thevickypedia.github.io/stress-injector/](https://thevickypedia.github.io/stress-injector/)

## License & copyright

&copy; Vignesh Sivanandha Rao

Licensed under the [MIT License](https://github.com/thevickypedia/stress-injector/blob/main/LICENSE)

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "stress-injector",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "stress-test,numpy-arrays,cpu-stress,memory-stress,url-stress,multiprocessing,multithreading",
    "author": "",
    "author_email": "Vignesh Sivanandha Rao <svignesh1793@gmail.com>",
    "download_url": "",
    "platform": null,
    "description": "[![Pypi-version](https://img.shields.io/pypi/v/stress-injector)](https://pypi.org/project/stress-injector)\n[![Pypi-py-version](https://img.shields.io/pypi/pyversions/stress-injector)](https://pypi.org/project/stress-injector)\n\n[![pages-build-deployment](https://github.com/thevickypedia/stress-injector/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/thevickypedia/stress-injector/actions/workflows/pages/pages-build-deployment)\n[![pypi-publish](https://github.com/thevickypedia/stress-injector/actions/workflows/python-publish.yml/badge.svg)](https://github.com/thevickypedia/stress-injector/actions/workflows/python-publish.yml)\n\n[![Pypi-format](https://img.shields.io/pypi/format/stress-injector)](https://pypi.org/project/stress-injector/#files)\n[![Pypi-status](https://img.shields.io/pypi/status/stress-injector)](https://pypi.org/project/stress-injector)\n\n![Maintained](https://img.shields.io/maintenance/yes/2023)\n[![GitHub Repo created](https://img.shields.io/date/1599432310)](https://api.github.com/repos/thevickypedia/stress-injector)\n[![GitHub commit activity](https://img.shields.io/github/commit-activity/y/thevickypedia/stress-injector)](https://api.github.com/repos/thevickypedia/stress-injector)\n[![GitHub last commit](https://img.shields.io/github/last-commit/thevickypedia/stress-injector)](https://api.github.com/repos/thevickypedia/stress-injector)\n\n# Stress Injector\nPython module, to inject memory, CPU and URL stress.\n\n<details>\n<summary><strong>Insights about <a href=\"https://github.com/thevickypedia/stress-injector/blob/main/stressinjector/cpu.py\">CPU Stress</a></strong></summary>\n\n* To achieve CPU stress, I have used multiprocess, looped for the number of logical cores, triggering an infinite loop on\n  each core.\n* The infinite loop will run for a given number of seconds (provided by the user)\n* Mean-while the `cpu_percent` from `psutil` runs (in a dedicated thread) in an infinite loop calculating the current CPU \n  utilization on each CPU core.\n* The dedicated thread runs for 3 seconds in addition to the number of seconds provided by the user.\n* Once the given number of seconds have passed, the `processes` and `threads` initiated to monitor CPU usage are stopped.\n</details>\n<br>\n<details>\n<summary><strong>Insights about <a href=\"https://github.com/thevickypedia/stress-injector/blob/main/stressinjector/memory.py\">Memory Stress</a></strong></summary>\n\n* In this script, I have used `numpy.random.bytes` which are sampled from uniform distribution.\n* These random bytes are collected from the machine's physical memory increasing the program's usage.\n* I have then used `getrusage` (get resource usage) for `SELF` to get the memory consumed only by the current script.\n* The `size_converter` converts the bytes from resource usage to a human understandable format.\n</details>\n<br>\n<details>\n<summary><strong>Insights about <a href=\"https://github.com/thevickypedia/stress-injector/blob/main/stressinjector/onus.py\">URL Stress</a></strong></summary>\n\n* In this script, I have used threadpools to make concurrent requests.\n* The script uses `requests` module to make calls.\n* Takes arguments\n  * **rate**: Number of calls to make. _Defaults to 100K_\n  * **timeout**: Timeout for each request. _Defaults to 0.5_\n  * **retry_limit**: Retry limit if the system is unable to spinup more threads. _Defaults to 5_\n  * **circuit_break**: Wait time in seconds between retries. _Defaults to 5_\n  * **request_type**: Function from `requests` module.\n\n</details>\n\n### Usage\n`pip install stress-injector`\n\n[CPU Stress](https://github.com/thevickypedia/stress-injector/blob/main/stressinjector/cpu.py)\n```python\nimport stressinjector as injector\n\n\nif __name__ == '__main__':\n    injector.CPUStress(seconds=300)\n```\n\n[Memory Stress](https://github.com/thevickypedia/stress-injector/blob/main/stressinjector/memory.py)\n```python\nimport stressinjector as injector\n\n\nif __name__ == '__main__':\n    injector.MemoryStress(gigabytes=2_000)\n```\n\n[URL Stress](https://github.com/thevickypedia/stress-injector/blob/main/stressinjector/url.py)\n```python\nimport os\nimport stressinjector as injector\n\n\nif __name__ == '__main__':\n    injector.URLStress(url='http://0.0.0.0:5002/')  # Stress test GET calls\n\n    # Stress test POST calls, also supports PUT, and DELETE\n    sample_data = {'headers': {'Authorization': 'Bearer %s' % os.environ.get('TOKEN')}}\n    injector.URLStress(\n      url='http://0.0.0.0:5002/',\n      request_type=injector.RequestType.post,\n      **sample_data\n    )\n```\n> This module can only induce stress on a given URL by making N number of calls. Suitable for APIs running on localhost.\n> \n> To perform a real-time load test, refer [locust.io](https://locust.io/)\n\n#### Coding Standards\nDocstring format: [`Google`](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) <br>\nStyling conventions: [`PEP 8`](https://www.python.org/dev/peps/pep-0008/) <br>\nClean code with pre-commit hooks: [`flake8`](https://flake8.pycqa.org/en/latest/) and \n[`isort`](https://pycqa.github.io/isort/)\n\n#### [Release Notes](https://github.com/thevickypedia/stress-injector/blob/main/release_notes.rst)\n**Requirement**\n```shell\npython -m pip install gitverse\n```\n\n**Usage**\n```shell\ngitverse-release reverse -f release_notes.rst -t 'Release Notes'\n```\n\n#### Linting\n`PreCommit` will ensure linting, and the doc creation are run on every commit.\n\n**Requirement**\n<br>\n```bash\npip install --no-cache sphinx==5.1.1 pre-commit recommonmark\n```\n\n**Usage**\n<br>\n```bash\npre-commit run --all-files\n```\n\n### Pypi Package\n[![pypi-module](https://img.shields.io/badge/Software%20Repository-pypi-1f425f.svg)](https://packaging.python.org/tutorials/packaging-projects/)\n\n[https://pypi.org/project/stress-injector/](https://pypi.org/project/stress-injector/)\n\n### Runbook\n[![made-with-sphinx-doc](https://img.shields.io/badge/Code%20Docs-Sphinx-1f425f.svg)](https://www.sphinx-doc.org/en/master/man/sphinx-autogen.html)\n\n[https://thevickypedia.github.io/stress-injector/](https://thevickypedia.github.io/stress-injector/)\n\n## License & copyright\n\n&copy; Vignesh Sivanandha Rao\n\nLicensed under the [MIT License](https://github.com/thevickypedia/stress-injector/blob/main/LICENSE)\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2021 Vignesh Sivanandha Rao  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Python module, to inject memory and CPU stress, and URL load test",
    "version": "0.9",
    "project_urls": {
        "Bug Tracker": "https://github.com/thevickypedia/stress-injector/issues",
        "Docs": "https://thevickypedia.github.io/stress-injector/",
        "Homepage": "https://github.com/thevickypedia/stress-injector",
        "Release Notes": "https://github.com/thevickypedia/stress-injector/blob/main/release_notes.rst",
        "Source": "https://github.com/thevickypedia/stress-injector"
    },
    "split_keywords": [
        "stress-test",
        "numpy-arrays",
        "cpu-stress",
        "memory-stress",
        "url-stress",
        "multiprocessing",
        "multithreading"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "141f3be120b004f4169b38e23823231263b1f5d19afb9bf5e91694703b811e3e",
                "md5": "84d57ff8209a041627cde2afbee7ee18",
                "sha256": "fc0200a153362cde6ef2b8e68d71290c491275c5478b078f8b8eb28dfd8f13b2"
            },
            "downloads": -1,
            "filename": "stress_injector-0.9-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "84d57ff8209a041627cde2afbee7ee18",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 12725,
            "upload_time": "2023-08-31T03:32:49",
            "upload_time_iso_8601": "2023-08-31T03:32:49.592250Z",
            "url": "https://files.pythonhosted.org/packages/14/1f/3be120b004f4169b38e23823231263b1f5d19afb9bf5e91694703b811e3e/stress_injector-0.9-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-31 03:32:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "thevickypedia",
    "github_project": "stress-injector",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "stress-injector"
}
        
Elapsed time: 0.17869s