Skip to content

Commit 18fa151

Browse files
committed
refactor(webapp): rename realtime emission fan-out metrics to what they count
1 parent 02f7a57 commit 18fa151

2 files changed

Lines changed: 26 additions & 30 deletions

File tree

apps/webapp/app/services/realtime/envChangeRouter.server.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,15 @@ export type EnvChangeRouterOptions = {
5151
/** Observability: a buffered record was evicted. `cap` evictions mean the env churns more
5252
* runs inside the window than the buffer holds (the replay guarantee is degrading). */
5353
onReplayEviction?: (reason: "cap" | "window") => void;
54-
/** Observability: per-batch emission fan-out. `runEmissions` = total (feed,run) rows resolved
55-
* to feeds this batch (the baseline per-feed serialize count); `distinctSerializations` = distinct
56-
* (columnSig,runId) among them (what a serialize-once-per-batch memo would compute). The gap
57-
* (runEmissions - distinctSerializations) is the duplicate serialization such a memo would remove. */
54+
/** Observability: per-batch emission fan-out. `deliveries` = total (feed,run) rows matched and
55+
* resolved to feeds this batch. It is an upper bound on the per-feed wire serializations, since
56+
* the client working-set diff drops already-seen rows before encoding. `distinctRuns` = distinct
57+
* (columnSig,runId) among them (the serialize-once-per-batch floor). `deliveries / distinctRuns`
58+
* is the average number of feeds a changed run is delivered to; a shared-serialization step would
59+
* save at most `deliveries - distinctRuns` encodings. */
5860
onEmissionFanout?: (stats: {
59-
distinctSerializations: number;
60-
runEmissions: number;
61+
distinctRuns: number;
62+
deliveries: number;
6163
feeds: number;
6264
}) => void;
6365
/** Read-your-writes gate over the replica: delays wake-path hydrates until the replica
@@ -618,8 +620,8 @@ export class EnvChangeRouter {
618620

619621
// 4. Assemble each feed's matched rows (post-filtering tag feeds against the
620622
// authoritative hydrated row) and resolve its pending wait.
621-
let runEmissions = 0;
622-
const emittedSerializationKeys = new Set<string>();
623+
let deliveries = 0;
624+
const distinctRunKeys = new Set<string>();
623625
for (const [feed, runIds] of matchedRunIdsByFeed) {
624626
if (!feed.resolve) {
625627
continue; // stopped waiting while we hydrated; its next poll/backstop covers it
@@ -642,19 +644,19 @@ export class EnvChangeRouter {
642644

643645
if (rows.length > 0) {
644646
feed.resolve({ reason: "notify", rows });
645-
runEmissions += rows.length;
647+
deliveries += rows.length;
646648
for (const matched of rows) {
647-
emittedSerializationKeys.add(`${feed.columnSig}
649+
distinctRunKeys.add(`${feed.columnSig}
648650
}
649651
}
650652
// No surviving rows (e.g. a partial-record candidate that didn't actually match):
651653
// leave the feed waiting; nothing relevant changed for it.
652654
}
653655

654-
if (runEmissions > 0) {
656+
if (deliveries > 0) {
655657
this.options.onEmissionFanout?.({
656-
distinctSerializations: emittedSerializationKeys.size,
657-
runEmissions,
658+
distinctRuns: distinctRunKeys.size,
659+
deliveries,
658660
feeds: matchedRunIdsByFeed.size,
659661
});
660662
}

apps/webapp/app/services/realtime/nativeRealtimeClientInstance.server.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,15 @@ function initializeNativeRealtimeClient(): NativeRealtimeClient {
7171
unit: "rows",
7272
});
7373

74-
const emissionRunSerializations = meter.createCounter(
75-
"realtime_native.emission_run_serializations",
76-
{
77-
description:
78-
"Total per-feed row emissions per batch (the wire-value serializations the current path performs). Divide by realtime_native.emission_distinct_serializations for average feeds-per-run fan-out; the excess is duplicate serialization a serialize-once-per-batch memo would remove.",
79-
}
80-
);
74+
const emissionFeedDeliveries = meter.createCounter("realtime_native.emission_feed_deliveries", {
75+
description:
76+
"Matched (feed,run) rows resolved to feeds per batch, summed. Upper bound on per-feed wire serializations, since the client working-set diff drops already-seen rows before encoding. Divide by realtime_native.emission_distinct_runs for average feeds-per-run fan-out.",
77+
});
8178

82-
const emissionDistinctSerializations = meter.createCounter(
83-
"realtime_native.emission_distinct_serializations",
84-
{
85-
description:
86-
"Distinct (columnSig,runId) emitted per batch, summed. A serialize-once-per-batch memo would perform exactly this many serializations vs realtime_native.emission_run_serializations today; 1 - (this / run_serializations) is the memo's serialization-work saving.",
87-
}
88-
);
79+
const emissionDistinctRuns = meter.createCounter("realtime_native.emission_distinct_runs", {
80+
description:
81+
"Distinct (columnSig,run) among the deliveries per batch, summed. The serialize-once-per-batch floor: a shared-serialization step would encode at most this many rows, saving at most (feed_deliveries minus distinct_runs) encodings.",
82+
});
8983

9084
const backstops = meter.createCounter("realtime_native.backstops", {
9185
description:
@@ -182,9 +176,9 @@ function initializeNativeRealtimeClient(): NativeRealtimeClient {
182176
unsubscribeLingerMs: env.REALTIME_BACKEND_NATIVE_UNSUBSCRIBE_LINGER_MS,
183177
onReplay: (result) => replays.add(1, { result }),
184178
onReplayEviction: (reason) => replayEvictions.add(1, { reason }),
185-
onEmissionFanout: ({ distinctSerializations, runEmissions }) => {
186-
emissionRunSerializations.add(runEmissions);
187-
emissionDistinctSerializations.add(distinctSerializations);
179+
onEmissionFanout: ({ distinctRuns, deliveries }) => {
180+
emissionFeedDeliveries.add(deliveries);
181+
emissionDistinctRuns.add(distinctRuns);
188182
},
189183
replicaLag: lagEstimator
190184
? {

0 commit comments

Comments
 (0)