ai-ecosystem-benchmark 0.0.1__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,178 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Aerospike, Inc.
@@ -0,0 +1,110 @@
1
+ Metadata-Version: 2.4
2
+ Name: ai-ecosystem-benchmark
3
+ Version: 0.0.1
4
+ Summary: Framework for benchmarking AI ecosystem tools against database backends
5
+ Author-email: "Aerospike, Inc." <info@aerospike.com>
6
+ License-Expression: Apache-2.0
7
+ Keywords: ai,benchmark,database,aerospike,postgres,redis
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Dynamic: license-file
18
+
19
+ # AI Ecosystem Benchmark
20
+
21
+ Generalized framework for benchmarking AI tools that depend on database backends.
22
+
23
+ ## Python Package
24
+
25
+ This repository is also a Python package named `ai-ecosystem-benchmark`. The
26
+ package is intentionally minimal for now while the benchmark framework takes
27
+ shape.
28
+
29
+ Install and sync the development environment with [`uv`](https://docs.astral.sh/uv/):
30
+
31
+ ```bash
32
+ uv sync
33
+ ```
34
+
35
+ Run the local checks:
36
+
37
+ ```bash
38
+ uv run pytest
39
+ uv run ruff check .
40
+ uv run ruff format --check .
41
+ uv run mypy
42
+ uv run deptry .
43
+ ```
44
+
45
+ Install pre-commit hooks once per checkout:
46
+
47
+ ```bash
48
+ uv run pre-commit install
49
+ ```
50
+
51
+ ## Implementing a Workload
52
+
53
+ Benchmark workloads should subclass `BaseBenchmarkWorkload` and implement the
54
+ required lifecycle hooks:
55
+
56
+ - `setup()`: prepare clients, data, or other state before benchmarks run.
57
+ - `between_benchmarks()`: reset or pause between benchmark executions.
58
+ - `teardown()`: clean up resources after benchmarks finish.
59
+
60
+ Connection strings are optional. If a connection string is omitted, that backend
61
+ is assumed to be disabled for the benchmark run.
62
+
63
+ Backend-specific benchmark methods are discovered by name:
64
+
65
+ - Aerospike methods start with `aerospike`
66
+ - Postgres methods start with `postgres`
67
+ - Redis methods start with `redis`
68
+
69
+ ```python
70
+ from ai_ecosystem_benchmark import BaseBenchmarkWorkload
71
+
72
+
73
+ class MyWorkload(BaseBenchmarkWorkload):
74
+ def __init__(
75
+ self,
76
+ aerospike_connection_string: str | None = None,
77
+ postgres_connection_string: str | None = None,
78
+ redis_connection_string: str | None = None,
79
+ ) -> None:
80
+ super().__init__(
81
+ aerospike_connection_string=aerospike_connection_string,
82
+ postgres_connection_string=postgres_connection_string,
83
+ redis_connection_string=redis_connection_string,
84
+ )
85
+
86
+ def setup(self) -> None:
87
+ return None
88
+
89
+ def between_benchmarks(self) -> None:
90
+ return None
91
+
92
+ def teardown(self) -> None:
93
+ return None
94
+
95
+ def aerospike_test_insert(self) -> None:
96
+ ...
97
+
98
+ def redis_test_lookup(self) -> None:
99
+ ...
100
+ ```
101
+
102
+ ## Infrastructure
103
+
104
+ The first infrastructure target is a GCP Compute Terraform stack that can provision any combination of Redis, Postgres, and Aerospike benchmark clusters. The GitHub Actions workflow in `.github/workflows/terraform.yml` runs Terraform manually through `workflow_dispatch` and prints non-sensitive endpoint details after apply.
105
+
106
+ See `infra/terraform/gcp-compute/README.md` for setup details.
107
+
108
+ ## License
109
+
110
+ This project is licensed under the Apache License 2.0. See `LICENSE` for details.
@@ -0,0 +1,92 @@
1
+ # AI Ecosystem Benchmark
2
+
3
+ Generalized framework for benchmarking AI tools that depend on database backends.
4
+
5
+ ## Python Package
6
+
7
+ This repository is also a Python package named `ai-ecosystem-benchmark`. The
8
+ package is intentionally minimal for now while the benchmark framework takes
9
+ shape.
10
+
11
+ Install and sync the development environment with [`uv`](https://docs.astral.sh/uv/):
12
+
13
+ ```bash
14
+ uv sync
15
+ ```
16
+
17
+ Run the local checks:
18
+
19
+ ```bash
20
+ uv run pytest
21
+ uv run ruff check .
22
+ uv run ruff format --check .
23
+ uv run mypy
24
+ uv run deptry .
25
+ ```
26
+
27
+ Install pre-commit hooks once per checkout:
28
+
29
+ ```bash
30
+ uv run pre-commit install
31
+ ```
32
+
33
+ ## Implementing a Workload
34
+
35
+ Benchmark workloads should subclass `BaseBenchmarkWorkload` and implement the
36
+ required lifecycle hooks:
37
+
38
+ - `setup()`: prepare clients, data, or other state before benchmarks run.
39
+ - `between_benchmarks()`: reset or pause between benchmark executions.
40
+ - `teardown()`: clean up resources after benchmarks finish.
41
+
42
+ Connection strings are optional. If a connection string is omitted, that backend
43
+ is assumed to be disabled for the benchmark run.
44
+
45
+ Backend-specific benchmark methods are discovered by name:
46
+
47
+ - Aerospike methods start with `aerospike`
48
+ - Postgres methods start with `postgres`
49
+ - Redis methods start with `redis`
50
+
51
+ ```python
52
+ from ai_ecosystem_benchmark import BaseBenchmarkWorkload
53
+
54
+
55
+ class MyWorkload(BaseBenchmarkWorkload):
56
+ def __init__(
57
+ self,
58
+ aerospike_connection_string: str | None = None,
59
+ postgres_connection_string: str | None = None,
60
+ redis_connection_string: str | None = None,
61
+ ) -> None:
62
+ super().__init__(
63
+ aerospike_connection_string=aerospike_connection_string,
64
+ postgres_connection_string=postgres_connection_string,
65
+ redis_connection_string=redis_connection_string,
66
+ )
67
+
68
+ def setup(self) -> None:
69
+ return None
70
+
71
+ def between_benchmarks(self) -> None:
72
+ return None
73
+
74
+ def teardown(self) -> None:
75
+ return None
76
+
77
+ def aerospike_test_insert(self) -> None:
78
+ ...
79
+
80
+ def redis_test_lookup(self) -> None:
81
+ ...
82
+ ```
83
+
84
+ ## Infrastructure
85
+
86
+ The first infrastructure target is a GCP Compute Terraform stack that can provision any combination of Redis, Postgres, and Aerospike benchmark clusters. The GitHub Actions workflow in `.github/workflows/terraform.yml` runs Terraform manually through `workflow_dispatch` and prints non-sensitive endpoint details after apply.
87
+
88
+ See `infra/terraform/gcp-compute/README.md` for setup details.
89
+
90
+ ## License
91
+
92
+ This project is licensed under the Apache License 2.0. See `LICENSE` for details.
@@ -0,0 +1,82 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "ai-ecosystem-benchmark"
7
+ version = "0.0.1"
8
+ description = "Framework for benchmarking AI ecosystem tools against database backends"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "Apache-2.0"
12
+ authors = [
13
+ {name = "Aerospike, Inc.", email = "info@aerospike.com"}
14
+ ]
15
+ keywords = ["ai", "benchmark", "database", "aerospike", "postgres", "redis"]
16
+ classifiers = [
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Topic :: Software Development :: Libraries :: Python Modules",
23
+ ]
24
+ dependencies = []
25
+
26
+ [dependency-groups]
27
+ dev = [
28
+ "deptry>=0.25",
29
+ "mypy>=1.20",
30
+ "pre-commit>=4.6",
31
+ "pytest>=8",
32
+ "ruff>=0.15",
33
+ ]
34
+
35
+ [tool.setuptools.packages.find]
36
+ where = ["src"]
37
+ include = ["ai_ecosystem_benchmark*"]
38
+
39
+ [tool.pytest.ini_options]
40
+ testpaths = ["tests"]
41
+
42
+ [tool.deptry]
43
+ known_first_party = ["ai_ecosystem_benchmark"]
44
+
45
+ # Ruff: linter and formatter.
46
+ [tool.ruff]
47
+ target-version = "py310"
48
+ line-length = 100
49
+ extend-exclude = [".venv", "dist", "build"]
50
+
51
+ [tool.ruff.lint]
52
+ select = [
53
+ "E", # pycodestyle errors
54
+ "W", # pycodestyle warnings
55
+ "F", # pyflakes
56
+ "I", # isort
57
+ "UP", # pyupgrade
58
+ "B", # flake8-bugbear
59
+ "SIM", # flake8-simplify
60
+ "C4", # flake8-comprehensions
61
+ "N", # pep8-naming
62
+ ]
63
+ ignore = [
64
+ "E501", # line length, handled by the formatter
65
+ ]
66
+
67
+ [tool.ruff.lint.per-file-ignores]
68
+ "**/tests/**" = ["B011"]
69
+
70
+ # Mypy: static type checker.
71
+ [tool.mypy]
72
+ python_version = "3.10"
73
+ files = [
74
+ "src/ai_ecosystem_benchmark",
75
+ "tests",
76
+ ]
77
+ ignore_missing_imports = true
78
+ check_untyped_defs = true
79
+ warn_redundant_casts = true
80
+ warn_unused_ignores = true
81
+ warn_return_any = true
82
+ warn_unreachable = true
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,6 @@
1
+ """AI ecosystem benchmark package."""
2
+
3
+ from ai_ecosystem_benchmark.base_benchmark_workload import BaseBenchmarkWorkload
4
+ from ai_ecosystem_benchmark.benchmark_runner import BenchmarkRunner
5
+
6
+ __all__ = ["BaseBenchmarkWorkload", "BenchmarkRunner"]
@@ -0,0 +1,98 @@
1
+ """Fixed-size log-linear histogram for nanosecond latency measurements.
2
+
3
+ This module is private to the package: import via the public surface in
4
+ :mod:`ai_ecosystem_benchmark.benchmark_runner` (e.g. via ``runner.metrics``) rather
5
+ than reaching in here directly.
6
+
7
+ Loosely modeled on `HdrHistogram <http://hdrhistogram.org/>`_: linear sub-buckets within
8
+ each power-of-two range of nanoseconds. ``record`` is O(1) and uses constant memory
9
+ regardless of how many values are recorded, which is what we need for long high-qps
10
+ benchmarks where storing every individual latency would explode RAM. ``percentile_ns``
11
+ is O(_COUNTS_LENGTH) but only runs at report time, off the hot path.
12
+
13
+ The maximum relative error of any recorded value compared to the bucket it lands in
14
+ is bounded by ``1 / _SUB_BUCKET_COUNT`` (~0.8% with the current settings).
15
+ """
16
+
17
+ from threading import Lock
18
+
19
+ _SUB_BUCKET_BITS = 7
20
+ _SUB_BUCKET_COUNT = 1 << _SUB_BUCKET_BITS # 128 sub-buckets per power-of-two range
21
+ _SUB_BUCKET_HALF = _SUB_BUCKET_COUNT >> 1 # 64
22
+ # Track values up to 2^_HIGHEST_TRACKABLE_BITS ns. 42 bits is ~73 minutes per call --
23
+ # anything beyond that gets clamped to the last bucket rather than overflowing.
24
+ _HIGHEST_TRACKABLE_BITS = 42
25
+ _BUCKET_COUNT = _HIGHEST_TRACKABLE_BITS - _SUB_BUCKET_BITS + 1
26
+ # Layout: bucket 0 is the linear [0, 128) range (full 128 slots). Each subsequent
27
+ # bucket adds _SUB_BUCKET_HALF (64) new slots, since the lower half of each bucket's
28
+ # nominal range overlaps with the previous bucket and is not re-stored.
29
+ _COUNTS_LENGTH = _SUB_BUCKET_COUNT + (_BUCKET_COUNT - 1) * _SUB_BUCKET_HALF
30
+
31
+
32
+ class LatencyHistogram:
33
+ """Thread-safe log-linear histogram of nanosecond values."""
34
+
35
+ __slots__ = ("_counts", "_count", "_min_ns", "_max_ns", "_lock")
36
+
37
+ def __init__(self) -> None:
38
+ self._counts: list[int] = [0] * _COUNTS_LENGTH
39
+ self._count = 0
40
+ self._min_ns = 0
41
+ self._max_ns = 0
42
+ self._lock = Lock()
43
+
44
+ def record(self, value_ns: int) -> None:
45
+ """Record a single nanosecond value. Negative values are silently dropped."""
46
+ if value_ns < 0:
47
+ return
48
+ index = _counts_index(value_ns)
49
+ with self._lock:
50
+ self._counts[index] += 1
51
+ if self._count == 0 or value_ns < self._min_ns:
52
+ self._min_ns = value_ns
53
+ if value_ns > self._max_ns:
54
+ self._max_ns = value_ns
55
+ self._count += 1
56
+
57
+ def count(self) -> int:
58
+ return self._count
59
+
60
+ def min_ns(self) -> int:
61
+ return self._min_ns
62
+
63
+ def max_ns(self) -> int:
64
+ return self._max_ns
65
+
66
+ def percentile_ns(self, percentile: float) -> int:
67
+ """Return the bucket lower bound for the given percentile in ``[0, 100]``."""
68
+ with self._lock:
69
+ counts_snapshot = self._counts.copy()
70
+ total = self._count
71
+ max_value = self._max_ns
72
+ if total == 0:
73
+ return 0
74
+ target = max(1, min(total, round((percentile / 100.0) * total)))
75
+ cumulative = 0
76
+ for index, count in enumerate(counts_snapshot):
77
+ cumulative += count
78
+ if cumulative >= target:
79
+ return _value_at_index(index)
80
+ return max_value
81
+
82
+
83
+ def _counts_index(value_ns: int) -> int:
84
+ if value_ns < _SUB_BUCKET_COUNT:
85
+ return value_ns
86
+ bucket_index = value_ns.bit_length() - _SUB_BUCKET_BITS
87
+ if bucket_index >= _BUCKET_COUNT:
88
+ return _COUNTS_LENGTH - 1
89
+ sub_bucket_index = value_ns >> bucket_index
90
+ return bucket_index * _SUB_BUCKET_HALF + sub_bucket_index
91
+
92
+
93
+ def _value_at_index(counts_index: int) -> int:
94
+ if counts_index < _SUB_BUCKET_COUNT:
95
+ return counts_index
96
+ bucket_index = (counts_index - _SUB_BUCKET_HALF) // _SUB_BUCKET_HALF
97
+ sub_bucket_index = counts_index - bucket_index * _SUB_BUCKET_HALF
98
+ return sub_bucket_index << bucket_index
@@ -0,0 +1,81 @@
1
+ """Base class for benchmark workloads."""
2
+
3
+ from abc import ABC, abstractmethod
4
+ from collections.abc import Callable
5
+ from inspect import getmembers, ismethod
6
+ from typing import cast, final
7
+
8
+ BenchmarkTest = Callable[[], None]
9
+
10
+
11
+ class BaseBenchmarkWorkload(ABC):
12
+ """Base class for benchmark workloads."""
13
+
14
+ def __init__(
15
+ self,
16
+ aerospike_connection_string: str | None = None,
17
+ postgres_connection_string: str | None = None,
18
+ redis_connection_string: str | None = None,
19
+ ) -> None:
20
+ """Initialize the workload."""
21
+ self.aerospike_connection_string = aerospike_connection_string
22
+ self.postgres_connection_string = postgres_connection_string
23
+ self.redis_connection_string = redis_connection_string
24
+
25
+ @final
26
+ def is_aerospike_enabled(self) -> bool:
27
+ """Return whether Aerospike should be benchmarked."""
28
+ return self.aerospike_connection_string is not None
29
+
30
+ @final
31
+ def is_postgres_enabled(self) -> bool:
32
+ """Return whether Postgres should be benchmarked."""
33
+ return self.postgres_connection_string is not None
34
+
35
+ @final
36
+ def is_redis_enabled(self) -> bool:
37
+ """Return whether Redis should be benchmarked."""
38
+ return self.redis_connection_string is not None
39
+
40
+ @final
41
+ def get_aerospike_tests(self) -> list[BenchmarkTest]:
42
+ """Return Aerospike benchmark methods."""
43
+ if not self.is_aerospike_enabled():
44
+ return []
45
+ return self._get_tests_with_prefix("aerospike")
46
+
47
+ @final
48
+ def get_postgres_tests(self) -> list[BenchmarkTest]:
49
+ """Return Postgres benchmark methods."""
50
+ if not self.is_postgres_enabled():
51
+ return []
52
+ return self._get_tests_with_prefix("postgres")
53
+
54
+ @final
55
+ def get_redis_tests(self) -> list[BenchmarkTest]:
56
+ """Return Redis benchmark methods."""
57
+ if not self.is_redis_enabled():
58
+ return []
59
+ return self._get_tests_with_prefix("redis")
60
+
61
+ @abstractmethod
62
+ def setup(self) -> None:
63
+ """Prepare the workload before benchmark execution."""
64
+ ...
65
+
66
+ @abstractmethod
67
+ def between_benchmarks(self) -> None:
68
+ """Run between benchmark executions."""
69
+ ...
70
+
71
+ @abstractmethod
72
+ def teardown(self) -> None:
73
+ """Clean up the workload after benchmark execution."""
74
+ ...
75
+
76
+ def _get_tests_with_prefix(self, prefix: str) -> list[BenchmarkTest]:
77
+ return [
78
+ cast(BenchmarkTest, method)
79
+ for name, method in getmembers(self, predicate=ismethod)
80
+ if name.startswith(prefix)
81
+ ]