Testing for 100,000 services we don't have yet
The hardest minute for an ISP's software is the one after nbn drops an area. Every router in it loses its session at once. When nbn fixes the fault, every one of them asks to come back at the same moment, and every customer behind them needs to be told what happened: by a notice, in their support conversation, or through their provider's webhook.
That's the minute the platform is most likely to fall over, and the minute customers most need it not to.
We don't have 100,000 services. I wanted to know where Underlay would fall over before a customer found out for us, so we built a harness that runs Underlay as if 100,000 services were on it, fixed what it found, and turned what it measures into gates that fail the build if anything gets worse.
This is how the harness works, how we got the numbers, what it found, and what it can't tell us.
The rule: nothing on the network
My rule for the project was no BNG Blaster, nothing on our development or production hardware, and nothing on our network. What I asked for was "gates and checks we can run locally, or in CI, to make sure it never gets worse. So we profile them and then we can push them as minimums." A Mac was fine. Whatever the harness found, we'd fix in the same project.
A load test against real kit gives real numbers once. It's noisy, and blind to causes: one more query on every login looks like a busy afternoon. We wanted numbers that can't flap, checked on every change.
The harness may not send a packet to our BNG, our edges, our CGNAT pair or production. Everything it talks to is the real code under test or a fake on 127.0.0.1.
Where we started
Before building anything, we read the code for what would break first. It wasn't flattering:
- CI ran
make vetand built the images. It ran no tests, and there wasn't a benchmark in the repository. - radiusd, our RADIUS server, started a goroutine for every packet, with no limit. A request had no deadline, the database had no statement timeout, and the pool had 12 connections.
- An Access-Request took 9 to 16 round trips to the database, and an accounting Interim 14 or 15.
- A CoA or Disconnect had no timeout. One router that never answered would hold up every one after it until radiusd restarted.
- Twelve services sending their first traffic at once would deadlock radiusd. Marking a service online held a transaction on one connection and read its welcome email's details on a second, so twelve would hold all 12 connections, each waiting for a 13th, and every login would wait with them.
We wrote each problem down with the test that would reproduce it: 36 in all, ranked. Eight were bugs already, 24 would break at some size, and 4 would only get slowly worse.
What comfortable at 100,000 means
We seeded the shape we expect, not just the count: about 20,000 accounts, with 10 resellers holding 60% of the services. 88% active and the rest in every other state. 60% on our CGNAT, 20% with a public IPv4, the rest on their own addresses, Layer 2 or not nbn at all. PPPoE on a tenth of the Layer 3 services and latency monitoring on every live one, then private networks, domains, a year of invoices and 90 days of history.
Our next BNGs come at about 5,000 subscribers each, so 100,000 services is 20 BNGs: 79,206 subscribers with a session, and 165,900 open sessions in all.
At that size, seven bars all had to pass:
| Bar | |
|---|---|
| 1 | Every gate passes: at 10,000 services in CI, and at 100,000 on the Mac |
| 2 | Steady accounting uses no more than a quarter of radiusd's measured capacity |
| 3 | One BNG's storm of logins: no timeouts inside the BNG's retry window. All 20 at once: every subscriber back within 10 minutes, nothing wrong |
| 4 | Every background loop finishes inside its period with at least 2× to spare |
| 5 | Every process peaks at 60% of its memory limit or less |
| 6 | Postgres: projected size at full retention under half the volume, no sequential scan of over 10,000 rows on a hot path, connection waits bounded |
| 7 | Prometheus fits the latency series, and the edges' desired state builds and applies in time |
The second half of bar 3 was my call, halfway through. If every BNG drops at once, recovery may take up to 10 minutes, as long as it's 100% correct: no wrong answer, no deadlock, no session lost or filed under the wrong service, no crash. Timeouts and retries on the way are fine. A router taking a minute to come back after an outage is normal. A session filed under someone else's service is wrong, and stays wrong.
Gates that can't flap
A gate is a Go test next to the code it gates, built only with -tags scale. It seeds a world on a fresh schema, runs one operation, and counts what that did to Postgres. A tracer on both of the store's connection pools sees every statement:
- Statements, rows and transactions, and the store function behind each statement, so a failure names the call that changed.
- Connections held at once. An operation that holds two connections from one pool fails when its test ends, unless it's listed with a reason. That's the first-traffic deadlock, gated everywhere.
- Plans. auto_explain logs each statement's actual plan, with buffers, as a JSON notice, and the tracer hangs it on the statement running on that connection. A gate can refuse a sequential scan of over 10,000 rows, a sort spilling to disk, or a sequential scan inside a loop. The planner's settings are pinned, so a Mac and a CI runner plan alike.
- Growth. At N and 10N, statements and rows mustn't grow, and buffers may grow by one B-tree level.
- Notify commits. Postgres serialises the commit of every transaction that sends a NOTIFY, so a storm's signals mustn't send one each.
- Allocations, exactly, per CPU architecture, on paths that never touch the database.
The gate behind the key in the next section, trimmed:
ctx, _ := scale.Scope(context.Background(), key)
// ...
st, err := scale.Count(ctx, func(ctx context.Context) error {
d = srv.decide(ctx, id)
return nil
})
// ...
scale.RequireOneConn(t, st)
plans := db.Plans(t, st).NoSeqScan(10_000).NoExternalSort().NoSeqScanInsideLoop()
scale.CheckStats(t, key, st, plans)Wall time is never gated in CI, apart from deadlines at least 10 times what a run should take. Throughput is measured on the Mac, and recorded.
The ratchet
Every gate's numbers are committed beside it. This is the first one we recorded, before we'd changed anything: the DHCPv4 pass of a home CGNAT service, at 10,000 services.
"radius/auth/ipoe/home-cgnat": {
"statements": 9,
"tx_control": 0,
"rows": 11,
"max_conns": 1,
"notify_commits": 0,
"buffers": 58,
"calls": [
"FindLiveNbnServiceByAVC",
"ListOpenSessionsByService",
"PoolForService",
"PoolForService",
"ServiceNetwork",
"ServiceNetwork",
"ServiceNetwork",
"NbnSpeed",
"V6DNSForService"
],
...
}Nine statements, one after another, with the same calls made twice and three times. Today the same key is one statement and 46 buffers, or 52 at 100,000 services.
Statements, rows, connections, notify commits, the calls and the plans' shapes must match exactly. Buffers may move by a quarter, plus four. A worse number fails, naming what changed and giving the command to record it on purpose, in a commit of its own titled scale: raise <key>: <why>. A better number fails too until it's recorded, or a slide back to the old number would pass. A key no test checked fails, and CI never records anything.
There are 157 baselines at each size. Over the project, 21 commits raised one on purpose, each with its reason, such as scale: raise nbn/order-sync/pass: an order read lets go of its lease when it's done (one statement more per order read).
CI runs it all on every change to the Go code: the unit tests, the database suite in four shards and the scale gates in four more, each job on its own Postgres 17 in memory, with durability off, since counts don't depend on the disk, and autovacuum off, since the gates analyze what they seed. On the Mac, make scale-big runs every gate again at 100,000 services against baselines of their own. It fails past an hour, and took 42 to 43 minutes when we timed it.
Seeded worlds are deterministic, from a fixed seed. The gates' 100,000-service world seeds in 23.8 s on the Mac, plus 9.7 s to analyze, with synthetic addresses from 198.18.0.0/15 (set aside for benchmarking), 100.64.0.0/10 and 2001:db8::/32.
Twenty BNGs on a Mac
Counting statements tells you a login got cheaper. It doesn't tell you whether 79,206 routers can log in at once. For that we wrote a BNG simulator.
Each simulated subscriber is a small Junos state machine that sends what our MX204 sends, attribute for attribute: the VLAN, DHCPv4 and DHCPv6 passes for IPoE; the PADI's VLAN pass, the PPP login and DHCPv6 over it for PPPoE; Starts with an Interim straight after, an Interim every 600 s, Stops with their causes, and Accounting-On and Off. Each simulated BNG's RADIUS client behaves as our MX204's does: 2,000 requests outstanding, a 3 s timeout, 3 retries, identifiers reused only once answered or given up on. It answers CoA and Disconnect, and a fake router renders its subscribers as XML for our reconciler to read over NETCONF.
Twenty BNGs need twenty source addresses. Rather than loopback aliases and sudo, the simulator has a datagram network inside the process, where each BNG binds its own address in 198.18.0.0/15 and radiusd's real server code sees twenty routers. radiusd runs as a child process with its production pod's 1 GiB memory limit, Go's at 80% of it, its pool of 32 connections, and only 2 CPUs. A tunnel over loopback carries each datagram to it with its source address in front.
We handicapped the Mac on purpose. Postgres runs with fsync and synchronous commit on, and radiusd reaches it through a fault proxy that adds 500 µs each way, about a millisecond a round trip, standing in for the network hop between them in production. The same proxy can stall the database mid-storm. Numbers without the handicaps are reported, never gated.
How do you know an answer is right at thousands of packets a second? First the simulator calibrates: it brings every subscriber up slowly and records each Access-Accept. Under load, an answer that differs from calibration's is wrong. No run, from the first, found one.
Two API pods run Underlay's background loops beside it, from the outage detector to the latency history, against fakes of everything outside: routers, Prometheus, our wholesale provider's API with its rate limits, payments, accounting, mail, SMS and the support assistant's model. DNS lookups are refused before they leave the machine, 12,000 of them in the final run.
There are 18 scenarios: steady load and capacity; a CoA flood, and a CoA to a router that never answers; 64 services' first traffic at once; the background loops; an NNI flap, a reboot, a config commit's Accounting-On, lost Stops and reused session ids; a storm on one BNG, on one with its database stalled for 5 s, and on all 20; the full drop; then the database's size, the metrics, and memory last. make scale-report seeds a fresh database and runs them all, with these flags:
SCALE_REPORT_FLAGS = -tier 100k -history 90 -bngs 20 -transport tunnel -db-latency 500us -capacity-step 30s -scenario all -write-summaryIt has an hour. The final run took 27 minutes 26 seconds, 10 and a half of them seeding.
Five of seven
Once all 36 problems had a fix and a gate, we drove the whole stack at 100,000 services, and the first run failed five of the seven bars:
| First run | After | |
|---|---|---|
| radiusd's capacity, Interims a second | 2,500 | 7,250 |
| One BNG's storm of 5,000 | 375 timeouts, 4,625 up | No timeouts, all up in 4.1 s |
| All 20 BNGs at once | 5,590 of 79,206 up after 27.8 s | All 79,206 up in 50.1 s |
| Their requests that ran out of tries | 73,616 | 0 |
| The outage detector on a mass drop | About 260 signals a second | 9,908 downs in 170 statements |
It wasn't the handicaps. With them off, all 12 cores and no added latency, 17,841 of the 79,206 came up.
The second run failed four bars. The third failed one, and that one was our gate's fault. The fourth passed all seven.
The storm
Twenty BNGs with 2,000 requests outstanding each is 40,000 requests in flight, and a subscriber takes about seven to come up: 565,021 requests for 79,206 subscribers in the final run. Each request gets four tries, 3 s apart. A subscriber whose request runs out of tries stays down until its router starts over.
Five changes got radiusd there.
One read per request. An Access-Request read its service, open sessions, PPPoE pin, placement (three statements), speed and IPv6 resolvers one at a time. Now it reads everything its answer needs in one statement, and each fact only if its answer carries it. An Access-Request or an accounting packet is one to three statements. A service's first Interim, which marks it online and queues its welcome email, went from 12 statements on two connections to 5 on one.
Don't wait for the disk when the next packet says it again. On the Mac, a commit that waits for the disk took 5 to 56 ms, and one that doesn't 0.07 ms, and in one storm Postgres spent three quarters of its time waiting on WAL writes for Starts. But an Interim's counters are cumulative, so the next Interim or the Stop carries whatever a crash just after it would lose, and every Start is followed straight away by an Interim that writes it again. So Starts, Interims on an open session, the pin a PPPoE PADI leaves and the RADIUS log's rows now commit with synchronous_commit off, for that transaction only. Stops and everything else still wait. One BNG's storm went from about 850 requests a second to between 2,705 and 3,548, with no retries.
Admission control. radiusd now reads its own sockets, and drops a datagram from an unknown source or with a bad authenticator before doing any work. It runs as many handlers as its pool has connections, so none waits for a connection behind another, and serves per-BNG queues in turn, so one BNG can't starve the rest. A request waits at most 2.5 s for a handler and 1 s for each database connection, and is answered within 2.75 s of arriving or not at all, so an answer never crosses the BNG's retransmit at 3 s. From radiusd's source, comments trimmed:
requestBudget = 2750 * time.Millisecond
maxQueuedPerNAS = 2048
maxQueueWait = 2500 * time.Millisecond
maxTries = 4
shedMemory = 10 * time.Second
const MaxDBWait = time.SecondRetries first. When a storm is bigger than radiusd can answer at once, something has to be shed. The first run shed each try with the same odds, so a request could lose all four. Now a request whose earlier copy went unanswered comes back ahead of first tries, highest try first, and a shed request is remembered for 10 s so its retransmit counts as its next try. A storm sheds new requests, whose routers ask again in 3 s, and finishes what it started.
Silence, not a wrong answer. A failed lookup used to get an answer anyway: an Access-Reject, or an Accept in the wrong routing instance or at the profile's 1 Gbps default instead of the service's shaping. Now it gets none, and the router asks again.
The second run got one BNG's storm to no timeouts and capacity to 7,000 a second, but twenty BNGs at once still left 58,883 subscribers down. Part of that was Starts waiting for the disk. The rest was three bugs no quiet test would show:
- A retry that couldn't get through. radiusd remembered every Access-Request for 5 s, to drop retransmits. But a retransmit of a request in progress was already dropped, and one of a request already answered got its answer again from a cache, so the only copies it ever dropped were routers asking again for requests that had gone unanswered. Their second try never got through, and often not their third.
- Most of a gigabyte of nothing. A retransmit replaces its earlier copy if that's still waiting, but the old copy stayed in its queue, packet and all, and in a storm the first tries' queues were never reached. radiusd peaked at 926 MiB of its 1,024.
- A writer that never handed over. radiusd writes its log in batches: whichever handler starts a write takes everything pending. In a storm the first one kept writing every batch that arrived until the storm ended, while its own request waited. Two gates each lost exactly one request to it, on every try.
In the final run, steady accounting at 100,000 services, an Interim from every session each 10 minutes, was 276.5 a second: 3.8% of the 7,250 radiusd held with a 99th percentile under a second. One BNG's 3,958 subscribers came back in 3.2 s. All 20 BNGs came back without a timeout, though 308,440 of their 565,021 requests were retries, and radiusd peaked at 291 MiB.
Bar 3 allowed more than one radiusd if it needed it. It didn't, and two were worse: with two replicas of 2 GiB each, every subscriber was back in 3 minutes 53 seconds, where one of 1 GiB took 56 to 72 s in the same round. Two pools of 32 connections against one Postgres meant longer waits for a connection, more lookups cut short and 16,122 transactions rolled back. More radiusd needs more database, not more pods. We run one.
The full drop
This is the minute the post started with, made worse: every BNG at once, not one area.
The full-drop scenario takes every subscriber on every BNG down, then has all 20 BNGs send Accounting-On and storm together. A subscriber that misses all four tries logs in again, as its router would, with its half-built sessions stopped first, wave after wave until everyone is up or 10 minutes have passed. Then every open session sends one Interim, paced at 2,000 a second, and every BNG's sessions are held against the database's, one by one. From the final run's report (B11 is our design notes' name for this half of bar 3):
- B11 recovery, all 20 BNGs: 77985/79206 subscribers up after the first wave; 79206/79206 up in 47.835s (2 waves at most); every subscriber up: true, the last BNG at 47.835s (bound 10m0s)
- B11 Interim round: 165900 Interims at 2000/s in 1m22.952s, 0 unanswered after every try
- B11 correctness: 165900 sessions checked; 0 missing from the database, 0 filed under another service, 0 with no service, 0 of another kind, 0 with other counters after an answered Interim, 0 open rows no BNG has (and 0 a lost Stop's: unanswered after every try, the janitor's), 0 on subscribers not up (not held to anything); 0 answers wrong; deadlocks +0; radiusd exited 0Everyone was back in 47.8 s, against a bound of 10 minutes. 1,221 subscribers needed their router to log in a second time, and none a third.
Telling everyone
When a subscriber's session ends, radiusd records a signal. The outage detector gives the service 3 minutes' grace to come back, then opens an outage, and the outage pipeline does the telling: the service.down event to the provider's webhooks and feed, the notices, the support conversation. Our wholesale terms promise providers those events within 5 minutes of recording them, and that has to hold on the worst day, not an average one.
The detector. In the first run it handled about 260 signals a second, each with statements of its own, and one pass held the leader's lock for the whole 300 s. It now takes signals in batches of 1,000, where a down followed by its up collapses to the outcome before anything is written. Outages open a page at a time in one statement, and a pass stops at 5 s so the next can start. 9,908 downs at 100,000 services cost it 170 statements.
The outage pipeline. Each outage's hooks ran on their own, about 54 statements each. A round's hooks now run as one batch, each read made once and each write one statement for all of them, in one transaction. A 10,000-service drop went from 536,544 statements to 12,782, on one connection, and the last service.down from 2 minutes 24 seconds after grace to half a second after it.
Notices. One limit, 100 texts an hour, covered every text we send. A mass outage could use it up and leave new customers without their sign-up codes, and a text past it was dropped without a record. Codes and bulk texts now have limits of their own, and a bulk text waits up to 6 hours or is skipped with its reason recorded. Email has a rolling daily budget, with 500 kept for codes, and a reseller with 6,000 services in a mass outage now gets one digest, not about 240 emails.
The reconciler. Every 2 minutes, the API reads each BNG's subscriber list over NETCONF and compares it with our sessions. After a storm, a router knows subscribers whose Start we never heard, and each cost three statements: 18,712 for a poll of 20 BNGs with 5,000 each. A poll of 20 is now 221 statements, the same at 100 subscribers a BNG as at 5,000. Parsing the list was quadratic, building a string one XML token at a time: 8.5 s for 4,000 subscribers, about 53 s projected at 10,000, against 60 s for the whole read. It streams now, and each simulated BNG's list of about 4,300 took 250 to 707 ms.
One more reconciler bug belongs in this story. Junos sends Accounting-On on some config commits with sessions still up, and our database closes them all until their next Interims reopen them. If a router's list had failed to read twice running, our rule took those closures as real: one commit while a router was unreadable would have marked every subscriber on it down, with notices and texts to match. Those closures now go to review, judged on the router's next read or on 25 minutes without accounting.
Everything else it found
Not all of it was RADIUS. Some of the rest:
| What | Before | After |
|---|---|---|
| The edges' desired state | About 7 queries per latency target, rebuilt every minute on every pod. Finding each home device's owner read every service its reseller had: 2.4 s of a 2.9 s build | 14 statements whatever the region holds, built once a revision: 415 ms at 100,000 |
| Accounting history | Every Interim stored as a row, pruned by one unbounded DELETE an hour | No Interim rows. Usage rolled up hourly, raw events partitioned by day and dropped a day at a time |
| Postgres at full retention, 100,000 services | 55.3 GiB projected | 31.4 GiB, under a third of a 100 GiB volume |
| Prometheus, a latency service | About 42 series | At most 8, 4 from each edge: 800,000 at 100,000 services, 48% of the 28 GiB we'd give Prometheus |
| Accounting system calls, an invoice | 5 | 2 |
| Connections | Every pod's pools could add up past Postgres's limit unnoticed | A gate renders the Helm chart and fails if they could, a rolling deploy's extra pod included |
Not all of the storage drop was a fix. The latency history's tables carried dead rows between vacuums, and packing them took its history from 304 to 205 KiB a service and the projection from 55.3 to 47.9 GiB. The rest was our measurement: the gate charged each table's first pages to every one of its 100 services, and at 1,000 services it came to 31.4. That's with closed sessions kept two years, as the data retention law requires, and the activity log seven.
The harness got things wrong too
A harness is code, and it had bugs of its own:
- It broke its own rule. In the second run, the API pods' reconciler dialled the fake routers' synthetic addresses over the real network, out of the Mac's default route. Nothing answered, but it shouldn't have tried. NETCONF now opens only to 127.0.0.1, and a router anywhere else is refused before it's dialled.
- It measured capacity during autovacuum. The third run measured 750 packets a second three minutes after seeding 20 GiB, while autovacuum read the new tables. Settled, the same world did 6,500. The simulator now waits for autovacuum and a checkpoint before it measures anything.
- It couldn't measure the full drop. Its 20-BNG storm brought each subscriber up once, so one that missed four tries stayed down. Nothing logged it in again or checked the sessions afterwards, and at 100,000 its setup ran out of its own 2-minute deadline. The full-drop scenario came out of that.
- Its numbers moved. The gate counting the reconciler's statements read 201 one run and 202 the next, depending on what the storm before it left. Buffers moved by a quarter with autovacuum's timing, and a plan's baseline named the day's partition and broke the next day. That gate now starts from the same state every run, gates that change rows vacuum before they measure, and a plan that names a day can't be recorded.
Shipping it
We rehearsed the release on the Mac against a copy of production's schema, with synthetic data in production's shape: the migration with the old radiusd writing beside it, a rollback to the old version on the migrated schema, and forward again. Reviewing the runbook turned up three things that would have hurt on the night:
- The migration had to go first. radiusd has no readiness probe, so when it rolls, the old pod goes as soon as the new container starts. A migration that met a busy table would retry for up to 2 minutes and then crash-loop, with RADIUS unanswered throughout. So the migration ran first, as a Job of its own, while the old API and radiusd carried on.
- Postgres's restart would have waited on connections that never close. The release gave Postgres more connections and memory, which restarts it. CloudNativePG first stops it with a smart shutdown, which refuses new connections and waits, 180 s by default, for the old ones to finish. Our pools keep theirs open, so it would have waited out the 180 s refusing everyone new, and a radiusd pod that can't connect when it starts exits and crash-loops. We set
smartShutdownTimeoutto 10, and the runbook says to replace a crash-looping radiusd at once. - A provisioning script would have dropped every private network's routes. Our edge setup script wrote its template
frr.confandkeepalived.confover the ones the edge agent renders and reloaded both, taking every network's VRF and EVPN routes away until the agent's next apply, up to a minute later. It now leaves those files to the agent.
It went out on 21 November.
What it doesn't tell us
- A Mac isn't production. Its wall-clock numbers are baselines to compare our own runs against, not promises, which is why CI gates on counts.
- The BNG itself. Its login rate, routing engine and queues weren't tested: the harness tests the software behind the BNG, with the BNG simulated. Our CGNAT's data plane has its own numbers.
- Hypervisors, storage and the network between our servers.
- How fast texts go. The harness shows sign-up codes are never blocked by an outage's texts, and that nothing is dropped without a record. It can't make texts go faster than their limit.
- Address space, which is a project of its own.
What it means for you
We still don't have 100,000 services. We've seen what Underlay does with them, on a Mac held to production's limits, worst day included, and the gates keep it there. A change that adds a query to a login, holds a second connection inside a transaction, or turns a lookup into a sequential scan fails CI and names the call, before it gets near production.
If you're an ISP or MSP weighing whether we'll hold up as you grow, that's how we know. Ask us about anything this doesn't answer.
Better to meet the worst day on a Mac than in production.