Opcache, Moodle 2.6, and zend

Opcache, Moodle 2.6, and zend

by Rick Jerz -
Number of replies: 4
Picture of Particularly helpful Moodlers Picture of Testers

Howard (and others) I have been working with Moodle 2.6+ (Build: 20131205), PHP 5.5.6, and opcache.  I have added the following lines to php.ini as you had suggested in one of your other posts.  I am observing some behavior that I do not understand, so I thought that I would seek your help (or others.)

 [opcache]
opcache.enable =
opcache.memory_consumption = 128
opcache.max_accelerated_files = 4000
opcache.revalidate_freq = 60

 ; Required for Moodle
opcache.use_cwd = 1
opcache.validate_timestamps = 1
opcache.save_comments = 1
opcache.enable_file_override = 0 

; Experimental for Moodle 2.6 and later
;opcache.fast_shutdown = 1
;opcache.enable_cli = 1 ; Speeds up CLI cron

On the http://php.net/opcache webpage, it is suggested to add “zend_extension=/full/path/to/opcache.so” in php.ini.  I found the path to opcache.so  and added the following line to php.ini: 

zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20121212/opcache.so

On my virtual server, and have played around adding and removing the zend directive.  Here is the odd behavior: 

If I have this zend directive added, when I install Moodle and get to the page where Moodle checks for all its correct extensions, the opcode message is green, okay, suggesting that everything is fine.  However, after turning on “debugging|show performance information,” the page loading performance is slower with this zend directive on.  If I comment out this directive (i.e., remove it), the page load performance improves, by about 25%.   With the directive turned off, a new install of Moodle provides the warning about opcache.

1)    Why do you think this is?  What does zend do, and why is it slowing down page loads?

2)    Am I missing some additional setting that needs to be turned on within Moodle?

3)    Might the performance improve with zend turned on over time, or maybe with more complex moodle pages?

4)    Might I be missing something else?

To add a little more to my puzzle, when I compare the Plugins|caching|test performance results, with the zend directive turned on the File cache results for 5000 requests is about 10% better than with the zend directive turned off.  So maybe zend really does help with more activity.

Thanks.

Average of ratings: -
In reply to Rick Jerz

Re: Opcache, Moodle 2.6, and zend

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

How long has Moodle been running (actually looking at pages) before you test it? It's normal for the cache to slow down the site until the pages have actually been cached. So, you need to switch on the cache, run through all your test pages and then do it all again. The timing is valid the second time (now that the pages are cached).

There are viewers available for seeing what the cache is doing - and that's a good idea. There's some info that might be useful here - http://rtcamp.com/tutorials/php/zend-opcache/

In reply to Howard Miller

Re: Opcache, Moodle 2.6, and zend

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers

Thanks for your thoughts and ideas.

This is a brand new install of Moodle, experimental.  So it is not seeing the normal load yet.  I am configuring this new VPS to try to take advantage of the many things that I learned here on Moodle.org.  I am so happy that I have Moodle 2.6 running, along with the Opcache, PHP 5.5.6, and mySQL 5.5.32.  I will study your reference about zend-opcache some more.

I also had success improving my.cnf, based upon the many things that I have learned.  At this point, I am not sure if it did anything.  I am going to load my production Moodle into my experimental Moodle so that I have a better environment for testing.

I plan to explore optimizing my databases next.  Then, a few more changes and experiments.

Is there any other thing that you would highly recommend that I try?  I did not see any other "Moodle settings" to mess with, yet.

Thanks again.

In reply to Rick Jerz

Re: Opcache, Moodle 2.6, and zend

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

There are, I suppose, two kinds of performance optimisations - 1. Those that make the page load faster for everyone even if there's just you using the site and 2. Those that allow more people to use the site before it becomes unusably slow. They are, of course, interrelated.

Using opcache, should make the page load a bit quicker for everyone (once cached) but it will also lower the processor load and so you should see lower load with lots of users on the site.

Apache and MySQL optimisations are mostly about optimising the RAM you have. As Moodle is a big lump of software it can make Apache burn up memory. The default Apache settings tend to be for static web sites and will require winding back a bit for Moodle. MySQL on the other hand tends to be set up very conservatively and will happy use all the memory you give it - as long as you tell it to. Memory optimisation is a balance between actually using the memory you have and going into swap (which generally means the death of your site).

All this rather relies on you having some idea what is going on. This means you need to measure your server activity. I favour munin for general use. It's really simple to set up and also reasonably intuitive to see the results. There are other options which are often more appropriate to solving specific problems.

So, measure what's going on and start to tune your system. There's lots of advice out there but the best thing is to have a go and see what happens.

PS. One problem I'm seeing increasingly is VPSs with dog-slow disk IO times. Moodle's 'MUC' cache writes to disk by default and this will kill your site if the disk is slow. You would need to look at alternatives if that was the case (e.g. memcached). Don' t confuse this with opcache. This is Moodle's internal cache I'm talking about.

Average of ratings: Useful (1)
In reply to Howard Miller

Re: Opcache, Moodle 2.6, and zend

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers

So, "opcache" is meant to help a little of both #1and #2.

For several years, I have desired to get "caching" working on my Moodle.  Here is my current logic.  Since opcache is somewhat built into Moodle 2.6 and PHP 5.5.?, why not use it?  Also, the installation seems fairly straightforward.  In fact, this is the first time that I have succeeded getting a cache to work. So I would like to stick with it (until it breaks).  I think I will continue working with it over my semester (Christmas) break, and see how it goes.

I am the most active user of my Moodle site, so I am going to use my own judgment, along with whatever statistics I can gather, to assess my progress.

Yep, one can only get so much performance from a VPS.  At this point in time, the GoDaddy VPS that I have for experimenting fits my budget.  I am getting 2GB RAM, 60GB disk space, a company that manages many systems, for around $30 US per month.

Howard, I certainly appreciate the time you devote to helping users here on Moodle.org.  You will see me continuing to ask questions, as I now have a little time to experiment and learn.  Thanks.