TL;DR
- Cap browser automation concurrency using explicit runtime slots and a bounded waiting queue.
- Distinguish pending, allocated, accepted, and ended. Only verified terminal cleanup releases a slot in production.
- Treat browser concurrency, page concurrency, and application rate limits as separate budgets.
- Give each admitted job a deadline, one lifecycle owner, and a way to reconcile ambiguous creation or shutdown.
- Record peak active slots, job acceptance, queue age, and time to verified cleanup.
- Start with a small pilot, then adjust the limit against documented account capacity and observed task quality.
What does browser automation concurrency actually measure?
Browser automation concurrency measures the number of units doing or holding work simultaneously. A worker can run one script, a context can hold multiple pages, and a provider can count active browser sessions according to its lifecycle. Specify which unit you are limiting before setting a worker value. Nstdata offers managed browsers with a documented session lifecycle, so a job's slot can be tracked using the resource actually allocated to it.
A typical example runs staging catalog checks during a release. Twenty jobs enter a queue and each needs a browser for a short time. If all jobs launch at once, late cleanup or retries can substantially change how many sessions are active. The goal is a measured rate of accepted tests with predictable cleanup. The browser automation cost guide introduces a useful denominator for relating runtime consumption to accepted work.
Which limits should a browser job scheduler enforce?
A browser job scheduler should enforce separate bounds for waiting work, live provider resources, and operations against the target application. Define a lease from admission through end verification. Set a separate page count only when one job intentionally owns multiple tabs. The Playwright parallel worker documentation explains how local worker parallelism is configured. The Playwright context isolation guide explains what contexts isolate within a browser.
| Control | What it limits | When to release capacity |
|---|---|---|
| Queue size and age | Work waiting to become active | When it is admitted, deferred or explicitly canceled |
| Active browser slots | Managed runtimes reserved or allocated to jobs | When terminal cleanup is verified or allocation confidently failed |
| Page budget | Pages owned inside one independently managed job | When that job's page closes |
| Application action rate | Traffic and side effects against the authorized target | According to the app's published limits and workflow policy |
| Recovery budget | Time a failed or ambiguous operation consumes | After bounded reconciliation or explicit ownership transfer |
Provider limits, test runner workers, and site capacity can each be a bottleneck. Design to the most restrictive relevant condition. If a reliable target offers a separate documented API for a read-only assertion, consider moving the read-only confirmation there. For browser work, do not add slots simply because a visible queue is building.
How do you run a bounded batch with observable cleanup?
Reserve one logical slot before launching a job and return it after that job's cleanup is verified. The sample models five small jobs on two worker slots using asynchronous functions and synthetic outcomes. It is a runnable model of admission and cleanup in one Node.js process. Run it entirely in a local Node.js process before evaluating account capacity.
Step 1. Choose the job boundary
Give each queue item an ID, an approved target, a specific acceptance rule, and maximum queue and execution ages. Separate early rejection from a job that acquired a browser and later failed. Define who retains responsibility if a job times out after a session may have been allocated.
Step 2. Set the slot cap
Pick a low test cap supported by the operator's approved environment. For managed runs, confirm the current workspace policy, supported resource classes, and lifecycle states in the Cloud Browser automation documentation. Treat the sample's two slots as an illustrative application choice. On a real service, avoid using the whole advertised limit if independent workloads share it. Establish how your scheduler will observe capacity rather than assuming every rejection means overload.
Step 3. Run the fixture
Save the example as concurrency.mjs and run node concurrency.mjs with Node.js 22. It creates two workers, keeps results in input order, simulates a failure for job 3, and models cleanup in a finally block. It checks that peak active work is exactly two, cleanup occurred for all five jobs, one failed job remains visible, and the active count returns to zero. The Node.js timers reference describes the Promise-based delay used by the synthetic fixture.
import assert from 'node:assert/strict'; import { setTimeout as delay } from 'node:timers/promises'; async function runBatch(queue, slots, processJob) { if (!Number.isSafeInteger(slots) || slots < 1) throw Error('Positive slot count required'); const results = new Array(queue.length); let cursor = 0; async function worker() { while (cursor < queue.length) { const index = cursor++; try { results[index] = await processJob(queue[index]); } catch { results[index] = { id: queue[index], outcome: 'failed' }; } } } await Promise.all(Array.from({ length: Math.min(slots, queue.length) }, worker)); return results; } let active = 0; let peak = 0; const ended = []; const results = await runBatch([1, 2, 3, 4, 5], 2, async id => { active++; peak = Math.max(peak, active); try { await delay(15); if (id === 3) throw Error('Synthetic task failure'); return { id, outcome: 'accepted' }; } finally { await delay(5); ended.push(id); active--; } }); assert.equal(peak, 2); assert.equal(active, 0); assert.equal(ended.length, 5); assert.equal(results.filter(x => x.outcome === 'failed').length, 1); console.log(JSON.stringify({ peak, results, cleanupCount: ended.length }));
Step 4. Replace synthetic cleanup with actual reconciliation
In production, a worker that throws during stop must keep a managed slot tracked until a controller checks the browser. Report that item as cleanup pending and transfer ownership through a durable mechanism with a new deadline if necessary. The in-process demonstration waits for a successful simulated release. A distributed queue needs atomic admission, leases and a recovery controller so two replicas cannot independently claim the same capacity. Use the browser session lifecycle guide to distinguish disconnection from managed termination.
[Screenshot: Show a synthetic worker trace with two simultaneous jobs, one failed task, and five verified cleanup events. Keep actual account and resource IDs out of the capture.]
What should you do when the queue grows or a provider rejects work?
Classify the cause before raising the browser concurrency cap. A queue can grow because the target became slow, the worker cannot end sessions, attachment is failing, or the service reached a configured limit. Compare queue age with time spent in each state. Defer or reject stale tasks under a documented policy.
| Symptom | Check first | Adjustment |
|---|---|---|
| High queue age while slots stay sticky | Terminal state and cleanup owner | Resolve unconfirmed cleanup before admitting more work |
| Target rejects many otherwise valid jobs | App response and original allowed rate | Reduce per-target pressure and investigate the app outcome |
| Session creation is uncertain | Original request identity and provider status | Reconcile existing allocation before creating another |
| Accepted tasks decline as concurrency rises | Error composition and resource use | Reduce throughput target and pilot one bottleneck at a time |
| Jobs routinely wait longer than useful | Queue deadlines and task value | Expire or defer those jobs rather than rushing them |
Make one owner responsible for the slot between allocation and end. If a browser-create response is lost, follow the item and original request rather than replaying the entire job. The browser automation retry guide describes carrying an operation identity into reconciliation.
Which signals reveal a cleanup backlog?
A cleanup backlog appears when jobs finish faster than the controller can verify termination. Compare the time a page result was accepted with the time the associated runtime became terminal. Count sessions that are finished from the app's perspective but remain allocated in the scheduler. Group causes by observation, stop request and terminal verification so an expired session can be distinguished from an unavailable status check.
Retain a separate cleanup queue with a bounded reconciliation deadline and an owner who can inspect the original session. Keep those slots accounted for while the controller resolves their state. A temporary throughput drop can show that the scheduler protects its runtime budget during a downstream failure.
How does Nstdata Cloud Browser work with bounded browser queues?
Nstdata Cloud Browser provides managed cloud browsers for browser automation and AI agents with documented session discovery, attachment and shutdown. A controller can schedule use against current account policy, pass an owned session to a worker, and confirm termination before admitting the next job. Browser runtime and proxy use can have separate cost components. Keep the queue and application acceptance outside the provider lifecycle so you can measure failed work and pending cleanup. Consult current pricing and usage for the units that apply to your configuration.
- Admission. Associate a reserved slot and existing task ID with each intended session allocation.
- Outcome tracking. Record business acceptance independently of browser state so errors do not disappear from throughput statistics.
- Terminal reconciliation. Retain ownership until the stop result is established, including after a worker or controller restart.
- Usage measurement. Record active runtime and operator effort per accepted task when comparing concurrency settings.
What should your first concurrency pilot establish?
A concurrency pilot should establish that work remains within the chosen live resource cap when tasks pass, fail and take longer than expected to terminate. Use a small authorized queue and a repeatable task with an independent business check. Record peak live slots, queue age, task results, and time to cleanup. Increase the limit only after the existing configuration meets quality and latency requirements.
If the queue remains full, differentiate work blocked on the target from work blocked on browser release. Cloud Browser QA examples are useful for constructing a target result that stays comparable across pilot batches.
FAQ
Q: Is browser session concurrency the same as page concurrency?
Session limits cover provider resources. Page count is the number of tabs a job opens within the browser. Track both when they affect acceptance or capacity.
Q: When can a worker return a production slot?
Return the slot after the allocated runtime is verified terminal or you can determine no resource was allocated. An exited worker alone is insufficient evidence.
Q: Should an HTTP throttling response trigger more browser workers?
Inspect the service policy and the cause of the response. Respect the documented limits and classify the outcome before retrying or changing capacity.
Q: Does this code enforce a limit across multiple hosts?
The sample enforces a cap in one process. A distributed system needs shared admission and leased ownership with reconciliation.
Q: Which metric should guide the next slot increase?
Compare throughput of accepted work, queue age, failure rates, cleanup lag, and usage. Raise the cap only when the test workload can sustain the change.





