إنتقل إلى المحتوى الرئيسي

📊 Performance Tuning

Optimize Monitron SaaS for high-load environments with many monitors.


🐘 PHP Configuration

memory_limit = 256M
max_execution_time = 120
upload_max_filesize = 100M
post_max_size = 100M
opcache.enable = 1
opcache.memory_consumption = 256
opcache.max_accelerated_files = 20000
opcache.validate_timestamps = 0 # Set to 1 during development

💾 Database Optimization

MySQL my.cnf

[mysqld]
innodb_buffer_pool_size = 512M # 50-70% of RAM for dedicated DB servers
innodb_log_file_size = 256M
innodb_flush_log_at_trx_commit = 2 # Faster writes, slight durability risk
query_cache_type = 0 # Disabled in MySQL 8+
max_connections = 200

Index Health

Monitron includes indexes on frequently queried columns. Verify they exist:

SHOW INDEX FROM monitor_checks;
SHOW INDEX FROM monitors;

⚡ Redis

Use Redis for both caching and queues for best performance:

.env

CACHE_DRIVER=redis
QUEUE_CONNECTION=redis
SESSION_DRIVER=redis

Install Redis

sudo apt install redis-server
sudo systemctl enable redis

🔄 Queue Worker Tuning

For Many Monitors (200+)

# /etc/supervisor/conf.d/monitron-worker.conf
[program:monitron-worker]
numprocs=6 # More workers for more monitors
command=php /var/www/monitron/artisan queue:work redis --sleep=1 --tries=3 --max-time=3600 --max-jobs=1000

Separate Critical Queue

[program:monitron-worker-critical]
numprocs=2
command=php /var/www/monitron/artisan queue:work redis --queue=checks-critical --sleep=1 --tries=3

[program:monitron-worker-standard]
numprocs=4
command=php /var/www/monitron/artisan queue:work redis --queue=checks-standard,default --sleep=3 --tries=3

📦 Laravel Optimization

# Run ALL optimizations
php artisan optimize
php artisan view:cache
php artisan event:cache
php artisan filament:optimize

# Autoloader optimization
composer install --no-dev --optimize-autoloader --classmap-authoritative

🌐 Nginx Tuning

worker_processes auto;
worker_connections 2048;

http {
keepalive_timeout 65;
gzip on;
gzip_types text/plain application/json application/javascript text/css;

fastcgi_cache_path /tmp/nginx-cache levels=1:2 keys_zone=monitron:10m;
}

📊 Monitoring Your Monitoring

Yes, you should monitor Monitron itself! Use an external uptime service (or a second Monitron instance) to check:

  • Your Monitron dashboard URL
  • Queue worker health (add a heartbeat ping to your worker)
  • Database connectivity
  • Disk space on the Monitron server