Skip to content

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

sudo mailq
# Large queue indicates bottleneck

If queue backing up:

# Increase filter workers
sudo mb-config set filter.workers 12
sudo systemctl reload mb-filter

Check Filter Performance

# Processing time stats
sudo grep "Processing Time" /var/log/mailborder/mb-filter.log | tail -n 20

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

# CPU
top

# Memory
free -m

# Disk I/O
iostat -x 1 5

PHP-FPM Optimization

Check worker count:

sudo cat /etc/php/8.2/fpm/pool.d/mailborder.conf | grep pm

Increase workers:

sudo nano /etc/php/8.2/fpm/pool.d/mailborder.conf

Change:

pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 15

Restart:

sudo systemctl restart php8.2-fpm

Database Optimization

Check slow queries:

sudo mysql -u mailborder -p -e "SHOW PROCESSLIST"

Optimize tables:

sudo mb-maintenance --optimize-db

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:

top
# Press '1' to show all cores

Common causes:

  1. mb-filter CPU high:
  2. Too many workers
  3. Reduce scan depth
  4. Increase timeouts

  5. Rspamd CPU high:

  6. Restart: sudo systemctl restart rspamd
  7. Reduce rules if needed

  8. ClamAV CPU high:

  9. Normal during signature updates
  10. 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:

free -m
ps aux --sort=-%mem | head -n 20

Common causes:

  1. ClamAV (normal: 400-600 MB)
  2. MariaDB (grows with connections)
  3. mb-filter workers

Optimize ClamAV:

sudo nano /etc/clamav/clamd.conf

Add:

Bytecode no  # Reduces memory ~100 MB

Optimize database connections:

sudo mb-config set rpcd.db_pool_max 30  # Reduce from 50

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:

iostat -x 1 5
# High %iowait indicates disk bottleneck

Check disk usage:

df -h
sudo du -sh /var/log/mailborder/*
sudo du -sh /var/spool/mailborder/*

Clean up:

sudo mb-maintenance --cleanup-logs
sudo mb-quarantine-cleanup

Optimize disk: - Move logs to separate disk - Move quarantine to separate disk - Use SSD for database

Database Performance

Check Connection Pool

sudo mysql -u mailborder -p -e "SHOW STATUS LIKE 'Threads_connected'"

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:

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Add:

slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 2

Analyze:

sudo mysqldumpslow /var/log/mysql/slow.log

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:

sudo mb-maintenance --optimize-db

Network Performance

Check latency:

ping -c 10 mailborder.example.com

Check bandwidth:

sudo iftop

Optimize Nginx:

sudo nano /etc/nginx/nginx.conf

Adjust:

worker_connections 4096;
keepalive_timeout 30;
client_max_body_size 50M;

Redis Performance

Check Redis stats:

redis-cli info stats
redis-cli info memory

Optimize:

sudo nano /etc/redis/redis.conf

Adjust:

maxmemory 1gb
maxmemory-policy allkeys-lru

Restart:

sudo systemctl restart redis-server

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

See Also