Moodle Cache Changes

Moodle Cache Changes

by Callum Laverick -
Number of replies: 18

Hey,

I have read the Moodle cache documentation and am still struggling to achieve in what I need to do.

I am trying to reduce pageload times and overall site performance, I manage to find an old thread about this topic which recommended changing the values in the .htaccess file to improve upon the standard Moodle cache timings, the code is as follows:

 ## EXPIRES CACHING ##

<IfModule mod_expires.c>

ExpiresActive On


## IMAGES ##

ExpiresByType image/jpg "access plus 1 year"

ExpiresByType image/jpeg "access plus 1 year"

ExpiresByType image/gif "access plus 1 year"

ExpiresByType image/png "access plus 1 year"

ExpiresByType image/x-icon "access plus 1 year"


## CSS ##

ExpiresByType text/css "access plus 1 month"


## HTML ##

ExpiresByType text/html "access plus 1 month"


## JAVASCRIPT ##

ExpiresByType text/javascript "access plus 1 month"

ExpiresByType text/x-javascript "access plus 1 month"

ExpiresByType application/javascript "access plus 1 month"

ExpiresByType application/json "access plus 1 month"

ExpiresByType application/x-javascript "access plus 1 month"

ExpiresByType application/x-shockwave-flash "access plus 1 month"

ExpiresByType application/pdf "access plus 1 month"

ExpiresDefault "access plus 1 month"

</ifModule>


However this is having zero effect on performance and I am unsure in what to do to improve site caching. Any suggestions or recommendations would be great. 

P.S. Site is hosted on shared hosting (linux) and managed through cpanel.

Thanks in advance 

Callum 

Average of ratings: -
In reply to Callum Laverick

Re: Moodle Cache Changes

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I wouldn't have thought it would to be honest. 

What version of Moodle is this? How slow is slow? What have you done (if anything) to determine where the slowness is coming from? Is there any monitoring on the server?


In reply to Howard Miller

Re: Moodle Cache Changes

by Callum Laverick -

Moodle is running version 3.3, used range of different sites to determine speed, but currently finding gtmetrix(.)com to be the most consistently accurate. The site is not running slow, average fully load time of around 10.2sec, the only category that is really falling behind on is Leverage browser caching, currently scoring 16/100. I am just looking to scrape seconds off the load times and trying to improve overall general performance and the biggest area that needs this is caching. I do monitor the server when testing and nothing seems wrong on that end.

In reply to Callum Laverick

Re: Moodle Cache Changes

by Mathew Gancarz -
Picture of Core developers

Hi Calllum, that is pretty slow.. Is that 10 seconds for the login page or for a dashboard/page with lots of content on it?

We use gtmetrix.com and it does a nice waterfall chart if you click over to the "Waterfall" tab. Ours looks something like the below. The GET logo, help and user '429 ms' bars are the images loading, and the next biggest, the GET all '320 ms' bar is the CSS for the site theme, which is most of what caching would help with, but if something else is causing the slowness, tweaking the cache settings won't help you.


In reply to Mathew Gancarz

Re: Moodle Cache Changes

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi Mathew,
your graph shows HTTP Status 200 where 304 was expected (or 200 and the word cached somewhere w/ 0ms for the time spent, depending on the browser dev tools).

Did you purge the theme cache before getting these stats?
Do you have HTTP caching disabled (see Theme Designer Mode)?

Try the same tracing on https://moodle.org and you'll see what I mean.

HTH,
Matteo

In reply to Matteo Scaramuccia

Re: Moodle Cache Changes

by Mathew Gancarz -
Picture of Core developers

Hi Matteo, I ran the same gtmetrix test on moodle.org and got the below results (had to stitch a few images together). The settings used were: Testing from Vancouver, Canada. using Firefox (Desktop) with an Unthrottled Connection


In reply to Mathew Gancarz

Re: Moodle Cache Changes

by Mathew Gancarz -
Picture of Core developers

