Efficient load testing strategies with Puppeteer and headless Chrome

Hey folks! I’m planning a load test setup using Puppeteer and headless Chrome. I need to simulate 1000 users logging in. I’m torn between two ideas:

  1. Make 1000 headless Chrome instances with puppeteer.launch(). Then do the login steps for each. Sounds simple, but I’m worried about system resources. Can my machine handle it?

  2. Launch just one Chrome instance, but create 1000 CDP sessions. Not sure if this’ll work though. Can I set different caches for each session?

Does anyone have experience with this? What’s the best way to do load testing with Puppeteer? Any clever tricks or alternatives I’m missing?

I’d really appreciate any advice or best practices. Thanks in advance!

I’ve tackled similar load testing challenges, and I can share what worked well for me. Instead of going with either of your proposed approaches, I’d suggest looking into Puppeteer-cluster. It’s a library built on top of Puppeteer that handles concurrent browser instances and task queues efficiently.

With Puppeteer-cluster, you can set up a pool of browser instances and distribute your 1000 login tasks across them. This approach gives you fine-grained control over resource usage while maintaining good simulation fidelity. You can adjust the number of concurrent browsers based on your machine’s capabilities.

One trick I found helpful was to use a combination of real browser instances and ‘mock’ sessions. This lets you scale up the test without overwhelming your system. Just make sure to validate that the mock sessions behave similarly to real ones for your specific use case.

Remember to monitor your system resources during the test runs. You might need to tweak your setup a few times to find the sweet spot between load simulation accuracy and system stability.

hey mate, have u considered using puppeteer-cluster? it’s pretty neat for managing multiple browser instances. i’ve used it for similar stuff and it worked great. you can control how many browsers to run at once, which helps with resource management. just my 2 cents!

Based on my experience, launching 1000 separate Chrome instances isn’t practical for most machines. It’ll likely overwhelm your system resources quickly. The second approach with multiple CDP sessions is more viable, but it has limitations in simulating real-world scenarios accurately.

I’ve found success using a hybrid approach. Launch a smaller number of Chrome instances (say 50-100) and create multiple CDP sessions within each. This balances resource usage and simulation fidelity.

Another strategy is to use a distributed setup with multiple machines or cloud instances to spread the load. Tools like Selenium Grid or Puppeteer-cluster can help manage this.

For truly large-scale testing, consider specialized load testing tools like k6 or Gatling. They’re designed to handle thousands of concurrent users more efficiently than browser automation tools.