How to Run Multiple Browsers in Parallel#
Which Methods Can Boost the Performance?#
You can run Browserist as a normal, linear script or with various methods for concurrent processing:
Which Method Is Faster?#
Multi-processing and multi-threading are the fastest methods, sometimes twice as fast as running the same job in linear or asynchronous mode. For instance, measuring execution time of the code examples below yield the results like this in seconds:
Method | Rank | Improvement | Average | Min | Max |
---|---|---|---|---|---|
Linear | Baseline | 8.59 | 8.55 | 8.62 | |
Asynchronous | 2 % | 8.42 | 8.33 | 8.48 | |
Multi-threading | 103 % | 4.24 | 4.20 | 4.29 | |
Multi-processing | 105 % | 4.20 | 3.69 | 6.05 |
Find code examples of the tests below.
Basic Code Example#
Imagine that you want to scrape a website with multiple browser types: Chrome, Edge, Firefox. A simplified example of this:
- Open browser instance
- Load website example.com and do something
- Close browser instance
How the code could look:
Python | |
---|---|
This will print the following to the terminal:
Test Code Examples#
Let's try this with four different methods from linear to concurrent processing and run the tests with three different browsers (Chrome, Edge, Firefox):
Even Faster with Headless and Disable Images#
Gain even more performance by running the browsers in headless mode and with images disabled, including the added benefit that headless mode allows you to run the job as a background task while doing something else.
For example:
Results in seconds and compared to previous method:
Method | Rank | Improvement | Average | Min | Max |
---|---|---|---|---|---|
Linear | 2 % | 8.46 | 6.34 | 12.78 | |
Asynchronous | 7 % | 8.01 | 6.15 | 11.11 | |
Multi-threading | 113 % | 4.03 | 3.98 | 4.07 | |
Multi-processing | 139 % | 3.60 | 3.57 | 3.65 |