Interestingly, the same test re-ran through Gtmetrix with Google Chrome desktop completes in about 2.5 seconds, with I think the major differences being that it does the youtube embed and fonts.gstatic.com downloads in a fraction of the time. It shows 141 ms vs 760 ms for Youtube and 20 ms vs 350 for fonts.gstatic.com. I'm guessing Google Chrome has some optimizations for getting Google fonts. 

In reply to Mathew Gancarz

Re: Moodle Cache Changes

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Guessing that gtmetrix doesn't obey to those HTTP Headers related to caching i.e. real-life Moodle user experience is far better than these numbers, thanks to those headers (with proper theme setting, see above).

Try w/ the Browser Developer Tools like those in Chrome via <F12>, tab Network.

HTH,
Matteo

In reply to Matteo Scaramuccia

Re: Moodle Cache Changes

by Mathew Gancarz -
Picture of Core developers

Agreed. With dev tools, it shows a bunch of pulls from disk cache. Load time for moodle.org shows as 1.43 s. Gtmetrix changed some of their timing behaviour in February 2017, which made all of their reported scores become a bit longer than what users may actually experience. See https://gtmetrix.com/blog/new-performance-timings-available-default-to-fully-loaded-time/ for the technical details.

Average of ratings: Useful (1)
In reply to Callum Laverick

Re: Moodle Cache Changes

by Jeff White -
No idea on the settings you posted but wouldn't updating this entry in moodle/config.php do the trick? 


// Seconds for files to remain in caches. Decrease this if you are worried
// about students being served outdated versions of uploaded files.
//     $CFG->filelifetime = 60*60*6;


Average of ratings: Useful (1)
In reply to Jeff White

Re: Moodle Cache Changes

by Callum Laverick -

Hi Jeff,

Thank you for your reply, I will give this a go this afternoon and see if this works. Do you use this with your site? Does it increase the performance (load times) of the site much?

In reply to Callum Laverick

Re: Moodle Cache Changes

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hello,
please share a CSS or JS network request and its response from Moodle: you can make screenshots of the tab Network from the Browser Development Tools.
Guessing that your forced headers conflict with the one imposed by Moodle due to theme settings e.g. Cache-Control: no-cache.

I'm currently excluding issues w/ the time required to serve the HTML pages from Moodle, which could be really relevant compared to serve related JS/CSS files and static images.
In this case https://moodle.org/plugins/report_benchmark could give an approximate picture of the power available on your environment: see https://moodle.org/mod/forum/discuss.php?d=335357 for numbers from other systems.

HTH,
Matteo

Average of ratings: Useful (1)
In reply to Matteo Scaramuccia

Re: Moodle Cache Changes

by Callum Laverick -

Hello All,

Just wanted to say thank you first for all the responses to my initial post. Sorry about the late reply I have been in the process on acquiring a new dedicated server. My waterfall gtmetrix results are appalling in comparison to Moodle.org as seen in 'crapresults2'.

Matteo, I have attached JS network request responses please see below. Also worth noting that that the load time through google chrome developer tools came in at 2.32s... Which as seen in comparison to gtMetrix is better but still not perfect load time, anyone know a reason why these results differ so much?

The report benchmark plugin not really needed right now for me, My site I know for a fact is on a cheap large shared hosting solution which for previous sites worked fine. But my current site is now going to be upgraded onto a med/high spec dedicated Linux server due to growth in requirements.


Attachment CrapResults2.png
Attachment JS.PNG
In reply to Callum Laverick

Re: Moodle Cache Changes

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi Callum,
from what I can see the Moodle HTTP headers do their work nicely - you could try even to remove the ones forced via Apache: please, trust Moodle in this area wink - : everything is based on your local disk cache and nothing come from your server (but the HTML file, did you look at it too?) i.e. it looks like your own machine is slow in processing all those files.

Times from gtmetrix - I'm not familiar with this tool - can be affected also by the bandwidth available from your server.
Installing that plug-in will give you a benchmark of your local environment with some "relative" numbers that could identify bottlenecks in your disk or your database access: it's worth giving it a try.

