Skip to content

Learn each Hive node's rate limit and route within it instead of overrunning the fastest node #128

Not planned

Description

@feruzm

Problem

The Hive node pool sends each call to the fastest node that is not parked. A node's rate limit is per client IP, so the fastest node takes the whole stream, overruns its limit within seconds, answers 429 and gets parked. Then the next node gets everything.

Observed in production:

  • A large share of node calls are answered 429, each one a wasted round trip that also delays the read.
  • api.hive.blog is the fastest node and one of only two that serve bridge.*_v2, yet it answers only a tiny share of calls. When its park ends it takes a burst of roughly 50 calls within seconds, then answers 429 and is parked again for 40 to 60s. It accepts a full burst again after each park, so its sustainable rate is well above what we get from it.
  • api.hive.blog sends no Retry-After, so its park comes from our own 10/20/40/60s escalation.

There is also a small bug in NodeHealthTracker.RecordRateLimited: a 429 that carries Retry-After still advances the escalation streak. After a few of those, one header-less 429 jumps straight to a 40 or 60s park. The SDK's tracker only advances the streak on header-less 429s.

Proposal

Give each node a sending rate the process learns, and route within it.

  • Learned rate per node (additive increase, multiplicative decrease):
    • start at a moderate rate, for example 5 calls/s
    • raise it slowly while calls succeed, for example +0.5/s per clean window
    • halve it on a 429, and also park for Retry-After when the 429 carries one
    • keep a floor so a node is never starved, and a ceiling
  • Routing: among nodes with rate left, the fastest by the existing latency EWMA wins. If no node has rate left, wait briefly (short cap, for example 250ms) for the first one to free up; past the cap, send anyway as today.
  • Heavy calls cost more: a Heavy call class call counts as more than one unit against the rate.
  • Visible: /ssr/stats shows each node's learned rate and current use, so the effective limit of every node can be read without load-testing anyone.
  • Bug fix: a 429 with Retry-After no longer advances the escalation streak.
  • Several processes behind one IP share each node's limit. Additive increase with multiplicative decrease converges to a fair share without coordination, so no shared state is needed.

Acceptance tests

In EcencyApi.Tests (alongside HiveRpcFailoverTests.cs), with a fake clock and fake nodes:

  • A node that allows N calls per second, faced with demand of 3N/s, settles at a learned rate between 0.7N and N, and the share of 429s after warm-up is under 5%. Today's routing gets well over 30% on the same scenario.
  • Two nodes, the faster one limited: calls spill to the slower node once the faster one's rate is used, instead of the faster one being overrun and parked. The faster node serves continuously, never in burst-then-park cycles.
  • A 429 halves that node's learned rate. Successes raise it back.
  • A 429 with Retry-After: 3 parks for 3s and does not advance the escalation streak: a later header-less 429 parks for 10s, not 20s or more. (Fails today.)
  • When every node's rate is used, a call waits at most the cap and then still goes out.
  • A Heavy call uses more of the rate than a Cheap one.
  • /ssr/stats exposes the learned rate per node.

Out of scope

  • Persisting learned rates across restarts (could follow if warm-up turns out to cost much).
  • The SDK's own node routing, filed separately in ecency/vision-web.
  • Adding or removing nodes from the pool.

Activity

  1. feruzm commented on Nov 20, 2026

    @feruzm
    MemberAuthor

    Two items in this issue are superseded by #129, on purpose:

    • Heavy calls do not cost more of a node's rate than cheap ones. The limiters in front of public Hive nodes (nginx limit_req, Caddy) count requests, not their cost. Weighting heavy calls would make the pool hold back below what a node actually allows.
    • A 429 with Retry-After still advances the park ladder when it repeats with no answer in between. The first such 429 is honoured exactly. A node that keeps refusing every call while naming a short wait is refusing us, header or not. Without the ladder it was retried every second; with it, the park grows as for any other refusal.

    The acceptance test about the wait was also dropped: waiting for rate to come back made concurrent calls wake together, and most still found none, so the PR sends over the rate at once instead.

  2. reopened this on Nov 20, 2026
  3. feruzm commented on Nov 25, 2026

    @feruzm
    MemberAuthor

    Revised proposal (replaces the learned-rate design above, which was reverted in #130)

    Some public nodes limit a client to a fixed number of calls per rolling window. A rate learned by AIMD cannot see a window like that, so it keeps probing past it. Instead, give each node a window cap: count the calls sent to it in the last 60s, and stop sending once the count reaches what the node accepted when it last said 429.

    • Count: every request is counted at send time. A request answered 429 is refunded, since the node did not count it either.
    • Learn on 429: the count at that moment, if it is at least 100, becomes the cap (or lowers an existing cap). Below that it is treated as a burst or a passing episode, and the park works as today.
    • Route within it: a node at its cap is skipped like a parked node, with no request sent and no penalty. It remains a last-resort candidate when no other node can take the call.
    • Adapts upward: once the node has been held at its cap for a full window with no 429, the cap grows by half, so a raised limit is followed within minutes.
    • Adapts downward: a 429 below the cap lowers it.
    • Bug fix: a 429 with Retry-After no longer advances the escalation streak.
    • Visible: /ssr/stats shows each node's window_cap and window_sent.

    Acceptance tests (revised)

    EcencyApi.Tests/NodeWindowCapTests.cs, fake clock:

    • A node with no 429 yet has no cap.
    • A 429 after a full window sets the cap. A further call is skipped as at-cap (no request) and admitted again once the window has moved on.
    • A 429 after fewer than 100 calls in the window sets no cap.
    • A 429 at a lower count lowers the cap.
    • A node held at its cap for a full window without a 429 has its cap raised by half. An idle node's cap does not grow.
    • A last-resort probe is admitted past the cap.
    • Retry-After: 3 parks for 3s and does not advance the streak: a later header-less 429 parks for 10s.
    • The snapshot exposes the cap and the window count.
    • Client level: a window-limited node and a healthy second node under concurrent load. The limited node answers a handful of 429s instead of a batch each time its park lapses, and still serves what it accepts.

    Out of scope: persisting caps across restarts, the SDK's own routing (vision-web#2153), pool membership.

  4. reopened this on Nov 25, 2026
  5. feruzm commented on Nov 30, 2026

    @feruzm
    MemberAuthor

    Closing. The load reduction in #134 (together with fewer lookups per page on the web side) brought rate-limited answers from the public nodes down to a small fraction of what they were, with the same number of calls answered. What is left comes mostly from nodes with a fixed per-window limit, and is too small to justify per-node rate learning or a window cap, both of which made routing worse under production concurrency (#130, #133). Can be reopened if demand grows past what the pool can serve again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions