|
| 1 | +# VPA Performance Benchmark |
| 2 | + |
| 3 | +Measures VPA component latencies using KWOK (Kubernetes WithOut Kubelet) to simulate pods without real resource consumption. |
| 4 | + |
| 5 | +> **Note:** Currently only updater metrics are collected. Recommender metrics are planned for the future. |
| 6 | +
|
| 7 | +<!-- toc --> |
| 8 | +- [Prerequisites](#prerequisites) |
| 9 | +- [Quick Start (Local)](#quick-start-local) |
| 10 | +- [Manual Setup](#manual-setup) |
| 11 | +- [What It Does](#what-it-does) |
| 12 | +- [Profiles](#profiles) |
| 13 | +- [Flags](#flags) |
| 14 | +- [Metrics Collected](#metrics-collected) |
| 15 | + - [Updater Metrics](#updater-metrics) |
| 16 | +- [Scripts](#scripts) |
| 17 | +- [Cleanup](#cleanup) |
| 18 | +- [Notes](#notes) |
| 19 | + - [Performance Optimizations](#performance-optimizations) |
| 20 | + - [Caveats](#caveats) |
| 21 | +<!-- /toc --> |
| 22 | + |
| 23 | +## Prerequisites |
| 24 | + |
| 25 | +- Go 1.21+ |
| 26 | +- kubectl |
| 27 | +- Kind |
| 28 | +- yq |
| 29 | + |
| 30 | +## Quick Start (Local) |
| 31 | + |
| 32 | +The `full-benchmark.sh` script handles everything end-to-end: creates a Kind cluster, deploys VPA, installs KWOK, configures VPA for benchmarking, builds and runs the benchmark. |
| 33 | + |
| 34 | +```bash |
| 35 | +cd vertical-pod-autoscaler |
| 36 | +./benchmark/hack/full-benchmark.sh --profile=small --output=results.csv |
| 37 | +``` |
| 38 | + |
| 39 | +You can pass any benchmark flags directly: |
| 40 | + |
| 41 | +```bash |
| 42 | +./benchmark/hack/full-benchmark.sh --profile=small,medium,large --runs=3 --output=results.csv |
| 43 | +``` |
| 44 | + |
| 45 | +## Manual Setup |
| 46 | + |
| 47 | +If you prefer to run each step individually (or if the cluster already exists): |
| 48 | + |
| 49 | +```bash |
| 50 | +# 1. Create a Kind cluster (the full-benchmark.sh script appends benchmark-specific |
| 51 | +# kubeadmConfigPatches to .github/kind-config.yaml automatically; for manual setup, |
| 52 | +# create a cluster with the base config or your own) |
| 53 | +kind create cluster --config=.github/kind-config.yaml |
| 54 | + |
| 55 | +# 2. Deploy VPA |
| 56 | +./hack/deploy-for-e2e-locally.sh full-vpa |
| 57 | + |
| 58 | +# 3. Install KWOK and create fake node |
| 59 | +./benchmark/hack/install-kwok.sh |
| 60 | + |
| 61 | +# 4. Configure VPA deployments for benchmark (QPS/burst, updater interval) |
| 62 | +./benchmark/hack/configure-vpa.sh |
| 63 | + |
| 64 | +# 5. Build and run |
| 65 | +go build -C benchmark -o ../bin/vpa-benchmark . |
| 66 | +./bin/vpa-benchmark --profile=small --output=results.csv |
| 67 | +``` |
| 68 | + |
| 69 | +## What It Does |
| 70 | + |
| 71 | +The benchmark program (`main.go`) assumes the cluster is already set up with VPA, KWOK, and the fake node. It then: |
| 72 | + |
| 73 | +1. For each profile run: |
| 74 | + - Scales down VPA components |
| 75 | + - Cleans up previous benchmark resources |
| 76 | + - Creates ReplicaSets with fake pods assigned directly to KWOK node (bypasses scheduler) |
| 77 | + - Creates VPAs targeting those ReplicaSets |
| 78 | + - Scales up recommender, waits for recommendations |
| 79 | + - Scales up updater, waits for its loop to complete |
| 80 | + - Scrapes `vpa_updater_execution_latency_seconds_sum` metrics |
| 81 | +2. Outputs results to stdout and/or a CSV file if specified |
| 82 | + |
| 83 | +e.g., of output using this command: `bin/vpa-benchmark --profile=small,large,xxlarge` |
| 84 | + |
| 85 | +```bash |
| 86 | +========== Results ========== |
| 87 | +┌───────────────┬───────────────┬────────────────┬───────────────────┐ |
| 88 | +│ STEP │ SMALL ( 25 ) │ LARGE ( 250 ) │ XXLARGE ( 1000 ) │ |
| 89 | +├───────────────┼───────────────┼────────────────┼───────────────────┤ |
| 90 | +│ AdmissionInit │ 0.0000s │ 0.0001s │ 0.0004s │ |
| 91 | +│ EvictPods │ 2.4239s │ 24.5535s │ 98.6963s │ |
| 92 | +│ FilterPods │ 0.0002s │ 0.0020s │ 0.0925s │ |
| 93 | +│ ListPods │ 0.0001s │ 0.0006s │ 0.0025s │ |
| 94 | +│ ListVPAs │ 0.0024s │ 0.0030s │ 0.0027s │ |
| 95 | +│ total │ 2.4267s │ 24.5592s │ 98.7945s │ |
| 96 | +└───────────────┴───────────────┴────────────────┴───────────────────┘ |
| 97 | +``` |
| 98 | + |
| 99 | +We can then compare the results of a code change with the results of the main branch. |
| 100 | +Ideally the benchmark would be done on the same machine (or a similar one), with the same benchmark settings (profiles and runs). |
| 101 | + |
| 102 | +## Profiles |
| 103 | + |
| 104 | +| Profile | VPAs | ReplicaSets | Pods | |
| 105 | +| ------- | ---- | ----------- | ---- | |
| 106 | +| small | 25 | 25 | 50 | |
| 107 | +| medium | 100 | 100 | 200 | |
| 108 | +| large | 250 | 250 | 500 | |
| 109 | +| xlarge | 500 | 500 | 1000 | |
| 110 | +| xxlarge | 1000 | 1000 | 2000 | |
| 111 | + |
| 112 | +## Flags |
| 113 | + |
| 114 | +| Flag | Default | Description | |
| 115 | +| ---- | ------- | ----------- | |
| 116 | +| `--profile` | small | Comma-separated profiles to run. You can run multiple profiles at once. (e.g., `--profile=small,medium`) | |
| 117 | +| `--runs` | 1 | Iterations per profile. This is used for averaging multiple runs. | |
| 118 | +| `--output` | "" | Path to output file for results table (CSV format). Output will always be printed to stdout. | |
| 119 | +| `--kubeconfig` | "" | Path to kubeconfig. Required if not using KUBECONFIG env var or ~/.kube/config. | |
| 120 | + |
| 121 | +## Metrics Collected |
| 122 | + |
| 123 | +### Updater Metrics |
| 124 | + |
| 125 | +| Metric | Description | |
| 126 | +| ------ | ----------- | |
| 127 | +| `ListVPAs` | List VPA objects | |
| 128 | +| `ListPods` | List pods matching VPA targets | |
| 129 | +| `FilterPods` | Filter evictable pods | |
| 130 | +| `AdmissionInit` | Verify admission controller status | |
| 131 | +| `EvictPods` | Evict pods needing updates | |
| 132 | +| `total` | Total loop time | |
| 133 | + |
| 134 | +## Scripts |
| 135 | + |
| 136 | +| Script | Purpose | |
| 137 | +| ------ | ------- | |
| 138 | +| `hack/full-benchmark.sh` | Full local workflow (Kind + VPA + KWOK + configure + benchmark) | |
| 139 | +| `hack/install-kwok.sh` | Install KWOK controller and create fake node | |
| 140 | +| `hack/configure-vpa.sh` | Configure VPA deployments with benchmark-specific settings | |
| 141 | + |
| 142 | +Environment variables accepted by the scripts: |
| 143 | + |
| 144 | +| Variable | Default | Used by | |
| 145 | +| -------- | ------- | ------- | |
| 146 | +| `KWOK_VERSION` | `v0.7.0` | `install-kwok.sh` | |
| 147 | +| `KWOK_NAMESPACE` | `kube-system` | `install-kwok.sh` | |
| 148 | +| `KWOK_NODE_NAME` | `kwok-node` | `install-kwok.sh` | |
| 149 | +| `VPA_NAMESPACE` | `kube-system` | `configure-vpa.sh` | |
| 150 | +| `KIND_CLUSTER_NAME` | `kind` | `full-benchmark.sh` | |
| 151 | + |
| 152 | +## Cleanup |
| 153 | + |
| 154 | +```bash |
| 155 | +kind delete cluster |
| 156 | +``` |
| 157 | + |
| 158 | +## Notes |
| 159 | + |
| 160 | +### Performance Optimizations |
| 161 | + |
| 162 | +The benchmark includes several performance optimizations: |
| 163 | + |
| 164 | +- `configure-vpa.sh` modifies VPA deployments using `yq`: |
| 165 | + - Sets `--kube-api-qps=100` and `--kube-api-burst=200` on all three components |
| 166 | + - Sets `--updater-interval=2m` on the updater (default is 60s) |
| 167 | +- Pods are assigned directly to the KWOK node via `nodeName`, bypassing the scheduler for faster creation |
| 168 | +- The benchmark script appends `kubeadmConfigPatches` to the base `.github/kind-config.yaml` to increase API server limits (`max-requests-inflight`, `max-mutating-requests-inflight`) and kube-controller-manager client QPS to handle the large number of API calls |
| 169 | +- Uses ReplicaSets instead of Deployments to skip the Deployment controller layer and speed up pod creation, but keep a targetRef for VPA |
| 170 | + |
| 171 | +### Caveats |
| 172 | + |
| 173 | +- The updater uses `time.Tick` which waits the full interval before the first tick, so the benchmark sleeps 2 minutes before polling for metrics |
| 174 | +- The benchmark uses Recreate update mode. In-place scaling is not supported on KWOK pods. |
| 175 | +- The benchmark scales down all VPA components at the start of each run, so that any caching is not a factor. |
0 commit comments