How do you set up number of workers in Playwright for optimal test execution? or What's the best way

18 Replies, 858 Views

"What's the best way to set up number of workers in Playwright for parallel testing?"

Hey folks! 👋

So, I've been tinkering with Playwright and trying to figure out how to *set up number of workers in playwright* for max speed without nuking my machine.

From what I’ve seen, just slapping `--workers=4` (or whatever) in the CLI *kinda* works, but is there a smarter way? Like, should I match it to CPU cores? Or is there a sweet spot?

Also, does it even matter if my tests are I/O-bound vs CPU-bound?

Kinda confused rn, ngl. Would love to hear how y'all *set up number of workers in playwright* for your setups.

Thx in advance! 🚀

*(PS: pls no "it depends" answers... gimme some real-world numbers!)*
Hey! So I usually set up number of workers in playwright based on my machine's cores minus one. Like, if I've got 8 cores, I’ll do 7 workers.

But honestly, it *does* depend on your tests. If they’re heavy on I/O (like waiting for APIs), you can go higher. For CPU-heavy stuff, keep it lower.

I’ve also used `playwright.config.js` to tweak workers per project. Helps a ton if you’ve got mixed test types.

Check out Playwright’s docs on sharding too—might be useful!
I just go with half my CPU cores for the set up number of workers in playwright. Works fine for me, but YMMV.

Also, if your tests are flaky, more workers = more pain. Found that out the hard way lol.
For real-world numbers, I run 4 workers on a 6-core machine. Any more and my fans sound like a jet engine.

Playwright’s default is usually sane, but if you wanna tweak, start low and ramp up. Monitor CPU/memory tho!
Pro tip: Use `--workers=auto` and let Playwright decide. It’s smarter than you think!

But if you’re stubborn like me, match it to your cores *minus one* for breathing room. Also, avoid setting up number of workers in playwright too high if your tests share resources (e.g., same DB).
If your tests are I/O-bound, you can *probably* go wild with workers. But CPU-bound? Nah.

I’ve had success with `--workers=2 * cores` for API tests, but for E2E, I stick to cores - 1.

Playwright’s GitHub has some wild debates on this—worth a skim!
Honestly, just benchmark it. Run your suite with 2, 4, 8 workers and compare.

I found that set up number of workers in playwright beyond 6 didn’t help me at all—just added noise.

Also, `playwright test --list` can help gauge test duration before optimizing.
Thx everyone! 🙌

Tried `--workers=auto` and it’s *kinda* magic? Also bumped it to 6 on my 8-core machine and saw a nice speedup.

But now I’m curious—how do you handle worker setup in CI? Same logic? Or do you cap it lower?

(Also, big shoutout for the `os.cpus()` tip—didn’t know that was a thing!)
I’ve seen folks use `os.cpus().length` in the config to auto-set workers. Fancy, huh?

But yeah, for most projects, cores - 1 is the sweet spot. Unless you’re testing on a potato. Then godspeed.
If you’re in CI, check your provider’s docs. Some limit workers weirdly.

Locally, I do cores + 1 for I/O stuff. Controversial, but it works for me.

Playwright’s `--trace` can help spot bottlenecks too!



Users browsing this thread: 1 Guest(s)