Seeking Guidance on Moodle Server Configuration

Seeking Guidance on Moodle Server Configuration

Andrei AG發表於
Number of replies: 7

Hi Team,


I am seeking advice on optimizing my Moodle server configuration. Currently, my production environment runs on Apache, but I have noticed that it performs significantly slower compared to my staging environment, which runs on Nginx. Given the performance difference, I am considering whether I should replicate the staging setup for production.
Current Staging Environment:

    Moodle Version: 4.5.2 (Build: 20250210)
    Number of Users: 9.000+
    Number of Courses: 114
    Content: Some courses contain videos, but most content consists of SCORM packages and PDFs. Large files are stored in an S3 bucket to reduce local storage load.
    Forever Courses : Some courses remain open indefinitely, while others follow a scheduled start/end date.

Server (AWS) and Database Setup:

    EC2 Instance Type: c5.4xlarge (16 vCPUs)
    Storage: 1,000 GiB EBS (with an S3 bucket for file storage)

RDS (Database):

    Database Engine: MariaDB 11.4.4
    Instance Class: db.t3.2xlarge
    vCPUs: 8
    RAM: 32 GB
    Storage: 77 GiB

Web Stack:

    Nginx + PHP-FPM
    OPcache (1GB allocated)
    Redis (Application & Session Storage)

Performance Metrics:

    Load average: 0.20, 0.27, 0.32
    Memory usage: ~24.9 GB free out of 32 GB
    OPcache memory: 1024 MB total, 825 MB free
    Redis is installed, but the performance test indicates that it is "untestable."

I have already installed and run MySQLTuner and adjusted some settings based on its recommendations.

Despite having Redis configured, Moodle’s built-in performance tests still indicate that Redis is "untestable." Below are some test results:
File Cache Performance:

    Tested: 0.0074 / 0.0016 / 0.0002 / 0.0013

Redis:

    Status: Untestable

Currently, my application and session storage mappings are set to Redis. However, I would like to confirm that Redis is functioning properly.
My Questions:

    Does my staging configuration seem suitable for production use?
    Are there further optimizations I should consider given the 9.000+ users and 114 courses (some with video content)?
    Has anyone encountered the Redis "untestable" issue, and if so, how was it resolved?

評比平均分數: -
In reply to Andrei AG

Re: Seeking Guidance on Moodle Server Configuration

Ken Task發表於
Particularly helpful Moodlers的相片

While your question is about Redis will leave that to folks who actually run Redis caching.

