Moodle

Moodle Performance Tuning for High-Traffic Environments

Moodle performance degrades under load without proper configuration. Whether you're running a corporate training platform or an academic LMS, here's how to optimize for concurrent users.

Why Moodle slows down

Moodle is database-intensive. Every page load can trigger dozens of database queries. Common performance killers include:

  • No caching - Default Moodle installations don't use application caching
  • Undersized database - MySQL/MariaDB defaults aren't tuned for Moodle
  • Synchronous cron - Running tasks during user sessions
  • Large course catalogs - Unoptimized queries on big course lists
  • Plugin bloat - Too many plugins competing for resources

Enable application caching

Moodle's MUC (Moodle Universal Cache) dramatically reduces database load when properly configured.

Redis configuration (recommended)

Redis provides the best performance for Moodle caching. Add to config.php:

$CFG->cachestore_redis_server = '127.0.0.1';
$CFG->cachestore_redis_port = 6379;

Then configure cache stores in Site Administration > Plugins > Caching > Configuration.

Cache store mapping

  • Application cache - Redis (primary performance gain)
  • Session cache - Redis or database
  • Request cache - File or Redis

Database optimization

MySQL/MariaDB tuning

Key settings for Moodle workloads:

innodb_buffer_pool_size = 70% of available RAM
innodb_log_file_size = 256M
innodb_flush_log_at_trx_commit = 2
query_cache_type = 0
query_cache_size = 0

Note: Query cache is disabled intentionally - it causes contention on write-heavy Moodle workloads.

Regular maintenance

  • Run OPTIMIZE TABLE on large tables monthly
  • Monitor slow query log for optimization targets
  • Keep statistics current with ANALYZE TABLE

Cron configuration

Moodle cron should run frequently but never overlap with user sessions for heavy tasks.

Best practices

  • Run cron every minute via system cron (not web-based)
  • Use admin/cli/cron.php for better performance
  • Schedule heavy tasks (backups, reports) during off-hours
  • Monitor cron execution time - should complete in under 60 seconds
* * * * * /usr/bin/php /var/www/moodle/admin/cli/cron.php > /dev/null 2>&1

PHP configuration

Moodle benefits from PHP-FPM with OpCache properly configured:

opcache.enable = 1
opcache.memory_consumption = 256
opcache.interned_strings_buffer = 16
opcache.max_accelerated_files = 10000
opcache.validate_timestamps = 0
opcache.revalidate_freq = 0

Set validate_timestamps = 0 in production - restart PHP-FPM after deployments.

Infrastructure considerations

Separate services

For larger deployments, separate:

  • Web servers (NGINX + PHP-FPM)
  • Database server (dedicated MySQL/MariaDB)
  • Cache server (Redis)
  • File storage (shared storage or object storage)

Load balancing

Multiple web servers require:

  • Shared session storage (Redis or database)
  • Shared file storage for moodledata
  • Sticky sessions or consistent hashing

Monitoring and benchmarks

Track these metrics to measure performance:

  • Page load time - Target under 3 seconds for course pages
  • Database queries per page - Monitor for regressions
  • Cache hit ratio - Should be above 90%
  • Cron execution time - Should stay under 60 seconds
  • Concurrent user capacity - Load test before enrollment periods

Related Resources


Need Moodle performance help?

CCMS provides Moodle hosting optimized for performance with Redis caching, database tuning, and ongoing monitoring.

Get Help