On this page
- Choosing Hardware for Selenium: How Much RAM Do You Really Need?
- Environment Setup: Ubuntu 22.04 and Dependencies
- The Detection Problem: Why Your Bot Gets 403 Errors
- Optimization and Stability: Our 2024 Benchmarks
- What We Got Wrong: Mistakes and Surprises
- Practical Deployment Checklist
- FAQ: Frequently Asked Questions
Running Selenium on a VPS isn't just about installing a single library—it's a constant battle for every megabyte of RAM and an ongoing effort to hide automation from anti-fraud systems. Over the past 18 months, we've deployed more than 40 scrapers and bots across various server configurations, and the data we've collected shows that standard advice from the documentation often leads to process crashes (OOM Killer) or instant IP bans.
- Minimum entry threshold: Stable operation of 1 Chrome thread requires at least 1 GB of free RAM, even though the browser itself consumes around 180 MB at startup.
- Multithreading efficiency: On a VPS with 2 vCPUs and 4 GB of RAM (costing around $8-10 per month), it's optimal to run no more than 6-8 parallel instances.
- Anti-detect: Standard Selenium WebDriver is detected by 95% of websites protected by Cloudflare or Akamai within the first 3 requests.
- Deployment time: Setting up a production-ready environment from scratch takes an average of 4 hours, including debugging dependencies in headless mode.
Running a browser on a server without a graphical user interface is always a trade-off between speed and making your bot behave like a real human. We've tested dozens of configurations and are ready to share hard numbers that will help you save on hosting costs and avoid common mistakes when scaling.
In practice: we test everything described above on servers from our VPS partner — a VPS provider offering crypto payments and the locations we need.
Choosing Hardware for Selenium: How Much RAM Do You Really Need?
Chrome Headless consumes 180 MB of RAM immediately after opening a blank page. However, that number is deceptive. As soon as your script starts loading heavy assets (JS bundles, images, ad scripts), memory usage per tab jumps to 350-450 MB. If you plan to run Selenium on a budget server, be sure to check out our guide VPS in Plain English: What It Is, How to Choose, and Real 2024 Benchmarks to understand the limits of virtualization.
Our benchmarks on Ubuntu 22.04 show the following relationship between server resources and thread count:
| VPS Configuration (vCPU/RAM) | Max Threads (Stable) | CPU Usage (%) | Price (Average, 2024) |
|---|---|---|---|
| 1 Core / 1 GB RAM | 1-2 | 85-95% | $4 - $5/mo |
| 2 Core / 4 GB RAM | 6-8 | 60-75% | $10 - $15/mo |
| 4 Core / 8 GB RAM | 15-20 | 50-65% | $20 - $30/mo |
A swap file is mandatory for running Selenium on servers with less than 4 GB of RAM. Without it, Chrome crashes with the error "DevToolsActivePort file doesn't exist" as soon as the system runs short on memory. We recommend creating a swap file of at least 2 GB. You can find step-by-step setup instructions here: Linux Swap File: Setup, Optimization, and Hard-Won Experience (2024).
Environment Setup: Ubuntu 22.04 and Dependencies
Ubuntu 22.04 LTS remains the most stable foundation for running browser engines. The main challenge lies in installing Google Chrome alongside a matching ChromeDriver. Browser and driver versions frequently fall out of sync, causing critical errors at session startup.
Google Chrome requires more than 50 system libraries (libnss3, libatk1.0-0, etc.) that are missing from minimal VPS OS images. We use the following set of commands to prepare the server:
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
apt-get update && apt-get install -y google-chrome-stable xvfb
Xvfb (X virtual framebuffer) lets you emulate a physical display, which is critical for websites that check for graphical output. Even though modern Chrome supports the --headless=new flag, using Xvfb still resolves rendering issues with certain Canvas elements.
The Detection Problem: Why Your Bot Gets 403 Errors
Undetected-chromedriver drops the block rate to 2-5%, compared to 95% with vanilla Selenium. The primary reason for blocks on a VPS is the `navigator.webdriver` variable, which is always set to `true` in standard mode. Anti-fraud systems (Cloudflare, F5, Datadome) read this flag immediately.
Cloudflare also analyzes your browser's TLS fingerprint (JA3) and HTTP/2 settings. Because Selenium drives a "clean" Chrome instance, its fingerprint is overly sterile and predictable. We found that adding randomized delays between actions (from 1.5 to 4.2 seconds) and using high-quality residential proxies increases account lifespan by 10x.
Important takeaway: Using Docker for Selenium on a VPS is convenient, but it adds roughly 10-15% in RAM overhead. If you're tight on resources, running directly on the host Ubuntu OS is the better choice. For a head-to-head comparison of container engines, read Docker vs Podman: Real-World Migration Experience.
Optimization and Stability: Our 2024 Benchmarks
Selenium scripts frequently suffer from memory leaks. After opening 1,000 pages, a single Chrome process can bloat up to 2 GB. We implemented a practice of forcefully restarting the browser every 50-100 iterations, which keeps RAM usage within a predictable range.
Configuring shared memory (/dev/shm) is a critical step. By default, Docker containers and some VPS instances allocate only 64 MB to `/dev/shm`, which isn't enough for Chrome to render pages. Be sure to pass the `--disable-dev-shm-usage` argument to force the browser to use `/tmp` instead of shared memory if you can't resize `/dev/shm`.
Startup arguments for optimization in Python:
- --headless=new (required for newer versions of Chrome)
- --no-sandbox (necessary when running as root on a VPS)
- --disable-gpu (saves around 30-50 MB of RAM)
- --blink-settings=imagesEnabled=false (disabling images saves up to 40% of bandwidth and speeds up page loads by 1.5 sec)
If your goal is large-scale data collection, you may want to consider alternatives. We covered our experience with specialized scraping frameworks in Scrapy on a VPS: Setup, Optimization, and Real Numbers (2024).
What We Got Wrong: Mistakes and Surprises
Zombie processes were our biggest headache in early 2024. Whenever a Python script crashed unexpectedly, ChromeDriver and Chrome processes often lingered in memory. Overnight, a server with 16 GB of RAM became completely clogged with hung browser instances, taking down all running services. Now we always wrap execution in a `try...finally` block with an explicit `driver.quit()` call, backed by a system cron job that kills any Chrome processes older than 30 minutes every hour.
Disk space also caught us off guard. Every Chrome launch creates a temporary profile inside `/tmp`. If you don't specify a fixed `user-data-dir`, the `/tmp` directory balloons to tens of gigabytes within days. On one of our projects, a 20 GB disk filled up in 72 hours, corrupting the bot's database.
Contrarian take: Many guides recommend Selenium Grid for scaling. In our experience, for 90% of VPS workloads, it is far simpler and more reliable to spin up multiple independent Python processes using `multiprocessing` or `Celery`. Selenium Grid introduces an extra layer of abstraction that consumes an additional 1.2 GB of RAM just to run the hub and nodes.
Practical Deployment Checklist
- Server prep (15 minutes): Spin up a VPS running Ubuntu 22.04. A 2 GB RAM plan is enough to get started. Configure a 2-4 GB swap file. Difficulty: Low.
- Software installation (20 minutes): Install the stable release of Google Chrome. Avoid beta builds, as matching drivers are often unavailable. Difficulty: Medium.
- Anti-detect setup (30 minutes): Integrate `undetected-chromedriver` and configure User-Agent rotation. Make sure the screen resolution in headless mode is explicitly set to a standard value (e.g., 1920x1080). Difficulty: Medium.
- Monitoring (10 minutes): Set up alerts for low RAM. Expected outcome: reliable 24/7 bot operation without manual intervention. Difficulty: Low.
If you're planning to use Selenium for messaging app automation, check out our guide How to Host a Bot on a VPS: Deployment, Optimization, and Pricing Guide (2024).
FAQ: Frequently Asked Questions
How much RAM do I need for a single Chrome window?
For reliable performance on complex websites, budget 400-500 MB per thread. For lightweight landing pages without heavy JS, 200-250 MB is enough. Always leave a 15-20% buffer for OS overhead.
Why does Selenium run slower on a VPS than on my local PC?
The bottleneck usually comes down to weak single-core performance on budget VPS plans and network latency to the target site. Desktop PCs typically run CPUs clocked at 3.5-4.5 GHz, whereas server cores may be throttled or capped at 2.0-2.5 GHz.
Can I run Selenium on a dirt-cheap $1-2 VPS?
Theoretically yes, if you use Firefox in headless mode (which occasionally uses less RAM) and aggressively strip down page loads by disabling CSS, JS, and images. However, overall stability will be very poor, and you'll deal with frequent process restarts.
How do I avoid IP bans?
Use proxies. For Selenium on a VPS, residential or mobile proxies with per-request rotation work best. Datacenter IPs (owned by hosting providers) are preemptively blocked by most major websites.
slipjar.app
The slipjar.app team writes about hosting, servers and infrastructure in plain language.