Skip to content

Commit 7b5ed03

Browse files
committed
Add H2 connection pool with per-authority multiplexing
## Summary - Add AuthorityPool<C> that manages multiple H2 connections to a single authority (scheme+host+port), creating connections on demand when streams are exhausted and evicting failed ones - Add Pool<C> that routes requests to the correct AuthorityPool via a DashMap<ConnectionInfo, AuthorityPool<C>> - Add PoolBuilder with configurable max_connections and init_max_streams per authority
1 parent 7bb2e71 commit 7b5ed03

File tree

8 files changed

+1442
-4
lines changed

8 files changed

+1442
-4
lines changed

Cargo.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/service-client/Cargo.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ base64 = { workspace = true }
2525
bs58 = { workspace = true }
2626
bytes = { workspace = true }
2727
bytestring = { workspace = true }
28+
dashmap = { workspace = true }
29+
derive_builder = { workspace = true }
2830
futures = { workspace = true }
2931
h2 = "0.4.12"
3032
http = { workspace = true }
@@ -52,6 +54,12 @@ tracing = { workspace = true }
5254
zstd = { workspace = true }
5355

5456
[dev-dependencies]
57+
criterion = { workspace = true, features = ["async_tokio"] }
5558
googletest = { workspace = true }
59+
pprof = { version = "0.15", features = ["criterion", "flamegraph"] }
5660
tempfile = { workspace = true }
57-
tokio-stream = {workspace = true}
61+
tokio-stream = {workspace = true}
62+
63+
[[bench]]
64+
name = "h2_pool_benchmark"
65+
harness = false
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Service Client Benchmarks
2+
3+
Compares the custom H2 connection pool against hyper_util's legacy client using in-memory duplex streams.
4+
5+
## Benchmark groups
6+
7+
| Group | What it measures |
8+
|-------|-----------------|
9+
| `sequential` | Single request latency |
10+
| `concurrent/{10,50}` | Throughput under H2 multiplexing |
11+
| `body-{1KB,64KB}` | Data echo throughput |
12+
13+
## Running benchmarks
14+
15+
Run all benchmarks:
16+
17+
```bash
18+
cargo bench -p restate-service-client --bench h2_pool_benchmark
19+
```
20+
21+
Dry-run (verify they execute without measuring):
22+
23+
```bash
24+
cargo bench -p restate-service-client --bench h2_pool_benchmark -- --test
25+
```
26+
27+
Run a single benchmark by name filter:
28+
29+
```bash
30+
cargo bench -p restate-service-client --bench h2_pool_benchmark -- "sequential/custom-pool"
31+
```
32+
33+
## CPU profiling with pprof (built-in)
34+
35+
The benchmarks include [pprof](https://github.com/tikv/pprof-rs) integration that generates flamegraph SVGs.
36+
37+
### Prerequisites
38+
39+
On Linux, allow perf events:
40+
41+
```bash
42+
sudo sysctl kernel.perf_event_paranoid=-1
43+
```
44+
45+
### Profile a benchmark
46+
47+
Pass `--profile-time=<seconds>` to activate profiling:
48+
49+
```bash
50+
cargo bench -p restate-service-client --bench h2_pool_benchmark -- "sequential/custom-pool" --profile-time=30
51+
```
52+
53+
The flamegraph is written to:
54+
55+
```
56+
target/criterion/sequential/custom-pool/profile/flamegraph.svg
57+
```
58+
59+
Open it in a browser for an interactive view.
60+
61+
## CPU profiling with samply (external)
62+
63+
[samply](https://github.com/mstange/samply) can profile the benchmark binary without any code changes.
64+
65+
```bash
66+
# Build the benchmark binary (release mode)
67+
cargo bench -p restate-service-client --bench h2_pool_benchmark --no-run
68+
69+
# Find and run with samply
70+
samply record target/release/deps/h2_pool_benchmark-* --bench "sequential/custom-pool" --profile-time=30
71+
```
72+
73+
This opens the Firefox Profiler UI automatically.

0 commit comments

Comments
 (0)