Thought I'd share an observation ... seems the 'darling' for hosting AMP stacks now-a-days is using PHP-FMP, but there aren't any moodle docs for configuring (or I haven't found where - which is possible)!

So in that light ...

found this reference:
https://www.inmotionhosting.com/support/server/php-fpm/php-fpm-settings-for-better-optimization/

Values below were ball park recommend by InMotion hosting.

PHP-FMP
Traffic Load    Average    Heavy
Max Children    25-35    40-60
Process Idle Timeout    100    100-150
Max Requests    200-350    400-600

pm_max_children: 500
pm_max_requests: 2000
pm_min_spare_servers: 1
pm_max_spare_servers: 25
pm_process_idle_timeout: 150
php_value_disable_functions: 0
pm_max_children: Max number of child processes
pm_max_requests: Number of requests a child process executes before respawning.
pm_min_spare_servers: Minimum idle server processes
pm_max_spare_servers: Maximum idle server processes
pm_process_idle_timeout: Time until an idle process is killed in s(econds), m(inutes), m(inutes), h(ours), or d(ays).
php_value_disable_functions: Functions to disable. This doesn’t overwrite php.ini settings.

ps aux |grep php-fpm
should show the path to the config file being used.
and there might/should be an include statement that will show path to other related conf files php-fpm will load.

From a config file:
;   dynamic - the number of child processes are set dynamically based on the
;             following directives. With this process management, there will be
;             always at least 1 children.
;             pm.max_children      - the maximum number of children that can
;                                    be alive at the same time.
;             pm.start_servers     - the number of children created on startup.
;             pm.min_spare_servers - the minimum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is less than this
;                                    number then some children will be created.
;             pm.max_spare_servers - the maximum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is greater than this
;                                    number then some children will be killed.


If you change config, restart service.

Then check that the changes you have made are in effect.
php-fpm -tt

'Spirit of Sharing', Ken

評比平均分數:Useful (1)
In reply to Andrei AG

Re: Seeking Guidance on Moodle Server Configuration

Howard Miller發表於
Core developers的相片 Documentation writers的相片 Particularly helpful Moodlers的相片 Peer reviewers的相片 Plugin developers的相片
The "untestable" thing is not an issue. It's just that the tests that Moodle includes don't work with Redis. I don't know why. It's always been difficult getting answers out of the people who developed the cache functionality.

Anyway, it doesn't mean that there's a problem.
評比平均分數:Useful (1)
In reply to Andrei AG

Re: Seeking Guidance on Moodle Server Configuration

Alain Raap發表於
Hi Andrei,

Performance can be optimized by using caching, caching and caching, for PHP the Zend Opcache, for session and Moodle MUC Redis, for the database InnoDB (load your database in memory). It all fits together when tuned in a way that you find your bottlenecks in your Moodle stack. It took us a lot of time, but we see that every new LTS version asks for a good performance test. Redis 'untestable' means that there is no test configuration found in [your site]/admin/settings.php?section=cachestore_redis_settings, configure it there and you can run the tests. But, as Howard mentioned, it's not a really good test to find out your Redis performance. You could try the Redis benchmark on the server, but that only gives you a view of the server itself, and not when a lot of clients cache their data in Redis. There is a plugin you can install to see some stats of Redis: https://moodle.org/plugins/tool_redis
I hope this gives you a little insight, feel free to contact me if I can help you, as we run almost the same stack.
評比平均分數:Useful (1)
In reply to Andrei AG

Re: Seeking Guidance on Moodle Server Configuration

Akash Yadav發表於
Hi,

It looks like you’ve done a great job setting up and analyzing your staging and production environments. The fact that your staging setup on Nginx is performing better than production on Apache is a strong indicator that you should consider replicating that setup for production.

1. Is Your Staging Setup Suitable for Production?

Yes, in most cases, Nginx + PHP-FPM performs better than Apache, especially for high-traffic environments like Moodle. Since you have 9,000+ users and a large number of courses, the switch could bring noticeable improvements. However, before making the final decision, you might want to test a few additional aspects:

• Load Testing: Even though staging performs well, running a stress test with simulated high concurrency (e.g., JMeter or Locust) can confirm if it will scale efficiently under real production loads.
• Auto-Scaling Considerations: Since you’re on AWS, it’s worth checking whether your infrastructure should include auto-scaling to handle peak traffic smoothly.
• Load Balancing: If you expect traffic to grow, setting up an Application Load Balancer (ALB) in AWS can help distribute the load evenly.

Once these aspects are verified, transitioning production to Nginx + PHP-FPM should be a good move.

2. Redis "Untestable" Issue – Possible Fixes

If Moodle's built-in performance test is marking Redis as "untestable", the issue could be related to configuration, connectivity, or caching settings. Here are some troubleshooting steps:

Check Redis Connectivity

Run this command on your server:
redis-cli ping
If Redis is working correctly, it should return:
PONG
If not, there may be an issue with the Redis service or its configuration.

Verify Moodle’s Redis Configuration

Make sure your Moodle config.php file includes the correct Redis settings:

$CFG->session_handler_class = '\core\session\redis';
$CFG->session_redis_host = '127.0.0.1'; // Change if using a remote Redis server
$CFG->session_redis_port = 6379;
$CFG->session_redis_database = 0;
$CFG->session_redis_auth = 'your-redis-password'; // If applicable
$CFG->session_redis_acquire_lock_timeout = 120;

Also, check Redis timeouts and memory settings by running:

redis-cli config get timeout
redis-cli config get maxmemory

Use Predis Instead of PHPRedis

Some users have resolved Redis performance issues by switching from PHPRedis to Predis. You can install Predis with:

composer require predis/predis
Then adjust your config.php file accordingly.

Retest Moodle’s Redis Performance

After making these changes, rerun Moodle’s built-in Redis performance test to check if the issue is resolved.

3. Additional Optimizations for High-Performance Moodle Hosting

Since your Moodle instance serves a large number of users, consider the following optimizations:

• Enable a Reverse Proxy (Cloudflare or AWS CloudFront): Helps cache static content and reduce direct server load.
• Fine-Tune MariaDB Settings: Even though MySQLTuner provides recommendations, additional tweaks to InnoDB settings can improve performance. Consider adjustments like:
• innodb_buffer_pool_size = 24G
• innodb_log_file_size = 512M
• innodb_flush_log_at_trx_commit = 2
• query_cache_type = 0
• Upgrade PHP: If possible, test PHP 8.3, as it provides better performance and security improvements.

4. Should You Fully Switch to the Staging Setup?

If your staging environment continues to outperform production under realistic load tests, switching it over makes sense. Just ensure Redis issues are resolved before deploying the changes.
If you are looking for a managed VPS hosting solution optimized for Moodle, you might want to check Onlive Server (https://onliveserver.com/). They offer scalable VPS and dedicated servers that can handle large Moodle installations efficiently, with built-in optimizations for Redis, MariaDB, and PHP-FPM.

Let me know if you need any further insights.
評比平均分數:Useful (1)