Commit 49e3370
Add SemiFuture driver API + RunSession + first-story latency (#724)
Summary:
Pull Request resolved: #724
Programmer-A scope of Phase 6 per `~/feedsim_v2/docs/phase6_researcher_notes.md` sections 1, 2, 3, and 6. Server-side handlers (§4) and legacy-code deletion (§5) are split into Phase 6/2 (Programmer-B) and Phase 6/3 (Programmer-C) commits.
Four changes:
1. `FeedSimDriver` SemiFuture API (`FeedSimDriver.h`, `FeedSimDriver.cc`). New `TestDriver::sendRequestAndAwait(type, payload, length)` returns a `folly::SemiFuture<std::string>` that fulfills with the response payload bytes when the matching `ResponsePacketHeader` arrives. Implementation: per-`TestDriver` `folly::F14FastMap<uint64_t, folly::Promise<std::string>> pending_promises` keyed by `request_id`; `next_request_id` promoted from a plain `uint64_t` to `std::atomic<uint64_t>` so callers from arbitrary threads can mint IDs without contention. `event_base_once` hops the actual write onto the libevent thread (the only thread that may touch the bufferevent state). `readCb` parses the response header, copies the payload out of the libevent buffer, looks up the `request_id` under `pending_mutex`, moves the promise out, drops the lock, and calls `setValue`. The legacy fire-and-forget `sendRequest` stays in place — Phase 6-C deletes it.
2. `RunSession` orchestration (`DriverNodeRank.cc`). New `RunSession(thread_id, driver, thread_data)` builds the 4-step session pipeline that mirrors prod multifeed_aggregator: createAndPrimeSession (await) -> getStoriesUncompressed (HOLD future) + streamData * N (parallel) + optional streamIfrPriorityRanking coin flip -> await all streamData -> await getStoriesUncompressed and record first-story latency -> getAllStories (await) -> done. Encoders `encodeCreateAndPrime`, `encodeGetStories`, `encodeStreamData`, `encodeStreamIfrPriority`, `encodeGetAllStories` populate the typed thrift structs from Phase 4-B with realistic field values, sample target wire sizes from `RpcDistRegistry::inboundRequestSize()`, and pad the dominant binary field with Silesia bytes (compression-realistic). `query_id = (thread_id << 32) | session_counter++` so the leaf's `query_id >> 32` shard derivation lands all four-six RPCs for one session on the same RANKER worker. The new `StartSessionLoop` callback dispatches `RunSession` on a dedicated `CPUThreadPoolExecutor("DriverSession", num_threads)` and chains the pacing-timer rearm (`TestDriver::scheduleNextSession`) onto the SemiFuture completion. Session mode is gated by `--rpc_dist_json` — without it, the legacy `MakeRequest` path remains for backward compat during the migration.
3. First-story latency histogram (`FeedSimDriver.h`, `FeedSimDriver.cc`). Second `LatencySampler` added to `DriverStats` (`first_story_sampler_`). `recordFirstStoryLatencyNs(uint64_t)` on `TestDriver` forwards into it; `recordSessionComplete()` increments a session counter. `printStats()` emits a new "Stats for first-story latency" block with `fs_count`, `fs_sessions`, and `fs_min/avg/50p/90p/95p/99p/99.9p` lines. The `fs_*` prefix keeps `search_qps.sh`'s per-percentile greps unambiguous.
4. `search_qps.sh` parsing (`packages/feedsim/third_party/src/scripts/search_qps.sh`). Per-response latency greps are anchored on ` ` (leading whitespace) so they don't accidentally match the new first-story block. Four new CSV columns appended (`fs_50p_ms, fs_90p_ms, fs_95p_ms, fs_99p_ms`). New `fs_<percentile>` latency-type targets supported alongside the existing `<percentile>` ones (use `-s fs_95p:500` to search against the prod-equivalent first-story SLA per researcher §6).
Driver-side `RpcDistRegistry` inbound exposure (`RpcDistRegistry.h`) — added `InboundIdx` enum (5 methods), `inboundMethodNames()`, `inboundRequestSize/Response/LatencyUs(InboundIdx)` accessors, parallel `inbound_req_/resp_/lat_` arrays, and updated `load()` to populate them from the `inbound` JSON section. Programmer-B independently introduced a near-identical enum with slightly different naming (`kCreateAndPrimeSession` vs `CREATE_AND_PRIME`); kept B's naming and consumed it from `DriverNodeRank.cc` so Programmer-C can keep a single canonical version when deduplicating.
CLI flags added (`DriverNodeRankCmdline.ggo`): `--rpc_dist_json` (path, gates session mode), `--streamdata_per_session` (int, default=2; 0 randomizes uniform[1,3]), `--stream_ifr_probability` (float, default=0.045 to match prod ratio per researcher §2).
Reviewed By: charles-typ
Differential Revision: D1037951761 parent 1b0890e commit 49e3370
6 files changed
Lines changed: 1029 additions & 41 deletions
File tree
- packages/feedsim/third_party/src
- scripts
- workloads/ranking
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
204 | | - | |
205 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
206 | 216 | | |
207 | 217 | | |
208 | 218 | | |
| |||
231 | 241 | | |
232 | 242 | | |
233 | 243 | | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
241 | 265 | | |
242 | 266 | | |
243 | 267 | | |
244 | 268 | | |
245 | | - | |
| 269 | + | |
| 270 | + | |
246 | 271 | | |
247 | 272 | | |
248 | 273 | | |
| |||
344 | 369 | | |
345 | 370 | | |
346 | 371 | | |
347 | | - | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
348 | 375 | | |
349 | 376 | | |
350 | | - | |
351 | | - | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
352 | 382 | | |
353 | 383 | | |
354 | 384 | | |
| |||
380 | 410 | | |
381 | 411 | | |
382 | 412 | | |
383 | | - | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
384 | 418 | | |
385 | 419 | | |
386 | 420 | | |
| |||
0 commit comments