Performance Optimization
Maximize your TinyBox VPS performance and efficiency
Memory Optimization
Add Swap Space
# Create swap file (recommended: 1-2x RAM size)
fallocate -l 2G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
# Make permanent
echo '/swapfile none swap sw 0 0' >> /etc/fstab
# Optimize swap usage
echo 'vm.swappiness=10' >> /etc/sysctl.conf
echo 'vm.vfs_cache_pressure=50' >> /etc/sysctl.conf
# Apply changes
sysctl -p
Memory Monitoring
# Check memory usage
free -h
# Show top memory consumers
ps aux --sort=-%mem | head -10
# Monitor memory in real-time
watch -n 2 free -h
# Clear memory cache (if needed)
sync && echo 3 > /proc/sys/vm/drop_caches
CPU & Process Optimization
Process Management
# Find CPU-heavy processes
top -o %CPU
# Kill resource-hungry process
kill -15 PID_NUMBER
# Set process priority (nice)
nice -n 10 command
renice 10 -p PID_NUMBER
Load Monitoring
# Check current load
uptime
# Monitor load in real-time
vmstat 1
# I/O wait monitoring
iostat -x 1
Healthy Load Averages
TINY 1.0 VPS (1 CPU):
- • Good: < 0.7
- • Fair: 0.7 - 1.0
- • High: > 1.0
TINY 2.1 VPS (2 CPU):
- • Good: < 1.4
- • Fair: 1.4 - 2.0
- • High: > 2.0
Disk I/O Optimization
Disk Usage Analysis
# Check disk usage
df -h
# Find largest directories
du -sh /* 2>/dev/null | sort -hr | head -10
# Find large files
find / -type f -size +100M 2>/dev/null | head -20
# Analyze specific directory
du -ah /var/log | sort -hr | head -10
Log Management
# Clean system logs
journalctl --vacuum-size=100M
journalctl --vacuum-time=30d
# Clean old logs
find /var/log -name "*.log" -mtime +30 -delete
find /var/log -name "*.gz" -mtime +30 -delete
# Set up log rotation
nano /etc/logrotate.conf
Application-Specific Optimizations
Web Server (Nginx)
# Optimize nginx.conf
worker_processes auto;
worker_connections 1024;
keepalive_timeout 30;
# Enable compression
gzip on;
gzip_min_length 1000;
gzip_types text/plain application/json;
# Enable caching
location ~* \.(jpg|jpeg|png|gif|css|js)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
Database (MySQL)
# Optimize my.cnf for limited RAM
[mysqld]
innodb_buffer_pool_size = 256M
max_connections = 30
query_cache_size = 32M
tmp_table_size = 32M
table_open_cache = 64
innodb_log_file_size = 32M
PHP Optimization
# Optimize php.ini
memory_limit = 256M
max_execution_time = 30
max_input_vars = 3000
opcache.enable = 1
opcache.memory_consumption = 64
Node.js with PM2
# PM2 ecosystem.config.js
module.exports = {
apps: [{
name: 'app',
script: 'app.js',
instances: 'max',
max_memory_restart: '256M',
node_args: '--max-old-space-size=256'
}]
};
Performance Monitoring Script
#!/bin/bash
# Save as /usr/local/bin/performance-check.sh
echo "🚀 TinyBox VPS Performance Report"
echo "=================================="
# System info
echo "📊 System Overview:"
uptime
echo
# Memory usage
echo "💾 Memory Usage:"
free -h
echo
# Top CPU processes
echo "🔥 Top CPU Consumers:"
ps aux --sort=-%cpu | head -6
echo
# Top Memory processes
echo "🧠 Top Memory Consumers:"
ps aux --sort=-%mem | head -6
echo
# Disk usage
echo "💿 Disk Usage:"
df -h /
echo
# Load average analysis
load1=$(uptime | awk '{print $10}' | sed 's/,//')
if (( $(echo "$load1 > 1.0" | bc -l) )); then
echo "⚠️ High CPU load detected: $load1"
else
echo "✅ CPU load normal: $load1"
fi
# Make executable: chmod +x /usr/local/bin/performance-check.sh
💡 Performance Tips
- • Run the performance check weekly
- • Monitor during peak usage times
- • Set up automated alerts for high usage
- • Keep swap usage below 50%
- • Restart services weekly
- • Update software regularly