Pools and scaling¶
Video: Pools, queues and team limits (1:12).
A pool is a set of identical browsers (BrowserPool) or devices (DevicePool). The operator keeps
each pool sized to demand: a few idle pods waiting, one more for each request in the queue, never
more than the pool's cap.
BrowserPool¶
The chart creates one BrowserPool per entry under pools:. You can also apply them directly:
apiVersion: hearth.testzeus.com/v1alpha1
kind: BrowserPool
metadata:
name: chromium-1-65
namespace: hearth
spec:
engine: chromium
protocol: playwright
playwrightVersion: "1.65"
warm: 2
maxSessions: 50
queueTimeoutSeconds: 120
maxSessionSeconds: 3600
scaleDownDelaySeconds: 300
resources: { cpu: "1", memory: 2Gi, shm: 1Gi }
nodeSelector: {}
| Field | Default | Meaning |
|---|---|---|
engine |
(required) | chromium, firefox or webkit |
protocol |
playwright |
playwright serves Playwright and CDP clients; webdriver serves Selenium (Chromium and Firefox only) |
playwrightVersion |
"" |
major.minor the pool runs, required for playwright pools; clients must match it. Ignored for webdriver |
image |
operator default | Browser image. Playwright pools default to <registry>/hearth-browser:{version}; WebDriver pools to <registry>/hearth-browser-webdriver:<tag> |
warm |
1 |
Idle pods kept ready for new sessions |
maxSessions |
50 |
Most pods (and so sessions) the pool runs at once |
queueTimeoutSeconds |
120 |
How long a request may wait for a free browser before HTTP 429 |
maxSessionSeconds |
3600 |
Longest a Playwright or CDP session may run |
scaleDownDelaySeconds |
300 |
Idle pods above warm are removed after this long |
resources.cpu |
"1" |
CPU request per pod |
resources.memory |
2Gi |
Memory request and limit per pod |
resources.shm |
1Gi |
Size of /dev/shm (a memory-backed volume); browsers crash on big pages without it |
nodeSelector |
{} |
Where browser pods may run |
A pool that is misconfigured (a playwright pool without a valid playwrightVersion, or a
webdriver pool for WebKit) is skipped and the operator logs a warning.
NAME ENGINE PROTOCOL PLAYWRIGHT READY BUSY QUEUED
chromium chromium playwright 1.65 2 3 0
selenium-chrome chromium webdriver 1 0 0
status.starting (pods still booting) is in kubectl get browserpool <name> -o yaml.
Several Playwright versions side by side¶
Clients must match the server's major.minor, so to serve teams on different versions, run one
pool per version, each with an image built for it:
pools:
- { name: chromium-1-65, engine: chromium, playwrightVersion: "1.65", warm: 2, maxSessions: 50 }
- { name: chromium-1-63, engine: chromium, playwrightVersion: "1.63", warm: 0, maxSessions: 10 }
The gateway sends each client to the pool of its version. Clients that do not say (CDP without
?version=) get the newest. The default image tag is the version (hearth-browser:1.63); the
release workflow publishes only the image for the current version, so build and push others
yourself (see Development).
How scaling works¶
Every 3 seconds the operator counts, per pool:
- ready: pods registered and waiting for a session
- starting: pods created but not registered yet
- busy: pods serving a session
- queued: requests waiting for a pod
Then it decides:
idle = ready + starting
wanted = warm + queued
room = maxSessions - (pods alive)
if idle < wanted: create min(wanted - idle, room, 10) pods
if idle > wanted: once that has lasted scaleDownDelaySeconds, remove the extra ready pods
- At most 10 pods are created per pool per pass, so a burst of 500 requests ramps up quickly without flooding the API server.
- Only ready pods are removed, each taken out of the ready set atomically first, so a pod a client is claiming at that moment is never deleted. Booting and busy pods are never removed.
- Any new demand resets the scale-down clock.
- A finished browser pod exits; the operator deletes it and the formula above decides whether to replace it.
- A pod that has not registered with the gateway 10 minutes after it was created (it failed to boot, or the farm's state was lost) is deleted and replaced.
- If a busy pod disappears (deleted, evicted, its node lost), its session is marked failed with
the browser or device went away during the sessionand the team's slot is freed.
The queue¶
When no pod is ready, the request waits in the pool's queue, oldest first, and the queued count
makes the operator add pods. A queued request whose gateway died (and so stopped waiting for it) is
failed after 20 minutes and its team slot freed. The client's connection stays open while it waits. After
queueTimeoutSeconds the gateway gives up with HTTP 429, pool_busy, Retry-After: 15, and a
message with the client's place in line.
A team's maxSessions is checked before the queue: a team at its limit is refused at once and
does not take a place in line. See Teams and keys.
Not built yet
Per-team fairness inside a pool's queue, a queue endpoint with position and ETA
(GET /api/queue), and growing the warm pool from recent bursts are planned. Today the queue
is first come, first served.
Choosing warm¶
warm is the trade-off between cost and wait. Each warm pod holds its CPU and memory request while
idle. With warm: 0, every session waits for a pod to boot: a few seconds on a node that already
has the image, much longer if a new node must join. Start with the number of sessions your CI
starts at once in its first second, and watch hearth_queue_wait_seconds (see
Operations).
Node autoscalers¶
Hearth sizes pods; your cluster autoscaler or Karpenter sizes nodes. Pending browser pods trigger new nodes as usual.
Browser and emulator pods carry cluster-autoscaler.kubernetes.io/safe-to-evict: "false" and
karpenter.sh/do-not-disrupt: "true", so a node with a live session is not drained under it. Idle
pods are cheap to lose but carry the same annotations, so set warm with node consolidation in
mind.
Use nodeSelector to keep browsers on a dedicated node group, sized so a node holds several pods
(for example 8 CPU and 16 GiB for 6 to 7 default pods).
Upgrades replace idle pods¶
Every pod is labelled with a hash of the pod template it was made from (hearth.testzeus.com/template).
When the template changes, for example a new image after helm upgrade or a change to resources,
the operator deletes idle pods made from the old template and creates new ones. Busy pods finish
their session first, then are replaced as they exit. A pod from the old template that has not
registered within 90 seconds is replaced too. Clients see no interruption.
DevicePool¶
Device pools have their own fields, including in-cluster emulators; see
Mobile devices. Emulator pools (cluster: set) scale with the same
formula, using cluster.warm, the pool's maxSessions and cluster.scaleDownDelaySeconds, but
emulators are reused between sessions instead of deleted. Pools of devices on hosts are not scaled
by the operator; their size is what the agents report.