library / Integrations / Search and time series / I0130
Graphite slot arrival jitter
Slot updates that arrive in clumps usually mean the reader stalled, not that the node sent late. This watcher times each slotNotification on arrival, counts the bursts and writes every gap in Graphite plaintext for a dashboard.
Why notifications arrive in clumps
A slot notification leaves the node when the node has a new slot. A slot is about 200 ms long since the Alpenglow switch, so a healthy feed brings roughly five messages a second. When five of them show up in one tick and then nothing for a while, the node sent them on schedule and your process read them late. The socket keeps the bytes in order, but your code receives them in whatever chunks the read loop gets, and each chunk can hold several messages.
Three things make a reader fall behind. Synchronous work on the event loop, such as a large JSON parse, a long loop over an array or a blocking file write, holds every pending message until it returns. A garbage collection pause does the same for a moment. A proxy or load balancer between your process and Carbium can also hold frames and forward them together. In each case the timestamps you take in your handler bunch up while the slot numbers keep their pace.
The slot numbers tell the causes apart. If the numbers in a clump run one after another, the node made those slots one after another and your reader caught up with them all at once. A gap in the numbers means slots were skipped, and the timing alone cannot show that.
Timing each arrival
The watcher opens one slot subscription on Carbium's WebSocket and stamps each notification with a monotonic clock the moment it reaches the handler. It keeps the gap to the arrival before. A gap under 5 ms counts as a burst, because messages read in one pass reach the handler almost together. Every gap goes to a file in the Graphite plaintext format, one line per arrival: carbium.slot.arrival_gap_ms <gap> <unix seconds>. A Graphite carbon listener reads that format, so a relay you run can forward the file as it grows.
Take the stamp before any other work runs in the handler. A stamp taken after a parse measures the parse too, and the parse is the thing under test.
The subscription runs on wss://services.carbium.sh unless CARBIUM_WS_URL says otherwise. The key goes on the URL as api-key, the form the auth page gives for WebSockets, and the watcher never prints the URL. A slot subscription costs 5 credits to open, then 20 credits per MiB sent. At 200 ms slots a 15 second run sees about 75 notifications, so its cost is small, and a feed left open all day costs in proportion to the bytes it moves.
The watcher
Install the one dependency with npm install @solana/[email protected], set "type": "module" in package.json, and run the file with a length in seconds. Node 24 strips the types on load. The watcher reads one variable, CARBIUM_KEY, and exits with a message when it is unset.
// I0130 · Graphite slot arrival jitter// https://carbium.sh/library/integrate/graphite-slot-arrival-jitter// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { createSolanaRpcSubscriptions } from "@solana/kit";import { appendFile, writeFile } from "node:fs/promises";const key = process.env.CARBIUM_KEY;if (!key) { console.error("Set CARBIUM_KEY to your whole Carbium key."); process.exit(1);}const seconds = Number(process.argv[2] ?? 15);if (!Number.isFinite(seconds) || seconds <= 0) { console.error("Pass a run length in seconds, for example 15."); process.exit(1);}// The key rides on the URL as api-key; one socket serves the whole run.const url = new URL(process.env.CARBIUM_WS_URL ?? "wss://services.carbium.sh");url.searchParams.set("api-key", key);const rpcSubscriptions = createSolanaRpcSubscriptions(url.toString());const out = "slot-arrivals.graphite"; // relative: written in the run directoryconst BURST_MS = 5; // arrivals this close were read in one passawait writeFile(out, "");const stop = new AbortController();setTimeout(() => stop.abort(), seconds * 1000);let last: number | null = null;let lastSlot = "none";let count = 0;let bursts = 0;let worst = 0;let total = 0;try { const feed = await rpcSubscriptions.slotNotifications().subscribe({ abortSignal: stop.signal }); for await (const note of feed) { const now = performance.now(); count++; lastSlot = String(note.slot); if (last !== null) { const gap = now - last; if (gap < BURST_MS) bursts++; worst = Math.max(worst, gap); total += gap; const unix = Math.floor(Date.now() / 1000); await appendFile(out, `carbium.slot.arrival_gap_ms ${gap.toFixed(1)} ${unix}\n`); } last = now; }} catch (err) { if (!stop.signal.aborted) { console.error("subscription failed:", err instanceof Error ? err.message : err); process.exit(1); }}if (count < 2) { console.log(`slots seen ${count}: not enough arrivals to measure, check the URL and key`);} else { console.log(`slots seen ${count}, last slot ${lastSlot}`); console.log(`arrivals within ${BURST_MS} ms of the one before: ${bursts}`); console.log(`mean gap ${(total / (count - 1)).toFixed(1)} ms, longest gap ${worst.toFixed(1)} ms`); console.log(`gaps written to ${out}`);}
run: node main.ts 15
Reading the summary
The summary prints the slot count, the number of bursts, the mean gap and the longest gap. At 200 ms slots the mean gap sits near 200 ms when the reader keeps up. The table reads the shape of a run.
| What you see | Likely cause | What to change |
|---|---|---|
| Bursts with consecutive slot numbers | The handler stalled and read several messages in one pass | Move parsing and file writes out of the subscription loop, or hand them to a queue |
| One long gap, then a burst | A pause in the process, such as garbage collection or a blocking call | Look at memory use and any synchronous call made in the same loop |
| Gaps with missing slot numbers | Slots the leader never produced, which send no notification | Nothing in the reader; a skipped slot is part of the chain |
| Steady gaps near 200 ms and no bursts | The feed and the reader both keep pace | Nothing; look for clumps in another process or a proxy |
A run of about 15 seconds is enough to see the shape. Run it again under the app's real load, because a stall that appears only under load does not show on an idle process.
Cost and connection limits
A slot subscription costs 5 credits to open, then 20 credits per MiB sent, and credits meter WebSocket work on the account. Limits are per account, so every key on the account draws on one budget.
Free carries 5 sockets per account, and one watcher uses one of them. Keep the watcher on one socket and reuse it for the whole run. Connections stay open for 600 s, and a reconnect starts a new subscription that carries no earlier notifications.
Where it ends
- The timing starts when the message reaches your handler. It cannot split delay on Carbium's side from delay on the network, so run the watcher on a host near the app and read the burst pattern as a whole.
- The 5 ms burst test suits one Node process on one machine. A slower or busier host can group reads more widely, so change the constant after a run on that host.
- It reads slot notifications only. It says nothing about transactions, accounts or the result of your own calls.
- A dropped socket loses the notifications sent while it was down. The summary counts only the arrivals it saw, so a dropped run shows fewer slots and one long gap.
- The output is a plain file with no retention and no aggregation. The watcher does not send to Graphite itself; a carbon listener or a relay you run has to read the file.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| Every gap lands in a burst, and the file shows the same burst pattern on every run. | The stall is in your handler on every message. Move parsing and file writes out of the loop, run again and compare the burst count. |
| The run ends at once with subscription failed and a 401 message. | The key is unknown at the door, and the error carries UNKNOWN_KEY. Set CARBIUM_KEY to the whole key, copied without a trailing space, and run again. |
| The summary reads zero slots, or it says there are not enough arrivals to measure. | Check CARBIUM_WS_URL. It must be a wss:// address, and the key must be the whole key on the URL. Unset the variable to use the default endpoint. |
| Two watchers in one directory write to the same Graphite file and their lines interleave. | Run one watcher per directory, because each one empties and then appends to the same file name. |
| The run stops in the middle with subscription failed after a few seconds. | The socket dropped. Start the watcher under a supervisor so it restarts, and treat the first gap after a restart as missed slots, not as a burst. |
Questions
Is the batching coming from Carbium or from my app?
Read the slot numbers next to the gaps. Consecutive slots in a clump with quiet time before it point at your reader, while steady gaps near one slot with no clumps mean the feed arrived on time.
Should every slot send a message?
A slot its leader produced sends one notification, and a slot the leader never produced sends none. A missing number in the sequence means a skipped slot, and no message comes for it.
Why is the burst limit 5 ms?
Messages read in one pass reach the handler almost at once, and 5 ms is wide enough to catch those while leaving a real slot gap of about 200 ms alone. Change the constant after a run on your own host.
Can the watcher write to Graphite itself?
No. It writes a plain file in the Graphite plaintext format, and a carbon listener or a relay you run can read it.