blob: b1eff1c8eb21d30b29f92131d006f5c9fcaed897 [file] [log] [blame] [view]
Dmytro Shteflyuk82754d22026-03-27 12:39:51 -04001# Ruby Protocol Benchmarks
2
3This directory holds a small harness for quick Ruby protocol benchmarks.
4Use it to spot read and write regressions in tree.
5
6## Quick Start
7Run the script with plain `ruby` from the repo root.
8
9```sh
10ruby test/rb/benchmarks/protocol_benchmark.rb
11```
12
13This runs the full benchmark set:
14
15- Ruby binary
16- Ruby compact
17- Ruby JSON
18- Header binary
19- Header compact
20- Header zlib
21- C binary, if `thrift_native.so` loads
22
23## Options
24Use flags or env vars to tune a run.
25
26```sh
27ruby test/rb/benchmarks/protocol_benchmark.rb --large-runs 1 --small-runs 10000
28```
29
30- `--json`
31- `THRIFT_BENCHMARK_LARGE_RUNS`
32- `THRIFT_BENCHMARK_SMALL_RUNS`
33- `THRIFT_BENCHMARK_SKIP_NATIVE=1`
34- `THRIFT_BENCHMARK_SCENARIOS`
35
36```sh
37ruby test/rb/benchmarks/protocol_benchmark.rb --json > benchmark.json
38```
39
40> [!NOTE]
41> `--json` keeps the warm-up pass, but only prints measured results.
42
43> [!TIP]
44> Set `THRIFT_BENCHMARK_SKIP_NATIVE=1` to force a pure-Ruby run.
45
46## Scenario IDs
47Use `--scenarios` or `THRIFT_BENCHMARK_SCENARIOS` to run only part of the matrix.
48
49```sh
50ruby test/rb/benchmarks/protocol_benchmark.rb --scenarios rb-bin-write-large,rb-json-read-large,hdr-zlib-read-small
51```
52
53Each ID has four parts:
54
55- family: `rb`, `c`, or `hdr`
56- protocol: `bin`, `cmp`, `json`, or `zlib`
57- operation: `write` or `read`
58- size: `large` or `small`
59
60### Full Table
61
62| ID | Family | Protocol | Operation | Size |
63| --- | --- | --- | --- | --- |
64| `rb-bin-write-large` | Ruby | binary | write | large |
65| `rb-bin-read-large` | Ruby | binary | read | large |
66| `c-bin-write-large` | C native | binary | write | large |
67| `c-bin-read-large` | C native | binary | read | large |
68| `rb-cmp-write-large` | Ruby | compact | write | large |
69| `rb-cmp-read-large` | Ruby | compact | read | large |
70| `rb-json-write-large` | Ruby | JSON | write | large |
71| `rb-json-read-large` | Ruby | JSON | read | large |
72| `rb-bin-write-small` | Ruby | binary | write | small |
73| `rb-bin-read-small` | Ruby | binary | read | small |
74| `c-bin-write-small` | C native | binary | write | small |
75| `c-bin-read-small` | C native | binary | read | small |
76| `rb-cmp-write-small` | Ruby | compact | write | small |
77| `rb-cmp-read-small` | Ruby | compact | read | small |
78| `rb-json-write-small` | Ruby | JSON | write | small |
79| `rb-json-read-small` | Ruby | JSON | read | small |
80| `hdr-bin-write-small` | Header | binary | write | small |
81| `hdr-bin-read-small` | Header | binary | read | small |
82| `hdr-cmp-write-small` | Header | compact | write | small |
83| `hdr-cmp-read-small` | Header | compact | read | small |
84| `hdr-zlib-write-small` | Header | zlib | write | small |
85| `hdr-zlib-read-small` | Header | zlib | read | small |
86
87> [!NOTE]
88> Native-only IDs fail if `thrift_native.so` is not available.
89
90## Reference
91
92### What It Measures
93
94- Large jobs serialize and deserialize one nested `Nested4` payload by default.
95- Small jobs serialize and deserialize many `OneOfEach` payloads.
96- Read jobs use payloads built before timing so they measure read cost, not payload construction.
97- Header jobs flush after each struct so reads benchmark framed messages, not a buffered write that was never emitted.
98
99### Files
100
101- `protocol_benchmark.rb`: benchmark harness and scenario definitions
102- `../fixtures/structs.rb`: sample structs used by the benchmark
103
104### Notes
105This harness is for quick in-tree checks.
106Use `--json` if you want structured output for scripts, result diffs, or branch comparisons.
107Run it more than once if you want a wider sample.