|
| 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.writes.parameters import WriteParameters |
| 22 | +except ModuleNotFoundError: |
| 23 | + from parameters import WriteParameters |
| 24 | + |
| 25 | + |
| 26 | +def get_write_params() -> Dict[str, List[WriteParameters]]: |
| 27 | + """Generates benchmark parameters from a YAML configuration file. |
| 28 | +
|
| 29 | + This function reads the configuration from `config.yaml`, located in the |
| 30 | + same directory, and generates all possible combinations of write parameters |
| 31 | + based on the defined workloads. It uses `itertools.product` to create |
| 32 | + a Cartesian product of parameters like bucket types, file sizes, etc. |
| 33 | +
|
| 34 | + Returns: |
| 35 | + Dict[str, List[WriteParameters]]: A dictionary where keys are workload |
| 36 | + names and values are lists of `WriteParameters` instances for that |
| 37 | + workload. |
| 38 | + """ |
| 39 | + params: Dict[str, List[WriteParameters]] = {} |
| 40 | + config_path = os.path.join(os.path.dirname(__file__), "config.yaml") |
| 41 | + with open(config_path, "r") as f: |
| 42 | + config = yaml.safe_load(f) |
| 43 | + |
| 44 | + common_params = config["common"] |
| 45 | + bucket_types = common_params["bucket_types"] |
| 46 | + file_sizes_mib = common_params["file_sizes_mib"] |
| 47 | + chunk_sizes_mib = common_params["chunk_sizes_mib"] |
| 48 | + rounds = common_params["rounds"] |
| 49 | + |
| 50 | + bucket_map = { |
| 51 | + "zonal": os.environ.get("DEFAULT_RAPID_ZONAL_BUCKET", config['defaults']['DEFAULT_RAPID_ZONAL_BUCKET']), |
| 52 | + "regional": os.environ.get("DEFAULT_STANDARD_BUCKET", config['defaults']['DEFAULT_STANDARD_BUCKET']) |
| 53 | + } |
| 54 | + |
| 55 | + for workload in config["workload"]: |
| 56 | + workload_name = workload["name"] |
| 57 | + params[workload_name] = [] |
| 58 | + processes = workload["processes"] |
| 59 | + coros = workload["coros"] |
| 60 | + |
| 61 | + # Create a product of all parameter combinations |
| 62 | + product = itertools.product( |
| 63 | + bucket_types, |
| 64 | + file_sizes_mib, |
| 65 | + chunk_sizes_mib, |
| 66 | + processes, |
| 67 | + coros, |
| 68 | + ) |
| 69 | + |
| 70 | + for ( |
| 71 | + bucket_type, |
| 72 | + file_size_mib, |
| 73 | + chunk_size_mib, |
| 74 | + num_processes, |
| 75 | + num_coros, |
| 76 | + ) in product: |
| 77 | + file_size_bytes = file_size_mib * 1024 * 1024 |
| 78 | + chunk_size_bytes = chunk_size_mib * 1024 * 1024 |
| 79 | + bucket_name = bucket_map[bucket_type] |
| 80 | + |
| 81 | + num_files = num_processes * num_coros |
| 82 | + |
| 83 | + # Create a descriptive name for the parameter set |
| 84 | + name = f"{workload_name}_{bucket_type}_{num_processes}p_{num_coros}c" |
| 85 | + |
| 86 | + params[workload_name].append( |
| 87 | + WriteParameters( |
| 88 | + name=name, |
| 89 | + workload_name=workload_name, |
| 90 | + bucket_name=bucket_name, |
| 91 | + bucket_type=bucket_type, |
| 92 | + num_coros=num_coros, |
| 93 | + num_processes=num_processes, |
| 94 | + num_files=num_files, |
| 95 | + rounds=rounds, |
| 96 | + chunk_size_bytes=chunk_size_bytes, |
| 97 | + file_size_bytes=file_size_bytes, |
| 98 | + ) |
| 99 | + ) |
| 100 | + return params |
0 commit comments