Skip to content

v0.1.30 - CPU Auto-Detection for Small VPS

Choose a tag to compare

@quanhua92 quanhua92 released this 19 Nov 14:12
· 748 commits to main since this release

πŸš€ CPU Auto-Detection for Small VPS

This release adds intelligent CPU detection to prevent overload on small VPS instances.

πŸ”§ Key Changes

CPU Auto-Detection

  • Automatically detects CPU cores and adjusts worker threads accordingly
  • 1-2 cores β†’ 1 worker thread (small VPS)
  • 3-4 cores β†’ 2 worker threads (medium system)
  • 5+ cores β†’ 4 worker threads (large system)

Concurrent Batch Optimization

  • Auto-detects optimal concurrent API batch requests
  • 1-2 cores β†’ 1 concurrent batch (sequential processing)
  • 3-4 cores β†’ 2 concurrent batches
  • 5+ cores β†’ 3 concurrent batches

Cache Frequency Adjustment

  • Reduced auto-reload frequency from 15s to 30s
  • Better balance between freshness and CPU efficiency

Startup Logging

  • Added detailed CPU configuration logging at startup
  • Shows detected cores, worker threads, and concurrent batches

πŸ“Š Expected Impact on 2-Core VPS

Before:

  • Worker threads: 8 (400% oversubscription)
  • Concurrent batches: 3 per worker
  • Auto-reload: Every 15s
  • CPU usage: 100% constantly

After:

  • Worker threads: 1 (optimal for 2 cores)
  • Concurrent batches: 1 (sequential)
  • Auto-reload: Every 30s
  • CPU usage: 30-50% during sync periods, near 0% when idle

πŸ” Technical Details

  • Added num_cpus dependency for CPU detection
  • Updated all workers (daily, slow, crypto) to use auto-detected configurations
  • Changed default concurrent_batches from 3 β†’ 1 (conservative fallback)

πŸ“ Files Modified

  • Cargo.toml: Add num_cpus dependency
  • src/utils.rs: Add CPU detection helpers
  • src/commands/serve.rs: Use auto-detected configuration + detailed logging
  • src/commands/pull.rs: Use auto-detected concurrent batches
  • src/services/data_store.rs: CACHE_TTL_SECONDS 15s β†’ 30s
  • src/models/sync_config.rs: Default concurrent_batches 3 β†’ 1
  • src/worker/*.rs: Use auto-detected concurrent batches

πŸš€ Deployment

The optimizations work automatically - no configuration needed. Check startup logs for detected configuration:

```
πŸ”§ CPU Configuration (auto-detected):
πŸ’» CPU cores detected: 2
πŸ”§ Worker threads: 1
⚑ Concurrent batches: 1
```


Full Changelog: v0.1.29...v0.1.30