|
| 1 | +# Copyright 2026 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +import itertools |
| 15 | +import os |
| 16 | +from typing import Dict, List |
| 17 | + |
| 18 | +import yaml |
| 19 | + |
| 20 | +try: |
| 21 | + from tests.perf.microbenchmarks.time_based.reads_regional.parameters import ( |
| 22 | + TimeBasedReadParameters, |
| 23 | + ) |
| 24 | +except ModuleNotFoundError: |
| 25 | + from reads_regional.parameters import TimeBasedReadParameters |
| 26 | + |
| 27 | + |
| 28 | +def _get_params() -> Dict[str, List[TimeBasedReadParameters]]: |
| 29 | + """Generates a dictionary of benchmark parameters for time based read operations.""" |
| 30 | + params: Dict[str, List[TimeBasedReadParameters]] = {} |
| 31 | + config_path = os.path.join(os.path.dirname(__file__), "config.yaml") |
| 32 | + with open(config_path, "r") as f: |
| 33 | + config = yaml.safe_load(f) |
| 34 | + |
| 35 | + common_params = config["common"] |
| 36 | + read_types = common_params["read_types"] |
| 37 | + file_sizes_mib = common_params["file_sizes_mib"] |
| 38 | + chunk_sizes_kib = common_params["chunk_sizes_kib"] |
| 39 | + num_ranges = common_params["num_ranges"] |
| 40 | + rounds = common_params["rounds"] |
| 41 | + duration = common_params["duration"] |
| 42 | + warmup_duration = common_params["warmup_duration"] |
| 43 | + |
| 44 | + # All read types use the same regional bucket |
| 45 | + bucket_name = os.environ.get( |
| 46 | + "DEFAULT_STANDARD_BUCKET", config["defaults"]["DEFAULT_STANDARD_BUCKET"] |
| 47 | + ) |
| 48 | + |
| 49 | + for workload in config["workload"]: |
| 50 | + workload_name = workload["name"] |
| 51 | + params[workload_name] = [] |
| 52 | + pattern = workload["pattern"] |
| 53 | + processes = workload["processes"] |
| 54 | + coros = workload["coros"] |
| 55 | + |
| 56 | + # Create a product of all parameter combinations |
| 57 | + product = itertools.product( |
| 58 | + read_types, |
| 59 | + file_sizes_mib, |
| 60 | + chunk_sizes_kib, |
| 61 | + num_ranges, |
| 62 | + processes, |
| 63 | + coros, |
| 64 | + ) |
| 65 | + |
| 66 | + for ( |
| 67 | + read_type, |
| 68 | + file_size_mib, |
| 69 | + chunk_size_kib, |
| 70 | + num_ranges_val, |
| 71 | + num_processes, |
| 72 | + num_coros, |
| 73 | + ) in product: |
| 74 | + file_size_bytes = file_size_mib * 1024 * 1024 |
| 75 | + chunk_size_bytes = chunk_size_kib * 1024 |
| 76 | + |
| 77 | + num_files = num_processes |
| 78 | + |
| 79 | + # Create a descriptive name for the parameter set |
| 80 | + name = f"{pattern}_{read_type}_{num_processes}p_{num_coros}c_{file_size_mib}MiB_{chunk_size_kib}KiB_{num_ranges_val}ranges" |
| 81 | + |
| 82 | + params[workload_name].append( |
| 83 | + TimeBasedReadParameters( |
| 84 | + name=name, |
| 85 | + workload_name=workload_name, |
| 86 | + pattern=pattern, |
| 87 | + bucket_name=bucket_name, |
| 88 | + bucket_type="regional", |
| 89 | + read_type=read_type, |
| 90 | + num_coros=num_coros, |
| 91 | + num_processes=num_processes, |
| 92 | + num_files=num_files, |
| 93 | + rounds=rounds, |
| 94 | + chunk_size_bytes=chunk_size_bytes, |
| 95 | + file_size_bytes=file_size_bytes, |
| 96 | + duration=duration, |
| 97 | + warmup_duration=warmup_duration, |
| 98 | + num_ranges=num_ranges_val, |
| 99 | + ) |
| 100 | + ) |
| 101 | + return params |
0 commit comments