stress-tool 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,39 @@
1
+ # This workflow will upload a Python Package using Twine when a release is created
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3
+
4
+ # This workflow uses actions that are not certified by GitHub.
5
+ # They are provided by a third-party and are governed by
6
+ # separate terms of service, privacy policy, and support
7
+ # documentation.
8
+
9
+ name: Upload Python Package
10
+
11
+ on:
12
+ release:
13
+ types: [published]
14
+
15
+ permissions:
16
+ contents: read
17
+
18
+ jobs:
19
+ deploy:
20
+
21
+ runs-on: ubuntu-latest
22
+
23
+ steps:
24
+ - uses: actions/checkout@v4
25
+ - name: Set up Python
26
+ uses: actions/setup-python@v3
27
+ with:
28
+ python-version: '3.x'
29
+ - name: Install dependencies
30
+ run: |
31
+ python -m pip install --upgrade pip
32
+ pip install build
33
+ - name: Build package
34
+ run: python -m build
35
+ - name: Publish package
36
+ uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
37
+ with:
38
+ user: __token__
39
+ password: ${{ secrets.PYPI_API_TOKEN }}
@@ -0,0 +1,162 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
110
+ .pdm.toml
111
+ .pdm-python
112
+ .pdm-build/
113
+
114
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
115
+ __pypackages__/
116
+
117
+ # Celery stuff
118
+ celerybeat-schedule
119
+ celerybeat.pid
120
+
121
+ # SageMath parsed files
122
+ *.sage.py
123
+
124
+ # Environments
125
+ .env
126
+ .venv
127
+ env/
128
+ venv/
129
+ ENV/
130
+ env.bak/
131
+ venv.bak/
132
+
133
+ # Spyder project settings
134
+ .spyderproject
135
+ .spyproject
136
+
137
+ # Rope project settings
138
+ .ropeproject
139
+
140
+ # mkdocs documentation
141
+ /site
142
+
143
+ # mypy
144
+ .mypy_cache/
145
+ .dmypy.json
146
+ dmypy.json
147
+
148
+ # Pyre type checker
149
+ .pyre/
150
+
151
+ # pytype static type analyzer
152
+ .pytype/
153
+
154
+ # Cython debug symbols
155
+ cython_debug/
156
+
157
+ # PyCharm
158
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
159
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
160
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
161
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
162
+ #.idea/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Nick Tsai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,18 @@
1
+ Metadata-Version: 2.3
2
+ Name: stress_tool
3
+ Version: 1.0.0
4
+ Summary: Stress test tool with statistical TPS reports based on Worker Dispatcher in Python
5
+ Project-URL: Homepage, https://github.com/yidas/python-stress-tool
6
+ Project-URL: Issues, https://github.com/yidas/python-stress-tool/issues
7
+ Author-email: Nick Tsai <myintaer@gmail.com>
8
+ License-File: LICENSE
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.0
13
+ Requires-Dist: openpyxl>=3.0.0
14
+ Requires-Dist: worker-dispatcher>=1.0.6
15
+ Description-Content-Type: text/markdown
16
+
17
+ # python-stress-test
18
+ Developing
@@ -0,0 +1,2 @@
1
+ # python-stress-test
2
+ Developing
@@ -0,0 +1,26 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "stress_tool"
7
+ version = "1.0.0"
8
+ authors = [
9
+ { name="Nick Tsai", email="myintaer@gmail.com" },
10
+ ]
11
+ description = "Stress test tool with statistical TPS reports based on Worker Dispatcher in Python"
12
+ readme = "README.md"
13
+ requires-python = ">=3.0"
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Operating System :: OS Independent",
18
+ ]
19
+ dependencies = [
20
+ "worker-dispatcher>=1.0.6",
21
+ "openpyxl>=3.0.0",
22
+ ]
23
+
24
+ [project.urls]
25
+ Homepage = "https://github.com/yidas/python-stress-tool"
26
+ Issues = "https://github.com/yidas/python-stress-tool/issues"
@@ -0,0 +1 @@
1
+ from .stress_tool import *
@@ -0,0 +1,152 @@
1
+ import worker_dispatcher as lib_worker_dispatcher
2
+ import time, datetime, copy
3
+ import openpyxl
4
+
5
+ default_config = {
6
+ 'raw_logs': {
7
+ 'fields': {}
8
+ },
9
+ }
10
+
11
+ def start(config: dict, worker_dispatcher: object=None):
12
+ worker_dispatcher = lib_worker_dispatcher if worker_dispatcher is None else worker_dispatcher
13
+ return worker_dispatcher.start(config)
14
+
15
+ def generate_report(config: dict={}, worker_dispatcher: object=None, file_path: str='./tps-report.xlsx'):
16
+
17
+ config =_merge_dicts_recursive(default_config, config)
18
+
19
+ worker_dispatcher = lib_worker_dispatcher if worker_dispatcher is None else worker_dispatcher
20
+
21
+ # TPS calculation
22
+ tps_data = worker_dispatcher.get_tps(interval=1, display_intervals=True)
23
+ wd_config = worker_dispatcher.get_last_config()
24
+
25
+ # Create a new Workbook
26
+ workbook = openpyxl.Workbook()
27
+
28
+ # Sheet for TPS Report
29
+ sheet = workbook.active
30
+ sheet.title = "Report"
31
+ # Taipei timezone
32
+ datetime_gmt = datetime.timezone(datetime.timedelta(hours=time.localtime().tm_gmtoff / 3600))
33
+ # Each row data
34
+ rows_data = []
35
+ rows_data.append([])
36
+ rows_data.append(["TPS", tps_data['tps']])
37
+ rows_data.append(["Started at", datetime.datetime.fromtimestamp(tps_data['started_at'], datetime_gmt).isoformat()])
38
+ rows_data.append(["Ended at", datetime.datetime.fromtimestamp(tps_data['ended_at'], datetime_gmt).isoformat()])
39
+ rows_data.append(["Total Duration", "{:.6f} sec".format(tps_data['duration'])])
40
+ rows_data.append(["Number of Requests", tps_data['count']['total']])
41
+ if wd_config['worker'].get('per_second'):
42
+ rows_data.append(["Concurrency per second", int(wd_config['worker']['number'] / wd_config['worker']['per_second'])])
43
+ else:
44
+ rows_data.append(["Concurrency", wd_config['worker']['number']])
45
+ rows_data.append(["Number of Successes", tps_data['count']['success']])
46
+ rows_data.append(["Success Rate", "{:.2f}%".format(tps_data['count']['success'] / tps_data['count']['total'] * 100 if tps_data['count']['total'] > 0 else 0)])
47
+ rows_data.append(["Metrices:"])
48
+ rows_data.append(["Average Execution Time", "{:.6f} sec".format(tps_data['metrics']['execution_time']['avg'])])
49
+ rows_data.append(["Maximum Execution Time", "{:.6f} sec".format(tps_data['metrics']['execution_time']['max'])])
50
+ rows_data.append(["Minimum Execution Time", "{:.6f} sec".format(tps_data['metrics']['execution_time']['min'])])
51
+ rows_data.append(["Success Average Execution Time", "{:.6f} sec".format(tps_data['metrics']['success_execution_time']['avg'])])
52
+ rows_data.append(["Success Maximum Execution Time", "{:.6f} sec".format(tps_data['metrics']['success_execution_time']['max'])])
53
+ rows_data.append(["Success Minimum Execution Time", "{:.6f} sec".format(tps_data['metrics']['success_execution_time']['min'])])
54
+ # Peak TPS
55
+ if tps_data['peak']:
56
+ rows_data.append([])
57
+ rows_data.append(["Peak TPS", tps_data['peak']['tps']])
58
+ rows_data.append(["Peak Started at", datetime.datetime.fromtimestamp(round(tps_data['peak']['started_at'], 3), datetime_gmt).isoformat()])
59
+ rows_data.append(["Peak Ended at", datetime.datetime.fromtimestamp(round(tps_data['peak']['ended_at'], 3), datetime_gmt).isoformat()])
60
+ rows_data.append(["Peak Duration", "{:.6f} sec".format(tps_data['peak']['duration'])])
61
+ rows_data.append(["Peak Number of Requests", tps_data['peak']['count']['total']])
62
+ rows_data.append(["Peak Number of Successes", tps_data['peak']['count']['success']])
63
+ rows_data.append(["Peak Success Rate", "{:.2f}%".format(tps_data['peak']['count']['success'] / tps_data['peak']['count']['total'] * 100)])
64
+ rows_data.append(["Peak Metrices:"])
65
+ rows_data.append(["Average Execution Time", "{:.6f} sec".format(tps_data['peak']['metrics']['execution_time']['avg'])])
66
+ rows_data.append(["Maximum Execution Time", "{:.6f} sec".format(tps_data['peak']['metrics']['execution_time']['max'])])
67
+ rows_data.append(["Minimum Execution Time", "{:.6f} sec".format(tps_data['peak']['metrics']['execution_time']['min'])])
68
+ rows_data.append(["Success Average Execution Time", "{:.6f} sec".format(tps_data['peak']['metrics']['success_execution_time']['avg'])])
69
+ rows_data.append(["Success Maximum Execution Time", "{:.6f} sec".format(tps_data['peak']['metrics']['success_execution_time']['max'])])
70
+ rows_data.append(["Success Minimum Execution Time", "{:.6f} sec".format(tps_data['peak']['metrics']['success_execution_time']['min'])])
71
+ rows_data.append([])
72
+ rows_data.append(["Raw Report", str(tps_data)])
73
+ for row in rows_data:
74
+ sheet.append(row)
75
+ # writer.writerows(rows_data)
76
+ # csv_file.close()
77
+
78
+ # Sheet for Raw Logs
79
+ sheet = workbook.create_sheet(title="Raw Logs")
80
+ # header
81
+ header_row = ["Task ID", "Started at", "Ended at", "Duration (sec)"]
82
+ # Customized Fields
83
+ customized_fields = config['raw_logs']['fields']
84
+ for key, value in customized_fields.items():
85
+ header_row.append(key)
86
+ sheet.append(header_row)
87
+
88
+ # Each row
89
+ for log in worker_dispatcher.get_logs():
90
+ row_data = [log['task_id'], str(log['started_at']), str(log['ended_at']), log['ended_at'] - log['started_at']]
91
+ # Customized Fields
92
+ user_log = log.get('log', {})
93
+ for key, value in customized_fields.items():
94
+ if callable(value):
95
+ try:
96
+ row_data.append(value(user_log))
97
+ except Exception as e:
98
+ # exit(e)
99
+ pass
100
+ else:
101
+ row_data.append(str(user_log.get(value, '')))
102
+ sheet.append(row_data)
103
+
104
+ # Sheet for Interval
105
+ if tps_data['intervals']:
106
+ sheet = workbook.create_sheet(title="Intervals")
107
+ # header
108
+ sheet.append([
109
+ "TPS",
110
+ "Started at",
111
+ "Ended at",
112
+ "Duration (sec)",
113
+ "Success",
114
+ "Total (Done)",
115
+ "Request",
116
+ "Response",
117
+ "Average Execution Time",
118
+ "Success Average Execution Time"
119
+ ])
120
+ for row in tps_data['intervals']:
121
+ row_data = [
122
+ row['tps'],
123
+ str(row['started_at']),
124
+ str(row['ended_at']),
125
+ row['duration'],
126
+ row['count']['success'],
127
+ row['count']['total'],
128
+ row['count']['start'],
129
+ row['count']['end'],
130
+ row['metrics']['execution_time']['avg'],
131
+ row['metrics']['success_execution_time']['avg']
132
+ ]
133
+ # exit(row_data)
134
+ sheet.append(row_data)
135
+
136
+ # Save workbook
137
+ workbook.save(file_path)
138
+
139
+ return file_path
140
+
141
+ def _merge_dicts_recursive(default_dict, user_dict):
142
+ merged_dict = copy.deepcopy(default_dict)
143
+ for key, user_value in user_dict.items():
144
+ if key in merged_dict:
145
+ if isinstance(merged_dict[key], dict) and isinstance(user_value, dict):
146
+ merged_dict[key] = _merge_dicts_recursive(merged_dict[key], user_value)
147
+ else:
148
+ merged_dict[key] = user_value
149
+ else:
150
+ merged_dict[key] = user_value
151
+
152
+ return merged_dict