Performance Issues¶
Troubleshooting slow performance and resource problems.
Quick Diagnostics¶
# System resources
top
free -m
df -h
# Service status
sudo mb-status
# Processing metrics
sudo mb-filter-stats
Slow Email Processing¶
Check Queue¶
If queue backing up:
Check Filter Performance¶
If slow: - Check Rspamd: rspamc stat - Check ClamAV: sudo systemctl status clamav-daemon - Increase timeout: sudo mb-config set filter.timeout 180
Slow Web Interface¶
Check Resources¶
PHP-FPM Optimization¶
Check worker count:
Increase workers:
Change:
Restart:
Database Optimization¶
Check slow queries:
Optimize tables:
Add indexes if needed:
-- Example for frequently queried columns
CREATE INDEX idx_quarantine_to ON mb_quarantine(envelope_to);
CREATE INDEX idx_log_received ON mb_log_email(received_at);
High CPU Usage¶
Identify culprit:
Common causes:
- mb-filter CPU high:
- Too many workers
- Reduce scan depth
-
Increase timeouts
-
Rspamd CPU high:
- Restart:
sudo systemctl restart rspamd -
Reduce rules if needed
-
ClamAV CPU high:
- Normal during signature updates
- Check:
sudo tail -f /var/log/clamav/freshclam.log
Optimize:
# Reduce virus scan recursion
sudo mb-config set antivirus.max_recursion 8
# Skip large files
sudo mb-config set filter.skip_large_files true
sudo mb-config set filter.max_file_size 26214400 # 25 MB
High Memory Usage¶
Check memory:
Common causes:
- ClamAV (normal: 400-600 MB)
- MariaDB (grows with connections)
- mb-filter workers
Optimize ClamAV:
Add:
Optimize database connections:
Add swap if needed:
# Create 2GB swap
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
# Add to /etc/fstab for persistence
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
Disk I/O Issues¶
Check I/O wait:
Check disk usage:
Clean up:
Optimize disk: - Move logs to separate disk - Move quarantine to separate disk - Use SSD for database
Database Performance¶
Check Connection Pool¶
Optimize connections:
# Increase pool size if maxed out
sudo mb-config set rpcd.db_pool_max 100
# Decrease if too many idle
sudo mb-config set rpcd.db_pool_min 10
Slow Queries¶
Enable slow query log:
Add:
Analyze:
Table Optimization¶
Check table sizes:
SELECT
table_name,
ROUND(((data_length + index_length) / 1024 / 1024), 2) AS size_mb,
table_rows
FROM information_schema.TABLES
WHERE table_schema = 'mailborder'
ORDER BY (data_length + index_length) DESC;
Optimize large tables:
Network Performance¶
Check latency:
Check bandwidth:
Optimize Nginx:
Adjust:
Redis Performance¶
Check Redis stats:
Optimize:
Adjust:
Restart:
Monitoring and Alerting¶
Set up monitoring:
# Install monitoring tools
sudo apt install htop iotop iftop
# Add to cron
*/5 * * * * /usr/local/bin/performance-check.sh
Alert script:
#!/bin/bash
CPU=$(top -bn1 | grep "Cpu(s)" | awk '{print $2}' | cut -d'%' -f1)
if (( $(echo "$CPU > 80" | bc -l) )); then
echo "High CPU: $CPU%" | mail -s "Performance Alert" admin@example.com
fi