microsoft / microsoft/playwright

feat: add browser pool pre-warming to run-server

Open
#39,499 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

P3-collecting-feedback
Dominant language
TypeScript
Stars
96.3k
Forks
6.5k
Avg merge
1d 6h
Merged PRs (30d)
180

Description

## Problem

When using `playwright run-server` with multiple test workers, all workers launch their browsers at roughly the same time. Each browser launch costs 2-5s of heavy CPU, so N workers starting simultaneously creates a sharp CPU spike followed by idle time — the load profile is spiky rather than saturated.

This pattern repeats whenever workers cycle (e.g. between test files): a burst of concurrent browser launches, then relative quiet. The CPU is either pegged or underutilized, never steadily loaded.

## Proposal

Add `--pre-warm ` and `--browser ` options to `run-server`. When specified:

1. The server launches N browsers into a pool **before** accepting connections
2. Incoming WebSocket clients receive an already-running browser instantly (no launch wait)
3. After handing out a browser, the server replenishes **one at a time** in the background

This smooths the CPU profile: instead of N simultaneous browser launches causing a spike, launches are spread out — one replenishment at a time, overlapping with actual test execution. The CPU stays steadily loaded rather than alternating between spikes and idle.

### Usage

```bash
# Pre-warm 4 browsers before accepting connections
npx playwright run-server --port 3333 --pre-warm 4 &

# Workers get instant browsers, replenishment happens in background
PW_TEST_CONNECT_WS_ENDPOINT=ws://localhost:3333/ npx playwright test
```

### Behavior

- Pool browsers handed out FIFO to connecting workers
- Background replenishment after each handout (one at a time, not all at once)
- Falls back to standard on-demand launch when pool is empty or client requests a socks proxy
- `--pre-warm 0` or omitting the flag = current behavior, no change to default path

## Motivation

We run a CI setup where a single `run-server` instance serves multiple test workers on the same machine. The goal is to keep CPU utilization high and steady rather than spiky. Pre-warming + serial replenishment achieves this by decoupling browser startup from test worker connection timing.

I have a working implementation and can open a PR if there's interest.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the run-server entry point and trace how browser launches, WebSocket connections, SOCKS-proxy requests, and server startup are handled. The payload names no files or tests; completion means implementing the stated pre-warm, FIFO handout, serial replenishment, fallback, and unchanged-default behaviors.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli, testing-qa
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.