{"id":16135643,"url":"https://github.com/thevickypedia/stress-injector","last_synced_at":"2025-03-18T15:31:33.510Z","repository":{"id":57471813,"uuid":"302229663","full_name":"thevickypedia/stress-injector","owner":"thevickypedia","description":"Python script, to inject memory, CPU and URL stress","archived":false,"fork":false,"pushed_at":"2024-05-18T05:46:20.000Z","size":398,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-02-28T10:35:58.607Z","etag":null,"topics":["cpu-stress","memory-management","memory-stress","multiprocessing","numpy-arrays","stress-test"],"latest_commit_sha":null,"homepage":"https://thevickypedia.github.io/stress_injector/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thevickypedia.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-08T04:17:37.000Z","updated_at":"2024-05-18T05:46:23.000Z","dependencies_parsed_at":"2024-05-18T06:30:35.944Z","dependency_job_id":"58405a93-87f8-464b-9f9b-b3703721e491","html_url":"https://github.com/thevickypedia/stress-injector","commit_stats":{"total_commits":42,"total_committers":3,"mean_commits":14.0,"dds":0.04761904761904767,"last_synced_commit":"873e2fa668c1c353006616fc5af16ac184c7b4f9"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thevickypedia%2Fstress-injector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thevickypedia%2Fstress-injector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thevickypedia%2Fstress-injector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thevickypedia%2Fstress-injector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thevickypedia","download_url":"https://codeload.github.com/thevickypedia/stress-injector/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243936385,"owners_count":20371505,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpu-stress","memory-management","memory-stress","multiprocessing","numpy-arrays","stress-test"],"created_at":"2024-10-09T23:08:49.794Z","updated_at":"2025-03-18T15:31:32.985Z","avatar_url":"https://github.com/thevickypedia.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![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\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eInsights about \u003ca href=\"https://github.com/thevickypedia/stress-injector/blob/main/stressinjector/cpu.py\"\u003eCPU Stress\u003c/a\u003e\u003c/strong\u003e\u003c/summary\u003e\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\u003c/details\u003e\n\u003cbr\u003e\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eInsights about \u003ca href=\"https://github.com/thevickypedia/stress-injector/blob/main/stressinjector/memory.py\"\u003eMemory Stress\u003c/a\u003e\u003c/strong\u003e\u003c/summary\u003e\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\u003c/details\u003e\n\u003cbr\u003e\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eInsights about \u003ca href=\"https://github.com/thevickypedia/stress-injector/blob/main/stressinjector/onus.py\"\u003eURL Stress\u003c/a\u003e\u003c/strong\u003e\u003c/summary\u003e\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\u003c/details\u003e\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\u003e This module can only induce stress on a given URL by making N number of calls. Suitable for APIs running on localhost.\n\u003e \n\u003e 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) \u003cbr\u003e\nStyling conventions: [`PEP 8`](https://www.python.org/dev/peps/pep-0008/) \u003cbr\u003e\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\u003cbr\u003e\n```bash\npip install --no-cache sphinx==5.1.1 pre-commit recommonmark\n```\n\n**Usage**\n\u003cbr\u003e\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 \u0026 copyright\n\n\u0026copy; Vignesh Sivanandha Rao\n\nLicensed under the [MIT License](https://github.com/thevickypedia/stress-injector/blob/main/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthevickypedia%2Fstress-injector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthevickypedia%2Fstress-injector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthevickypedia%2Fstress-injector/lists"}