Hardware and performance

 
 
Picture of Ashok Harnal
Caching web pages to enhance performance--where to include directives
 

The performance enhancing page of Moodle suggests to include the following code in the <directory> section of virtual server config file.

<IfModule mod_expires.c>
 ExpiresActive On
 ExpiresDefault "access plus 1 seconds"
 ExpiresByType text/html "access plus 1 seconds"
 ExpiresByType image/gif "access plus 1 week"
 ExpiresByType image/jpeg "access plus 1 week"
 ExpiresByType image/png "access plus 1 week"
 ExpiresByType text/css "access plus 1 week"
 ExpiresByType text/javascript "access plus 1 week"
 ExpiresByType application/x-javascript "access plus 1 week"
 ExpiresByType text/xml "access plus 1 seconds"
</IfModule>

The httpd.conf file on my Moodle setup in
Fedora/CentOS contains the following two <directory> sections:

<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

And the other the following:

<Directory "/usr/moodle/mymoodle" >
DirectoryIndex index.php
AcceptPathInfo on
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>

Moodle files are installed in the directory /usr/moodle/mymoodle. I suppose
that the suggested lines will need to be added here making the revised configuration file as:

<Directory "/usr/moodle/mymoodle" >
DirectoryIndex index.php
AcceptPathInfo on
AllowOverride None
Options None
Order allow,deny
Allow from all
<IfModule mod_expires.c>
 ExpiresActive On
 ExpiresDefault "access plus 1 seconds"
 ExpiresByType text/html "access plus 1 seconds"
 ExpiresByType image/gif "access plus 1 week"
 ExpiresByType image/jpeg "access plus 1 week"
 ExpiresByType image/png "access plus 1 week"
 ExpiresByType text/css "access plus 1 week"
 ExpiresByType text/javascript "access plus 1 week"
 ExpiresByType application/x-javascript "access plus 1 week"
 ExpiresByType text/xml "access plus 1 seconds"
</IfModule>
</Directory>

There is no VirtualHost directive/configuration in my httpd.conf. I suppose
there is only main server or the default server.

I will be very grateful for confirmation.





 
Average of ratings: -
Picture of Visvanath Ratnaweera
Re: Caching web pages to enhance performance--where to include directives
Group Particularly helpful Moodlers
Hi Ashok

You must be referring to http://docs.moodle.org/en/Performance_recommendations#Apache_performance
===
Caching (unsupported) - Please note that this kind of caching may create major problems during upgrades. Apache can be told to make pages load a lot faster by specifying that the browser should cache some various page elements such as images and reuse them from local memory rather than ask for them again every time a page is requested. How to do this varies slightly between OSes but there are two basic steps:

1. Install and enable mod_expires - refer to documentation or man pages

2. Add this code to the virtual server config file within the section for the root directory (or within the .htaccess file if AllowOverrides is On):
===

Apache would take this kind of instructions at many levels. Since you have "AllowOverrde none" you can't put that in .htaccess. Otherwise you can make it valid for all Apache virtual servers by putting it into apache2.conf or only for your Moodle as you've suggested. See http://httpd.apache.org/docs/2.2/mod/mod_expires.html.

mod_expired is a "passive" module, in certain cases it wouldn't change the "expires" header. You must watch its effect from the client end. See http://metaskills.net/2006/02/19/how-to-control-browser-caching-with-apache-2/.

Of course the module must be available and activated. Under Debian look into /etc/apache2/mods-available/ and /etc/apache2/mods-enabled/. There are also two scripts a2enmod/a2dismod to enable/disable Apache modules - I never use them.
 
Average of ratings:Useful (1)
Picture of Ashok Harnal
Re: Caching web pages to enhance performance--where to include directives
 

Many thanks for your detailed reply and guidance. Let me see how far the site performance gets improved.

 
Average of ratings: -
Picture of Andrew Nicols
Re: Caching web pages to enhance performance--where to include directives
Group DevelopersGroup Moodle HQGroup Particularly helpful MoodlersGroup Testers

I think that the '(Unsupported)' bit, and the note about Moodle 2.X can now be safely removed, or changed to 2.0 - 2.?.

Things have gotten a lot better of late owing to use of the cache purge timestamp in the URL for all themes, images, and javascript

Andrew

 
Average of ratings:Useful (1)
Picture of Petr Škoda
Re: Caching web pages to enhance performance--where to include directives
Group DevelopersGroup Documentation writersGroup Moodle HQGroup Particularly helpful Moodlers
GRRRR, somebody removed my notes and made it supported - DO NOT USE THE CACHING HACK ON 2.x PRODUCTION SITES!!!
 
Average of ratings:Useful (2)
Picture of Andrew Nicols
Re: Caching web pages to enhance performance--where to include directives
Group DevelopersGroup Moodle HQGroup Particularly helpful MoodlersGroup Testers

After much discussion with Petr, I retract my previous statement and have been persuaded otherwise.

There should be no benefit to enforcing caching at the web server. If files are served correctly through Moodle (and they should be across core) then caching is already set appropriately for all JS, images, and CSS. If there are cases you're aware of where this does not happen, then you should raise a Moodle issue. That said, there may be times within Moodle where this is deliberate because the latest version of a file needs to be served entirely uncached.

Forcing caching on the web server means that any files changed may be cached for an undesirable period of time when it should not be. This has the potential to mean that cached copies of files are used incorrectly in scenarios such as during upgrade.

Andrew

 
Average of ratings:Useful (2)
Picture of Ashok Harnal
Re: Caching web pages to enhance performance--where to include directives
 

Thanks for the guidance. I have a production server. And I have now removed caching hack from the web-server configuration.

 
Average of ratings: -
Picture of Visvanath Ratnaweera
The documentation needs to be corrected
Group Particularly helpful Moodlers
Pl. follow up in the "Moodle community sites" forum: https://moodle.org/mod/forum/discuss.php?d=223834 (Moodle documentation: Performance docs unstable).
 
Average of ratings: -
Mary Cooch
Re: The documentation needs to be corrected
Group Documentation writersGroup Moodle Course Creator Certificate holdersGroup Moodle HQGroup Particularly helpful MoodlersGroup TestersGroup Translators

Just came here to confess - I removed the bit about unsupported when Andrew mentioned it but I didn't notice his retraction later  and so it didn't immediately get changed back- so Petr's grrr can go to me not anybody elsesmile

 
Average of ratings: -
Picture of Visvanath Ratnaweera
Re: The documentation needs to be corrected
Group Particularly helpful Moodlers
Hi Mary

You must be talking to Petr https://moodle.org/mod/forum/discuss.php?d=223564#p972043, you have replied to my post: https://moodle.org/mod/forum/discuss.php?d=223564#p972729, and the follow up to my post should be in the "Moodle community sites" forum: https://moodle.org/mod/forum/discuss.php?d=223834.

Yes, your edit is in the open: http://docs.moodle.org/23/en/index.php?title=Performance_recommendations&action=historysubmit&diff=102588&oldid=102366. But the problem is not solved, because the caching is different amoung the Moodle versions (1.9, 2.0, 2.2, ...). See the discussions linked to the post in the "Moodle community sites" forum.
 
Average of ratings: -