Miches
March 13, 2023, 8:02am
1
Hello Forum,
I wanted to ask what is the “best” setting for PHP8 OpCache in combination with Matomo. I have e.g.
opcache.memory_consumption=128
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=15000
opcache.revalidate_freq=10
opcache.save_comments=1
opcache.max_wasted_percentage=15
opcache.enable_cli=1
opcache.validate_root=1
opcache.fast_shutdown=1
Hi @Miches
There is a ticket at:
opened 07:30PM - 24 Mar 21 UTC
c: Performance
Help wanted
c: Documentation
Using OPcache can speed up Matomo quite a bit as it avoids having to interpret t… he same PHP with every single page request.
Especially now with PHP 8 and JIT compiling (which is implemented as a part of OPcache) it might bring even more of a performance benefit.
There also should be no disadvantages (apart from a bit of memory usage from the cache) as Matomo already clears the cache on update/installs and for an application like Matomo everyone should be using `opcache.validate_timestamps=1` which slows down the cache a bit, but should avoid ever serving something different than the PHP file (maybe check `opcache.revalidate_freq`).
So I think we should:
- encourage more Matomo users to enable OPcache
- document recommended settings
- add a system check to warn against bad settings and generally recommend setting it up
(for reference: Nextcloud shows [a system check warning](https://github.com/nextcloud/server/blob/2afa1c57393790b33bc6593f9215482d8a4dd9f9/apps/settings/lib/Controller/CheckSetupController.php#L427-L453) if it isn't set up)
A bit more experimental, but especially with the JIT feature of PHP 8 it might also be interesting to look into opcache for php-cli. Generally most people recommend not using OPcache for php-cli as it is a in-memory cache which would mean that a new php-cli process would start with a fresh cache making it useless. But since PHP 7 one can alternatively use a file cache (`opcache.file_cache`) which would stay between calls and with the JIT compiler some hot loop during archiving might receive
quite a bit of speedup. (I have not yet tested Matomo with JIT)
Slightly related: If someone wants to do testing with OPcache, I can recommend https://github.com/amnuts/opcache-gui which gives a nice overview over the current cache status
Maybe if you install and enable the following plugin you can get some help as it contains a system check urging people to enable OPcache and checks a few options for correctness (cite: Lukas Winkler)?