This guide covers how to set up and configure connection-pooling on a Linux VPS. Whether you're running a production environment or a development setup, these instructions will help you get started quickly and securely.
Prerequisites
- A registered domain name (for public-facing services)
- Basic familiarity with the Linux command line
- A VPS running Ubuntu 22.04 or later (2GB+ RAM recommended)
Baseline Measurement
For production deployments, consider implementing high availability by running multiple instances behind a load balancer. This approach provides both redundancy and improved performance under heavy load.
# Kernel tuning: /etc/sysctl.d/99-performance.conf
cat << 'EOF' | sudo tee /etc/sysctl.d/99-performance.conf
# Network performance
net.core.somaxconn = 65535
net.core.netdev_max_backlog = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 15
# Memory management
vm.swappiness = 10
vm.dirty_ratio = 15
vm.dirty_background_ratio = 5
# File descriptors
fs.file-max = 2097152
fs.nr_open = 2097152
EOF
sudo sysctl --system
The output should show the service running without errors. If you see any warning messages, address them before proceeding to the next step.
Kernel and OS Tuning
Performance benchmarks show that properly tuned connection-pooling can handle significantly more concurrent connections than the default configuration. The key improvements come from adjusting worker processes and connection pooling.
# Benchmark before and after optimization
# CPU benchmark
sysbench cpu --cpu-max-prime=20000 run
# Memory benchmark
sysbench memory --memory-block-size=1M --memory-total-size=10G run
# Disk I/O benchmark
sysbench fileio --file-total-size=4G --file-test-mode=rndrw prepare
sysbench fileio --file-total-size=4G --file-test-mode=rndrw run
sysbench fileio --file-total-size=4G cleanup
Each line in the configuration serves a specific purpose. The comments explain the reasoning behind each setting, making it easier to customize for your specific use case.
- Enable firewall and allow only necessary ports
- Use strong, unique passwords for all services
- Keep all software components up to date
- Set up fail2ban for brute force protection
Wrapping Up
Following this guide, your connection-pooling setup should be production-ready. Keep an eye on resource usage as your traffic grows and don't forget to test your backup and recovery procedures periodically.