|
| 1 | +# Copyright 2025 PerfKitBenchmarker Authors. All rights reserved. |
| 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 | + |
| 15 | +"""Benchbase Benchmark. |
| 16 | +
|
| 17 | +This is a set of benchmarks that measures OLTP performance of managed |
| 18 | +postgres databases using the Benchbase(https://github.com/cmu-db/benchbase) |
| 19 | +framework. |
| 20 | +""" |
| 21 | + |
| 22 | +from typing import Any, Dict, List |
| 23 | + |
| 24 | +from absl import flags |
| 25 | +from perfkitbenchmarker import benchmark_spec as bm_spec |
| 26 | +from perfkitbenchmarker import configs |
| 27 | +from perfkitbenchmarker import sample |
| 28 | +from perfkitbenchmarker.linux_packages import benchbase |
| 29 | + |
| 30 | +BENCHMARK_NAME: str = 'benchbase' |
| 31 | +BENCHMARK_CONFIG: str = """ |
| 32 | +benchbase: |
| 33 | + description: Runs Benchbase benchmark. |
| 34 | + relational_db: |
| 35 | + cloud: GCP |
| 36 | + engine: spanner-postgres |
| 37 | + spanner_nodes: 3 |
| 38 | + db_spec: |
| 39 | + GCP: |
| 40 | + zone: us-central1-f |
| 41 | + db_disk_spec: |
| 42 | + GCP: |
| 43 | + disk_size: 2048 |
| 44 | + disk_type: pd-ssd |
| 45 | + vm_groups: |
| 46 | + clients: |
| 47 | + vm_spec: |
| 48 | + GCP: |
| 49 | + machine_type: n2-standard-21 |
| 50 | + zone: us-central1-c |
| 51 | + disk_spec: |
| 52 | + GCP: |
| 53 | + disk_size: 500 |
| 54 | + disk_type: pd-ssd |
| 55 | +""" |
| 56 | + |
| 57 | +FLAGS = flags.FLAGS |
| 58 | + |
| 59 | + |
| 60 | +def GetConfig(user_config: Dict[str, Any]) -> Dict[str, Any]: |
| 61 | + """Loads and returns benchmark config. |
| 62 | +
|
| 63 | + Args: |
| 64 | + user_config: user supplied configuration (flags and config file) |
| 65 | +
|
| 66 | + Returns: |
| 67 | + loaded benchmark configuration |
| 68 | + """ |
| 69 | + return configs.LoadConfig(BENCHMARK_CONFIG, user_config, BENCHMARK_NAME) |
| 70 | + |
| 71 | + |
| 72 | +# TODO(shuninglin): need to implement auth logic(automatic password gen) |
| 73 | +# for DSQL |
| 74 | +def Prepare(benchmark_spec: bm_spec.BenchmarkSpec) -> None: |
| 75 | + """Prepares the benchmark by installing BenchBase and loading data. |
| 76 | +
|
| 77 | + Args: |
| 78 | + benchmark_spec: The benchmark specification. Contains all data that is |
| 79 | + required to run the benchmark. |
| 80 | + """ |
| 81 | + |
| 82 | + vms = benchmark_spec.vms |
| 83 | + client_vm = vms[0] |
| 84 | + |
| 85 | + # Install BenchBase on the client VM |
| 86 | + client_vm.Install('benchbase') |
| 87 | + |
| 88 | + # Create the configuration file on the client VM |
| 89 | + benchbase.CreateConfigFile(client_vm) |
| 90 | + # TODO(shuninglin): Implement benchbase data loading |
| 91 | + |
| 92 | + |
| 93 | +def Run(benchmark_spec: bm_spec.BenchmarkSpec) -> List[sample.Sample]: |
| 94 | + """Runs the BenchBase benchmark. |
| 95 | +
|
| 96 | + Args: |
| 97 | + benchmark_spec: The benchmark specification. |
| 98 | +
|
| 99 | + Returns: |
| 100 | + A list of sample.Sample objects. |
| 101 | + """ |
| 102 | + del benchmark_spec # Unused for now. |
| 103 | + # TODO(shuninglin): Implement the run phase |
| 104 | + # 1. Construct the run command: |
| 105 | + # 2.1 Send the first run command as warmup |
| 106 | + # 2.2 Sleep for warmup duration |
| 107 | + # 2.3 Send the second run command as the main workload |
| 108 | + # 3. Parse results from the output files |
| 109 | + |
| 110 | + samples: List[sample.Sample] = [] |
| 111 | + return samples |
| 112 | + |
| 113 | + |
| 114 | +def Cleanup(benchmark_spec: bm_spec.BenchmarkSpec) -> None: |
| 115 | + """Cleans up the benchmark. |
| 116 | +
|
| 117 | + Args: |
| 118 | + benchmark_spec: The benchmark specification. |
| 119 | + """ |
| 120 | + # Nothing to do in cleanup for now. |
| 121 | + del benchmark_spec # Unused for now. |
| 122 | + pass |
0 commit comments