Our sleeping apps took 43 seconds to wake. The network policy engine was why
Apps with a database woke in 43 seconds at the median, and kube-router's 111-second policy syncs were most of it. How we measured it, tested Canal and Cilium on a copy of production, and switched.
Free apps on our platform go to sleep when nobody visits them for a while, and the next visitor wakes them up. That's how we can offer a free plan at all. It's also a promise: the person opening the page is waiting, and every second of that wait is ours.
I set a target of every wake under 10 seconds. On 6 November we measured how far away we were.
The baseline
Over 14 days there were 17,496 wakes started by a visit. The median took 30 seconds. The 90th percentile took 138 seconds. Only 25% finished within 10 seconds.
The split by what a wake had to do was more useful than the total:
| The wake | p50 | Within 10 s |
|---|---|---|
| No database, no files, same server as before | 5.8 s | 60% |
| Keeps files, same server | 18.6 s | 34% |
| No database, landed on another server | 35.3 s | 25% |
| Linked database, same server | 43.0 s | 2% |
| Linked database and files, same server | 50.0 s | 1% |
The simple case was already fine. Anything with a database was terrible: 2% of those wakes made it under 10 seconds. A database boots in about 10 seconds, so the database itself couldn't explain 43.
Where the time went
We watched 12 wakes live and followed the pod events and phase times. The trigger was fast, the pod existed before we had even written the wake row. Seven of the 12 had to download their image again, between 3 and 34 seconds, because workers ran at 63 to 83% disk and the kubelet throws away the least recently used images first, which is exactly a sleeping app's image. That's a real problem, but a separate one.
The big one was an init container called wait-for-database. Its job is to hold the app until the database answers. Over the day it took 32 seconds at the median and hit its 300-second cap at the 90th percentile.
The database was up. It just refused the new pod.
We run k3s, and k3s ships kube-router as its NetworkPolicy engine. Every account gets its own namespace with a fence around it, so we had about 6,500 NetworkPolicies, and 88% of them were in namespaces with no running pod at all, sleeping accounts. kube-router does a full sync: whenever any pod starts or stops anywhere, every server rebuilds every policy. Until the database's server had finished that rebuild, the new app pod's address simply wasn't on the allow list.
That sync averaged 111 seconds across the fleet, between 78 and 233 seconds per server. In October it had been 37 to 54 seconds. It grows with every account we add, so this was only going to get worse.
Two more things fell out of it. The k3s agent, where kube-router runs, used 1.3 to 1.8 of every worker's 4 cores, 21.5 cores across the fleet. And the same sync delay works the other way round: a probe showed a brand-new pod is not fenced itself for about 93 to 107 seconds, until its own server syncs. A slow policy engine is not only a performance problem.
No kube-router setting fixes this. Syncs are always full, and k3s hard-codes the options it starts kube-router with.
Two fixes that weren't enough
This wasn't the first time kube-router showed up. In October we had already seen new pods refused by their own database on another server for about a minute. Back then each server held 3,650 policies, and only 142 of 1,704 namespaces had a pod. The fix was to take the policies away from namespaces without pods for an hour and write them back before the next pod starts. It worked, and then sign-ups pushed the count up again.
In November the first change was the same idea one step further: accounts whose apps are all asleep lose two allow policies until their next pod. That took about 2,700 policies out of every sync. It helps, but every sync still covers every server's policies, and the count keeps growing with every account. We needed an engine that only programs the pods on its own server and applies small changes instead of rebuilding everything.
Testing on a copy of production
I didn't want to pick between Calico and Cilium from blog posts. So we built a throwaway test cluster: three small cloud servers with the same k3s version and the same gVisor runtime as production, loaded with production's 2,832 namespaces and 6,544 policies, and a pod created and one deleted every 15 seconds on each worker to imitate real churn. A fresh pod timed how long until it could reach a database pod in its namespace on the other worker, and how long it could still reach something its fence should block.
| kube-router | Canal | Cilium | |
|---|---|---|---|
| New pod reaches its database | 50-64 s | 0-10 ms | 10-20 ms |
| New pod unfenced for | 63-70 s | 0 | 0 |
| k3s agent CPU per worker | 1.06-1.13 cores | 0.07-0.14 | 0.04-0.10 |
| Memory used per worker | 1.2-1.3 GB | 0.8-0.9 GB | 1.1 GB |
Both alternatives were in a different league. Seconds to milliseconds. Our isolation checks (own database open, other accounts closed, port 25 closed, cloud metadata closed, DNS open) passed on both.
We picked Canal, which is Calico's policy engine Felix on top of flannel's VXLAN. The reason was boring and practical: it keeps flannel's tunnel on the same port, so pods started before the switch keep talking across servers the whole time. With Cilium's own tunnel, every running pod would have needed a restart before it could reach the others again. Canal also used about 250 MB less memory per server. Cilium is the more capable system. For the problem we had, Canal was the smaller and more reversible step.
The switch
We wrote the migration as a script with one step per phase and rehearsed it on the test cluster:
./migrate.sh status # before: kube-router rules on every node
./migrate.sh bookings # copy pod IP bookings, enable proxy_arp
./migrate.sh flip # restart k3s without its network policy controller
./migrate.sh canal # wait until every canal pod is Ready
./migrate.sh flush # remove kube-router's leftover rules
./migrate.sh roll # restart workloads node by node, then verify
The rehearsal found three traps, and I'm glad it did.
First, flannel and Calico book pod addresses in different folders. Without copying the bookings across, Canal handed out the address of a pod that was still running. On the test cluster CoreDNS got the metrics server's address.
Second, old pods sit on the cni0 bridge and think the whole /24 is their local link, so they ask for a new pod's address by ARP, and nobody answers. This one line fixed it:
sysctl -w net.ipv4.conf.cni0.proxy_arp=1
Third, kube-router's rules stay behind when it stops. Each old pod kept a frozen list of allowed sources and refused new pods. Three of those leftover rules accepted any packet carrying kube-router's mark, which would have let marked traffic past Calico. flush removes all of them.
We ran it in production on 7 November, starting around 01:00 UTC. It didn't go perfectly. Calico's node agent asked for 250m CPU, and some of our servers were already at 97% of their CPU requested. Three servers went NotReady for 10 to 30 minutes, and about 60 pods with account disks were down from 01:04 to 01:29. We lowered the request to 50m and carried on. The platform's own URLs answered every one of 1,210 checks between 00:55 and 02:56.
After
In the days after the switch, timed wakes on the free plan looked like this: no database p50 8.1 seconds, with files 10.5 seconds, with a database 18.1 seconds. That's a slightly different cut than the baseline table, free-plan wakes only, so compare with care. But database wakes went from 43 to 18 seconds at the median, and the policy wait is gone. What's left is the database booting, the app booting and image downloads.
So no, we're not at "every wake under 10 seconds". The target stays.
What I'd do differently
Replace the thing instead of tuning around it. We saw kube-router's sync delay in October and made it smaller by removing policies. That bought us a few weeks. A component whose work grows with every customer you sign up needs replacing, and the second workaround was the moment to say so.
Check per-node CPU requests before rolling out any DaemonSet. Those 25 minutes with disk pods down came from one number in a manifest, not from the migration itself.
And build the test cluster. It took about 15 minutes to create and found three traps that would each have caused an outage in production.
If you want to know how sleeping and waking works for your own apps, the limits page has the details.
Read next
blitz.cloud plan limits - apps, memory, storage and databases
Exact limits of the blitz.cloud free plan: apps, memory, storage and databases. How memory is reserved per app, CPU, and what is not limited.
Managed databases on blitz.cloud - PostgreSQL, MariaDB, Redis
Create managed PostgreSQL 17, MariaDB 11.4 or Redis (Valkey 8) databases on blitz.cloud, connected to your app automatically and backed up every night.
Deploy an app with a PostgreSQL database
Host an app with a managed PostgreSQL 17 database on blitz.cloud. DATABASE_URL is set for you, the database is private to your apps and backed up nightly.
Put your first app online today.
Start on the free plan, no credit card. Move to Pro when an app has to stay online.
Put your app online