Skip to content

Commit 82754d2

Browse files
kpumukJens-G
authored andcommitted
THRIFT-5944: Corrected and expanded Ruby protocol benchmarks
1 parent 269396a commit 82754d2

File tree

4 files changed

+546
-199
lines changed

4 files changed

+546
-199
lines changed

lib/rb/lib/thrift/thrift_native.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020
begin
2121
require "thrift_native"
2222
rescue LoadError
23-
puts "Unable to load thrift_native extension. Defaulting to pure Ruby libraries."
23+
warn "Unable to load thrift_native extension. Defaulting to pure Ruby libraries."
2424
end

test/rb/benchmarks/README.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Ruby Protocol Benchmarks
2+
3+
This directory holds a small harness for quick Ruby protocol benchmarks.
4+
Use it to spot read and write regressions in tree.
5+
6+
## Quick Start
7+
Run the script with plain `ruby` from the repo root.
8+
9+
```sh
10+
ruby test/rb/benchmarks/protocol_benchmark.rb
11+
```
12+
13+
This 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
24+
Use flags or env vars to tune a run.
25+
26+
```sh
27+
ruby 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
37+
ruby 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
47+
Use `--scenarios` or `THRIFT_BENCHMARK_SCENARIOS` to run only part of the matrix.
48+
49+
```sh
50+
ruby test/rb/benchmarks/protocol_benchmark.rb --scenarios rb-bin-write-large,rb-json-read-large,hdr-zlib-read-small
51+
```
52+
53+
Each 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
105+
This harness is for quick in-tree checks.
106+
Use `--json` if you want structured output for scripts, result diffs, or branch comparisons.
107+
Run it more than once if you want a wider sample.

0 commit comments

Comments
 (0)