Optimal Opcache settings?

myH2Oservers

Verified User
Joined
Mar 13, 2006
Messages
235
Location
Netherlands
We use Opcache for PHP caching. Since PHP continuously improves we are looking what the optimal Opcache settings could be. This is mainly regarding the following settings:

opcache.memory_consumption=3072
opcache.interned_strings_buffer=32
opcache.max_accelerated_files=40000

After tests it seems that setting the interned_strings_buffer too high this leads to a worse performance but not on every server. We are curious: what settings are you using for these 3 values? Ofcourse this will depend on how many websites and the specs of the server. Lets say the server has +/- 200 users/300 websites and 12 GB of memory. Please let me know what settings you are using, how many users/websites and what the specifications of the server are.
 

zEitEr

Super Moderator
Joined
Apr 11, 2005
Messages
13,871
Location
GMT +7.00
Looking for Optimal opcache settings and trying someone's else setup is not what you would really like, believe me.

The option opcache.max_accelerated_files does not depend on a number of sites and a number of users. A single site written with the help of a Zend framework might have much more PHP scripts than 10 simple WP sites. So you should not count on these numbers, but use find /home/ -name \*.php to see how many files you have there.

As for
opcache.memory_consumption you will need to monitor closely number of hits and misses together with an amount of used memory. You don't want to waste memory, but opcache should have enough RAM for caching most used PHP scripts.
 

myH2Oservers

Verified User
Joined
Mar 13, 2006
Messages
235
Location
Netherlands
Hi Alex, thank you for your answer. The main reason of my question is that most tutorials advice to use lets say 256 MB or 512 MB for memory_consumption. We already use 3 GB. This can mean 2 things:
- We have to conclude that we missed the good point and 3 GB is way to much (same goes for our other settings).
- These tutorials are not written for larger usage.

Therefore i was interested in other hosters their config, just to compare. Not to take it as a new truth ;)

I can imagine that assigning too much memory or using a too high accelerated files number at some point will hurt performance instead of deliver performance. For example at the point that looking at the accelerated_files index is taking more time than simply calculating the PHP code. About the accelerated files: i checked 1 server and it has 0.5 million php files in /home. I am not sure if that is the amount we want to set in the accelerated files.
 

zEitEr

Super Moderator
Joined
Apr 11, 2005
Messages
13,871
Location
GMT +7.00
Give this a try https://github.com/amnuts/opcache-gui/ and see how good your opcache works. I did not compare time to search cache VS time to process PHP, so I don't have anything to comment here. Probably someone else has more details on it.

We use:

Code:
opcache.memory_consumption=512
opcache.max_accelerated_files=16000
for default installations as a starting point.

At least one of the recently maintained by me server has 4Gb limit in opcache with 2.5Gb of average usage (with 32Gb of total RAM).
 

M7Web

Verified User
Joined
Jul 13, 2019
Messages
95
Always have questions about optimization, php, MySQL, apache and Nginx, is there any tutorial?
 

wattie

Verified User
Joined
May 31, 2008
Messages
994
Location
Bulgaria
The optimal settings for opcache on PHP-FPM with shared hosting (many sites) is... disabled :) This is personal opinion due to personal experience of course.

My reasons:

1. I did not notice any difference in overall load. My bottleneck is the disk usage and it did not decrease. No speed difference in some heavy websites loading time too.
2. Each php-fpm process becomes huge because of the cache each process must carry on

So what happens is that I wasted lots of ram for no benefit.
 
Top