Introduction
Does your monthly VPS bill give you heart palpitations?
- Bought a 4-core 8GB VPS, but actual CPU utilization is under 10%
- Disk space grew from 20GB to 100GB, but most of it is cold data
- Kept 2-3 idle servers “just in case”
- Year-end bill is 3× what you expected
The problem isn’t that you overpaid — it’s that you haven’t optimized resources based on actual usage.
Statistics show that unoptimized cloud infrastructure wastes 30-50% of its budget. Through the practical strategies in this guide, you can reduce VPS costs by 60-70% while maintaining or even improving service availability.
Step 1: Establish Cost Visibility
1.1 Create a Resource Monitoring Dashboard
Before optimizing, you must know where your money goes. Use Prometheus + Grafana to create resource utilization dashboards:
# Deploy Node Exporter on your VPS
docker run -d \
--name node-exporter \
--network host \
--pid host \
-v /proc:/host/proc:ro \
-v /sys:/host/sys:ro \
-v /:/rootfs:ro \
--mount type=bind,source=/etc/hostname,target=/etc/hostname \
prom/node-exporter
# Scrape metrics via Prometheus
# prometheus.yml
scrape_configs:
- job_name: 'vps-metrics'
static_configs:
- targets: ['localhost:9100']
1.2 Key Monitoring Metrics
| Metric | Optimization Threshold | Notes |
|---|---|---|
| CPU Utilization | < 30% consider downsizing | Long-term low utilization means oversupply |
| Memory Usage | < 40% consider downsizing | Note: buff/cache shouldn’t count as real usage |
| Disk I/O | < 20% can use HDD | Low I/O workloads can use cheaper HDD |
| Network Bandwidth | < 50% of peak | Estimate based on historical peaks |
| Disk Space | < 60% utilized | Keep 40% buffer space |
1.3 Cost Allocation Dashboard
Create per-VPS billing tracking:
#!/bin/bash
# cost-tracker.sh - Daily cost recording
VPS_NAME=$1
DAILY_COST=$2
DATE=$(date +%Y-%m-%d)
echo "$DATE,$VPS_NAME,$DAILY_COST" >> /opt/cost-tracking/history.csv
Step 2: Data-Driven Resource Adjustment
2.1 CPU Resource Optimization
Scenario A: Long-term Low Utilization
If your VPS has < 15% CPU utilization 24/7:
- Downgrade to smaller specs: e.g., 4C8G → 2C4G
- Switch billing model: Some providers offer per-second billing, cheaper for low utilization
- Use ARM architecture: AWS Graviton / Alibaba Cloud ARM instances offer better price-performance
# View historical CPU utilization (last 30 days)
promtool query instant prometheus:9090 \
'avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[30d])) * 100'
Scenario B: Intermittent High Utilization
If CPU peaks at 80-90% but stays below 20% otherwise:
- Enable auto-scaling: Dynamically adjust instance count based on load
- Use spot instances: Non-critical workloads can save 60-70% with spot instances
- Consolidate workloads: Migrate multiple low-utilization services to one machine
2.2 Memory Optimization
Memory is a significant cost component for VPS.
Optimization strategies:
# Check memory usage
free -h
# Note: buff/cache is not real usage
# Find memory-intensive processes
ps aux --sort=-%mem | head -10
# Check for memory leaks
vmstat 1 5
| Problem | Solution |
|---|---|
| Memory usage constantly growing | Check for memory leaks, set container memory limits |
| Frequent swap usage | Consider upgrading RAM, or optimize application config |
| High buff/cache usage | Normal behavior, can free with echo 3 > /proc/sys/vm/drop_caches |
2.3 Disk Space Tiering
Cold data archiving strategy:
#!/bin/bash
# storage-tiering.sh - Automatic cold data archival
# Find files not accessed in 90 days
find /data -type f -mtime +90 -exec mv {} /mnt/archive/ \;
# Compress archives periodically
tar czf /mnt/archive/backup-$(date +%Y%m%d).tar.gz /mnt/archive/old-files/
# Upload to cheap object storage (optional)
rclone copy /mnt/archive/ backup:my-bucket/cold-storage/
| Data Tier | Access Frequency | Storage Solution | Cost Comparison |
|---|---|---|---|
| Hot data | Multiple times daily | SSD/NVMe | $0.10/GB/month |
| Warm data | Several times weekly | HDD | $0.03/GB/month |
| Cold data | Several times monthly | Object storage | $0.01/GB/month |
| Archive data | Rarely | Tape/Deep archive | $0.004/GB/month |
Step 3: Auto-Scaling Strategies
3.1 Horizontal Scaling (Add Instances)
Best for: Services with fluctuating traffic (websites, APIs)
# Kubernetes HPA configuration
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: web-service
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: web-service
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
Cost calculation:
- Base instance: $20/month
- Peak extra instances: $20 × 5 instances × 10 hours/day ÷ 30 days = $33/month
- Total: $53/month (saving $147/month vs running 10 instances constantly)
3.2 Vertical Scaling (Adjust Instance Specs)
Best for: Single-service workloads with stable utilization
# Use DigitalOcean snapshot migration
doctl compute snapshot create my-vps-snapshot --instance-id 123456
doctl compute droplet create my-vps-small \
--image my-vps-snapshot \
--size s-1vcpu-1gb \
--region nyc1
3.3 Auto-Shutdown Strategy
For non-24/7 services (dev environments, test environments):
#!/bin/bash
# auto-shutdown.sh
# Business hours: 9:00-18:00
START_HOUR=9
END_HOUR=18
CURRENT_HOUR=$(date +%H)
if [ "$CURRENT_HOUR" -lt "$START_HOUR" ] || [ "$CURRENT_HOUR" -ge "$END_HOUR" ]; then
# Non-business hours, shutdown dev server
doctl compute droplet action stop 123456
fi
Savings: 15 hours saved per day, 50% cost reduction monthly.
Step 4: Spot Instances & Reserved Instances
4.1 Spot Instances
Save 60-70%, but can be reclaimed at any time.
| Scenario | Suitable? |
|---|---|
| Batch processing | ✅ Perfect fit |
| Containerized stateless services | ✅ Suitable (with auto-recovery) |
| Development/testing environments | ✅ Suitable |
| Production databases | ❌ Not suitable |
| Public API services | ⚠️ Requires redundancy design |
# AWS EC2 spot instance launch
aws ec2 run-instances \
--instance-market-options 'SpotOptions={InstanceInterruptionBehavior=terminate}' \
--instance-type m5.large \
--min-count 1 \
--max-count 1
4.2 Reserved Instances
Save 30-60%, ideal for long-term stable workloads.
# AWS Reserved Instance purchase example
aws ec2 purchase-reserved-instances-offering \
--reserved-instances-offering-id <offer-id> \
--instance-count 1
Hybrid strategy:
- Base load with reserved instances (guaranteed availability)
- Peak load with spot instances (cost reduction)
- Burst load with on-demand instances (flexibility)
Step 5: Storage Cost Optimization
5.1 Object Storage vs Block Storage
| Data Type | Original | Optimized | Savings |
|---|---|---|---|
| Static assets | EBS block storage | S3 + CDN | 70-80% |
| Backup files | Local disk | Object storage | 60-70% |
| Log archives | Local disk | Glacier | 90%+ |
| User files | Local disk | Object storage | 50-60% |
5.2 Smart Compression & Deduplication
# Enable ZFS compression
zfs set compression=zstd rpool/data
# Clean up unused packages regularly
apt autoremove --purge -y
apt clean
# Clean Docker resources
docker system prune -a --force
docker volume prune --force
5.3 CDN for Static Resources
Migrate static assets (images, CSS, JS) to CDN:
| Solution | Cost | Notes |
|---|---|---|
| Cloudflare Pro | $20/month | Basic CDN + security |
| Cloudflare Free | $0 | Suitable for low-traffic sites |
| Self-hosted CDN | $0.02/GB | Suitable for high traffic |
Step 6: Architecture Optimization to Reduce Infrastructure Needs
6.1 From Monolith to Microservices
Before optimization: One large VPS running all services
- 4C8G, $50/month
- Single point of failure affects all services
After optimization: Multiple small VPS instances分工运行
- 4 × 1C2G, $5/month = $20/month
- Fault isolation, easier to scale
6.2 Containerization & Resource Limits
# docker-compose.yml - Resource limits
services:
web:
image: nginx:latest
deploy:
resources:
limits:
cpus: '0.5'
memory: 256M
reservations:
cpus: '0.25'
memory: 128M
6.3 Serverless Architecture
For low-frequency services, consider serverless options:
| Service Type | Traditional | Serverless | Savings |
|---|---|---|---|
| Scheduled tasks | Running 24/7 | Lambda/Cloud Functions | 90%+ |
| Low-frequency API | Permanent process | API Gateway + Lambda | 80%+ |
| Batch processing | Fixed instance | Elastic containers | 70%+ |
Real-World Case: From $120/month to $28/month
Before Optimization
| Resource | Specs | Monthly Cost |
|---|---|---|
| Web server | 4C8G SSD | $40 |
| Database server | 4C16G SSD | $60 |
| Backup server | 2C4G 1TB HDD | $20 |
| Total | $120 |
Optimization Measures
- Web server downgrade: CPU utilization < 20% long-term, downgrade to 2C4G
- Database optimization: Add cache layer, reduce DB load, downgrade to 2C8G
- Backup tiering: Hot backups kept 7 days, cold backups archived to object storage
- Enable spot instances: Development environment uses spot instances
After Optimization
| Resource | Specs | Monthly Cost |
|---|---|---|
| Web server | 2C4G | $20 |
| Database server | 2C8G | $30 |
| Backups (object storage) | 1TB | $2.30 |
| Dev environment (spot) | 1C2G | $5 |
| Total | $57.30 |
Actual savings: $120 - $57.30 = $62.70/month (52% savings)
With further architecture optimization (adding cache, enabling CDN), costs can drop to $28/month (77% savings).
Monitoring Optimization Results
Establish continuous monitoring to ensure stability after optimization:
# Alertmanager rules
groups:
- name: cost-optimization
rules:
- alert: HighCPUUtilization
expr: node_cpu_seconds_total{mode="idle"} < 0.3
for: 10m
labels:
severity: warning
annotations:
summary: "CPU utilization exceeds 70%, consider scaling up"
- alert: StorageNearCapacity
expr: node_filesystem_avail_bytes / node_filesystem_size_bytes < 0.2
for: 5m
labels:
severity: critical
annotations:
summary: "Disk space below 20%, need to clean or expand"
Summary
VPS cost optimization is a continuous process requiring:
- Establish visibility: Monitor resource usage, track every expense
- Data-driven decisions: Adjust resources based on actual usage, not guesswork
- Automated strategies: Use auto-scaling, spot instances to reduce manual effort
- Architecture optimization: Fundamentally reduce demand for expensive resources
- Continuous monitoring: Regularly review bills, discover new optimization opportunities
Remember: The best optimization is avoiding unnecessary resource consumption, not saving money on wasted resources.
Start today — run the monitoring script for a week, analyze the data, then create your optimization plan. You’ll be amazed at how much you can save!
Appendix: Useful Optimization Tools
| Tool | Purpose | Link |
|---|---|---|
| Prometheus | Metrics monitoring | prometheus.io |
| Grafana | Visualization dashboards | grafana.com |
| SpotINST | Spot instance management | spotinst.com |
| CloudHealth | Cloud cost analysis | cloudhealthtech.com |
| rclone | Cloud storage sync | rclone.org |