HTH,
Matteo

Average of ratings: Useful (1)
In reply to Matteo Scaramuccia

Re: Moodle Cache Changes

by Callum Laverick -

Hi Matteo,

I think I will be removing the ones forced via Apache, my Moodle trust has been restored big grin , the problem I believe has been narrowed down to the poor performing server and probably not the best work computer. I will be downloading the bench marking plugin you previously mentioned as gtmetrix is still helpful but it is producing some inconsistent results.

Thank you Matteo for your help in diagnosing this issue.

Cheers,

Callum

In reply to Matteo Scaramuccia

Re: Moodle Cache Changes

by Callum Laverick -

Hi Matteo,

I managed to get the bench-marking plugin up and running with some interesting results. After 10 tests my results had a range of about 510 - 550 points. Most average result is posted below. And now I know it was mainly a hardware issue rather than that of a software. I have to revert the changes I made with Moodles caching and get a better server to solve this. Thank you once again and I will most certainly keep using this useful tool.

Cheers

Callum

Attachment Average Bench Mark.PNG
In reply to Callum Laverick

Re: Moodle Cache Changes

by Jeff White -

Hello Callum, 

I do not use this setting as I rely more on the default caching times of Moodle. It just sounded like a setting you were trying to do with your previous post. I dont think the direction you are going to improve performance is the right way to go. Do the basics with Opcache and using moodle default caching method and try to identify what is the bottleneck for your environment. 

FYI: 10 second load times is abhorrent. Your goal should be under a second in average page load times. 

In reply to Jeff White

Re: Moodle Cache Changes

by Chris Fryer -

Just to reaffirm what Jeff is saying, Moodle is pretty good with its Cache-control headers.  It sets "public" and "private" appropriately, and has good "max-age" directives for things like the theme.  But these settings are really only useful for *returning* users.  First-time visitors, or people who dump their browser cache at shutdown, won't have any of your site assets stored locally.

It's not clear what your architecture is.  Do you have the web server, database and files all on one machine, or have you scaled out?

If your moodledata volume is remote to the web server, you might find (as we do) that you get a lot of performance improvements from having a key/value store like Memcached.

https://docs.moodle.org/33/en/Caching

Turn on "performance info" in the "debugging" section of the admin menu (/admin/settings.php?section=debugging) and switch to a theme that displays it.  This will give you clues.

Above all, make sure you've tuned your database as finely as you can.  If you're using MySQL, the quickest possible win is to ensure you've set InnoDB's Buffer Pool settings (especially innodb_buffer_pool_size and innodb_buffer_pool_instances) appropriately.  Get as much of your DB into memory as you can, so you stay off those disks.

https://dev.mysql.com/doc/refman/5.6/en/innodb-buffer-pool.html

Chris

Average of ratings: Useful (1)
In reply to Chris Fryer

Re: Moodle Cache Changes

by Callum Laverick -

Hi Chris,

I think I have narrowed it down to choice of poor theme/hosting/database setup.

I am now currently in the process of getting new dedicated hosting with the current spec:

  •  Processor: Intel Quad Core Xeon E3-1230 v5 (3.40 Ghz)
  •  Memory: 32GB DDR4 ECC
  •  Storage: 2x250 SSD Samsung 850
  •  OS: Linux-CenOS 7 64bit
  •  Control Panel: cPanel with WHM
  •  Bandwidth: 10TB Data Transfer on a 1Gb/s port

I know a separate server for the Database would improve performance significantly however currently working with a small budget so this is the best possible solution. I will be placing the database on a separate SSD and this will help a little with performance. 

I am also using a SQL database and your tip of 'InnoDB's Buffer Pool settings (especially innodb_buffer_pool_size and innodb_buffer_pool_instances) appropriately' I will be looking into this once the new host has been set up and configured.

Will let you know how it all goes, but thank you for your help.

Cheers

Callum