Most Moodle installations run fine with 50 users. The problems start at 500 concurrent users—page load times creep up, SCORM packages stall, and the admin dashboard becomes unusable. At 5,000 users, an untuned Moodle server will simply fall over during peak periods.
This guide covers the architectural decisions and configuration changes that take a Moodle installation from "works fine in testing" to "handles 10,000+ concurrent users without breaking a sweat." Written from real-world experience tuning Moodle for enterprise-scale deployments.
Understanding Moodle's Performance Bottlenecks
Before tuning anything, understand where Moodle actually spends its time. Three areas account for 90% of performance issues:
- Database queries: Moodle is famously query-heavy. A single page load can trigger 200+ database queries on an untuned installation.
- Session handling: PHP file-based sessions are a concurrency bottleneck. At high user counts, session file locking causes request queuing.
- File serving: Moodle routes all file requests through PHP (for access control). This is expensive at scale compared to direct nginx file serving.
Database Optimisation
Choose PostgreSQL Over MySQL
For new installations above 500 users, PostgreSQL consistently outperforms MySQL for Moodle's workload. The MVCC concurrency model handles Moodle's heavy read/write mix better than MySQL's row-level locking. If you're on MySQL and experiencing performance issues, migrating to PostgreSQL as part of a version upgrade is worth the effort.
Index Optimisation
Run the Moodle performance overview tool (Site administration → Reports → Performance overview) regularly. It will flag missing indexes. Additionally, analyse your slow query log and add compound indexes for the specific query patterns your installation generates—these vary based on your plugin mix.
Key indexes to verify exist on large installations:
- mdl_course_completions: (userid, course, timeenrolled)
- mdl_logstore_standard_log: (timecreated, userid, courseid)
- mdl_grade_grades: (userid, itemid)
Read Replicas for Reporting
Reporting queries—course completion reports, grade exports, activity logs—are expensive and can saturate your primary database during peak hours. Configure a PostgreSQL read replica and route all reporting queries to it. Moodle supports read replicas natively via config.php:
$CFG->dbslavehost = 'replica.yourserver.com';
$CFG->dbslaveuser = 'moodle_read';
$CFG->dbslavepass = 'password';
$CFG->dbslave = true;
Caching Architecture
Moodle's caching subsystem (MUC — Moodle Universal Cache) supports multiple backends. The default file-based cache is a performance bottleneck at scale. Replace it with Redis or Memcached.
Redis Configuration
Redis is the recommended caching backend for production Moodle. Install Redis on a dedicated server (not the same server as the database), then configure Moodle:
- Install the Moodle Redis plugin (available in the plugins directory)
- Configure in Site administration → Plugins → Caching → Configuration
- Set Redis as the store for Application cache, Session cache, and Request cache
- Set Redis maxmemory-policy to allkeys-lru
Expected performance improvement: 40-60% reduction in page load time on cache-warm requests. The first request after a cache miss will still be slow—this is normal.
OPcache Configuration
PHP's OPcache dramatically reduces the overhead of PHP file parsing. For Moodle, optimise OPcache settings in php.ini:
opcache.enable=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=10000
opcache.revalidate_freq=60
opcache.save_comments=1
The opcache.max_accelerated_files setting is critical—Moodle has thousands of PHP files. If this is too low, files get evicted and re-parsed constantly.
Session Handling
Replace PHP file-based sessions with Redis sessions. File sessions create a lock per user session, which at 1,000 concurrent users means 1,000 file locks competing for filesystem access.
Configure in php.ini:
session.save_handler = redis
session.save_path = "tcp://redis.yourserver.com:6379"
Set Moodle's session driver to match in config.php:
$CFG->session_handler_class = '\core\session
edis';
$CFG->session_redis_host = 'redis.yourserver.com';
$CFG->session_redis_port = 6379;
$CFG->session_redis_database = 0;
File Serving and CDN Integration
X-Sendfile for File Serving
Enable X-Sendfile to allow nginx to serve files directly rather than routing through PHP. This is particularly impactful for SCORM packages and course media files.
In nginx config:
location /dataroot/ {
internal;
alias /var/moodledata/;
}
In Moodle config.php:
$CFG->xsendfile = 'X-Accel-Redirect';
$CFG->xsendfilealiases = array('/dataroot/' => $CFG->dataroot);
CDN for Static Assets
Offload static assets (JavaScript, CSS, images, fonts) to a CDN. CloudFront or Cloudflare work well. Configure in Moodle:
- Site administration → General → HTTP security → CDN for static files
- Point to your CDN origin
- Ensure the CDN is configured to cache .js, .css, .png, .woff2 files with long TTLs
For SCORM packages specifically, CDN delivery can reduce load times by 60-70% for learners outside your server's geographic region.
PHP-FPM Pool Tuning
The default PHP-FPM configuration is too conservative for high-concurrency Moodle. Adjust pool settings based on your server's RAM:
pm = dynamic
pm.max_children = 50 ; (RAM in MB / 40MB per PHP process)
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.max_requests = 500 ; Prevent memory leaks accumulating
Moodle Application-Level Tuning
Cron Optimisation
Moodle's cron job is a frequent performance bottleneck. By default it runs every minute and processes everything in sequence. For large installations, break cron into parallel tasks:
# Run cron every minute
* * * * * /usr/bin/php /var/www/moodle/admin/cli/cron.php
# Run scheduled tasks in parallel (Moodle 3.7+)
*/5 * * * * /usr/bin/php /var/www/moodle/admin/cli/scheduled_task.php --execute=\core\task\send_new_user_passwords_task
Logstore Configuration
Moodle logs every user action by default. At scale, this generates millions of log entries per day and slows queries. Review your logstore retention policy—most organisations only need 90 days of detailed logs for operational purposes, with annual rollup summaries for compliance reporting.
Monitoring and Alerting
You can't optimise what you don't measure. Set up monitoring for:
- Application metrics: Page load time (target: <2s), error rate, active sessions
- Database metrics: Query latency (p95 and p99), connection pool utilisation, slow query count
- Cache metrics: Redis hit rate (target: >95%), eviction rate, memory usage
- Server metrics: CPU utilisation, memory usage, disk I/O wait, network throughput
Grafana + Prometheus is the standard stack for this. Moodle's built-in performance overview is useful for initial diagnosis but insufficient for ongoing monitoring.
Conclusion
Scaling Moodle to 10,000+ concurrent users isn't about buying a bigger server—it's about architectural decisions at every layer of the stack. Redis caching, PostgreSQL with read replicas, PHP-FPM pool tuning, and CDN integration collectively deliver an order-of-magnitude performance improvement over a default Moodle installation.
The organisations that get this right don't wait for performance problems to appear. They instrument their installation from day one, establish baselines, and tune proactively. By the time a competitor's platform is falling over during peak training periods, a well-architected Moodle installation is handling the load without incident.