Commit d2d6247
Three knobs to rebalance Compression/Encryption: partial mock-ZSTD, server-ZSTD env gate, driver↔server TLS (facebookresearch#746)
Summary:
Pull Request resolved: facebookresearch#746
The t41 9-cell sweep (single×autoscale × rpc_fanout_scale on CPL/BGM/GRC, classified with the new v2 hot-func rules in D108210357) showed two persistent gaps vs prod multifeed_aggregator:
- **Compression over-target**: bench 5.9-10.0% across cells vs prod 3.9-5.2%. Bench runs ZSTD on every outbound mock_services channel (`MOCK_COMPRESS_ZSTD=1`) AND on every server response (`compressThrift`), so the total compression CPU footprint is roughly 2× prod.
- **Encryption under-target**: bench 0.9-1.8% on x86 vs prod 3.3-3.6%. The mock_services channel uses TLS (closes part of the gap) but the driver↔server channel runs plaintext over a raw `AsyncSocket`/libevent `bufferevent_socket`, leaving the bulk of the bench unencrypted.
This diff adds three independent knobs that let us experiment with the rebalance without touching the production-aligned defaults. All knobs are env-var-driven (LeafNodeRank uses gengetopt and rejects unknown CLI flags); all default to current behavior so unset = no change.
**Knob 1 — `MOCK_ZSTD_FRAC` (replaces all-or-nothing `MOCK_COMPRESS_ZSTD`):**
Float in [0.0, 1.0] that controls the fraction of `MockServicesClient` instances that enable per-channel ZSTD `CompressionConfig`. Each leaf builds one client per `SREventBase` thread (~88-176 per process); a process-global atomic counter assigns each new client a monotonic index, and the decision `(idx % 100) < int(frac * 100)` gives deterministic per-channel selection. Matches prod's mix-of-compressed-and-plaintext downstream services. Backwards compat: when `MOCK_ZSTD_FRAC` is unset, falls back to legacy `MOCK_COMPRESS_ZSTD` (1→1.0, 0→0.0); default when both unset = 1.0.
**Knob 2 — `FEEDSIM_SERVER_ZSTD` (gate for server-side response compression):**
Boolean env var, default true. When "0", both `compressThrift()` and `compressPayload()` in `LeafNodeRank.cc` return the input unchanged (passthrough), bypassing the ZSTD codec entirely. Reads the env once via `static const bool` so request-time cost is a single branch.
**Knob 3 — `FEEDSIM_DRIVER_TLS` (TLS on the driver↔server channel):**
Boolean env var, default false. When "1":
- `FeedSimServer` reads `FEEDSIM_TLS_CERT` / `FEEDSIM_TLS_KEY` env vars (wired by `run.sh` to the existing bench cert/key at `${FEEDSIM_ROOT}/certs/example.{crt,key}`), creates a `folly::SSLContext`, and wraps each accepted fd in `AsyncSSLSocket(ctx, evb, fd, true /*server*/)` via the `AcceptCallback` constructor.
- `FeedSimDriver` lazy-inits a process-global `SSL_CTX` (TLS_client_method, `SSL_VERIFY_NONE`) on first connection, and wraps each `DriverConnection`'s libevent `bufferevent` with `bufferevent_openssl_socket_new(base, fd, SSL_new(ctx), BUFFEREVENT_SSL_CONNECTING, BEV_OPT_CLOSE_ON_FREE)`. Requires `libevent_openssl` (added to `CMakeLists.txt` via `find_library(LIBEVENT_OPENSSL_LIB NAMES event_openssl ...)` and appended to `ranking-cpp2`'s link line).
Independent of `FEEDSIM_TLS`, which only covers the mock_services channel. No ALPN — the driver↔server protocol is custom binary, not Rocket.
Files:
- `MockServicesClient.cc`: add `envFloat()` helper + `resolveZstdFraction()` + atomic per-instance counter; replace `use_zstd = envBoolTrue(...)` with deterministic per-channel decision based on resolved fraction. `LOG_FIRST_N` logs the active fraction once per process.
- `LeafNodeRank.cc`: gate `compressThrift()` and `compressPayload()` on `FEEDSIM_SERVER_ZSTD`. Each function reads the env once via `static const bool`.
- `FeedSimServer.{cc,h}`: add `std::shared_ptr<folly::SSLContext>` member to `Impl`; in `run()` read `FEEDSIM_TLS_CERT` / `FEEDSIM_TLS_KEY` env vars and build the context if both set; pass the shared_ptr through `AcceptCallback`'s new ctor arg; in `connectionAccepted`, when ctx is set, wrap the fd in `AsyncSSLSocket` instead of plain `AsyncSocket`. Falls back to plain `AsyncSocket` when ctx is null.
- `FeedSimDriver.cc`: include `<event2/bufferevent_ssl.h>` + `<openssl/ssl.h>`; add `getDriverSslCtxOrNull()` with lazy static SSL_CTX init from `FEEDSIM_DRIVER_TLS` env; in `DriverConnection` ctor, when ctx is non-null, wrap fd in `bufferevent_openssl_socket_new` instead of plain `bufferevent_socket_new`.
- `CMakeLists.txt`: `find_library(LIBEVENT_OPENSSL_LIB NAMES event_openssl ...)` after the `find_program(GENGETOPT_EXECUTABLE)` block; append `${LIBEVENT_OPENSSL_LIB}` to `ranking-cpp2` next to `${LIBEVENT_LIB}`.
- `run.sh`: pass through `MOCK_ZSTD_FRAC` and `FEEDSIM_SERVER_ZSTD` env vars; when `FEEDSIM_DRIVER_TLS=1`, also export `FEEDSIM_TLS_CERT` and `FEEDSIM_TLS_KEY` pointing at `${FEEDSIM_ROOT}/certs/example.{crt,key}` (with readability check that errors out if missing).
Reviewed By: charles-typ
Differential Revision: D1093523011 parent f8ab6cd commit d2d6247
6 files changed
Lines changed: 262 additions & 10 deletions
File tree
- packages/feedsim
- third_party/src/workloads/ranking
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
780 | 780 | | |
781 | 781 | | |
782 | 782 | | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
783 | 820 | | |
784 | 821 | | |
785 | 822 | | |
| |||
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
41 | 53 | | |
42 | 54 | | |
43 | 55 | | |
| |||
64 | 76 | | |
65 | 77 | | |
66 | 78 | | |
| 79 | + | |
67 | 80 | | |
68 | 81 | | |
69 | 82 | | |
| |||
Lines changed: 63 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| 18 | + | |
| 19 | + | |
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
| |||
218 | 221 | | |
219 | 222 | | |
220 | 223 | | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
221 | 257 | | |
222 | 258 | | |
223 | 259 | | |
| |||
238 | 274 | | |
239 | 275 | | |
240 | 276 | | |
241 | | - | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
242 | 304 | | |
243 | 305 | | |
244 | 306 | | |
| |||
Lines changed: 63 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| 36 | + | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
| |||
241 | 243 | | |
242 | 244 | | |
243 | 245 | | |
244 | | - | |
| 246 | + | |
| 247 | + | |
245 | 248 | | |
246 | 249 | | |
| 250 | + | |
247 | 251 | | |
248 | 252 | | |
249 | 253 | | |
| |||
260 | 264 | | |
261 | 265 | | |
262 | 266 | | |
263 | | - | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
264 | 275 | | |
265 | 276 | | |
266 | | - | |
267 | | - | |
268 | | - | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
269 | 290 | | |
270 | 291 | | |
271 | 292 | | |
| |||
278 | 299 | | |
279 | 300 | | |
280 | 301 | | |
| 302 | + | |
281 | 303 | | |
282 | 304 | | |
283 | 305 | | |
| |||
298 | 320 | | |
299 | 321 | | |
300 | 322 | | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
301 | 328 | | |
302 | 329 | | |
303 | 330 | | |
| |||
390 | 417 | | |
391 | 418 | | |
392 | 419 | | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
393 | 450 | | |
394 | | - | |
| 451 | + | |
395 | 452 | | |
396 | 453 | | |
397 | 454 | | |
| |||
Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
809 | 809 | | |
810 | 810 | | |
811 | 811 | | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
812 | 823 | | |
813 | 824 | | |
814 | 825 | | |
| |||
830 | 841 | | |
831 | 842 | | |
832 | 843 | | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
833 | 857 | | |
834 | 858 | | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
835 | 865 | | |
836 | 866 | | |
837 | 867 | | |
| |||
0 commit comments