Optimizing PocketBase on VPS to Achieve 30,000 Requests/Second for Single File Backend Systems
A simple single-file backend system using PocketBase on a VPS can achieve high performance of up to 30,000 requests per second when properly optimized. This guide details the...
Image credit: 4311868 · Pixabay Content License
A simple single-file backend system using PocketBase on a VPS can achieve high performance of up to 30,000 requests per second when properly optimized. This guide details the configuration, system tuning, and performance optimization steps required to reach this level of throughput on a VPS platform, including operating system configuration, database optimization, proxy usage, and advanced techniques to ensure stability and fast response times under high load.
Platform Requirements and Configuration
To achieve 30,000 requests per second, you need a VPS with strong hardware specifications, preferably using an NVMe SSD with at least 4 CPU cores, 8 GB RAM, and a 1 Gbps network connection. Below are the minimum and recommended requirements:
- OS: Ubuntu 22.04 LTS or Debian 11
- RAM: 8 GB or more
- Storage: NVMe SSD (at least 50 GB)
- CPU: 4 cores or more, x86_64 or ARM64 architecture
- Network: 1 Gbps or better
Consider high-performance VPS solutions such as NVMe Cloud VPS for Docker, Nginx & Databases.
System and PocketBase Optimization
To maximize performance, follow these steps:
1. Operating System Configuration
Apply the following system tuning to optimize server performance:
sudo sysctl -w net.core.somaxconn=65535
sudo sysctl -w net.ipv4.tcp_max_syn_backlog=65535
sudo sysctl -w net.ipv4.tcp_fin_timeout=15
sudo sysctl -w net.ipv4.tcp_tw_reuse=1
sudo sysctl -w net.ipv4.tcp_tw_recycle=1
Also increase file and process limits:
echo "* soft nofile 65536" | sudo tee -a /etc/security/limits.conf
echo "* hard nofile 65536" | sudo tee -a /etc/security/limits.conf
echo "root soft nofile 65536" | sudo tee -a /etc/security/limits.conf
echo "root hard nofile 65536" | sudo tee -a /etc/security/limits.conf
2. PocketBase Configuration
Run PocketBase with the following optimized parameters:
./pocketbase serve --http=0.0.0.0:8080 --max-connections=65535 --max-requests-per-connection=1000
The --max-connections parameter allows more simultaneous connections, while --max-requests-per-connection reduces server load.
3. Use Nginx as Reverse Proxy
Nginx helps distribute load and improve performance. Configure Nginx as follows:
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
proxy_request_buffering off;
}
}
Enable Gzip compression and cache static resources for better performance.
Monitoring and Performance Testing
To ensure stable operation, monitor performance using tools such as:
- htop: Monitor CPU, RAM, and processes
- iftop: Monitor network traffic
- ab (Apache Bench): Load testing
Run a load test with the following command:
ab -n 10000 -c 1000 http://your-domain.com/api/
To achieve 30,000 requests per second, ensure response time remains under 100ms.
Alternative Solutions and References
For systems requiring higher performance, consider High-Performance Dedicated Servers for Production Clusters.
For additional insights on optimizing cloud costs and performance, refer to Optimizing Cloud Budgets: Automated Cloud FinOps Cost Control in CI/CD with Infracost.
Recommended NVMe Cloud VPS Plans to Deploy This Setup
Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.
VPS-3E
10% VAT included
- CPU: 2 vCPU
- RAM: 4 GB
- SSD: 50 GB NVMe
