-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OPcache recommendation wrong (opcache.enable_cli=1) #1439
Comments
@tessus Thanks for this. Makes total sense. We should change it. |
Fix is in nextcloud/server#15468 |
@MorrisJobke Thanks. I just saw that you have already fixed it in the server check. I would have opened another issue in the server repo for this. I originally opened this issue for the documentation: https://docs.nextcloud.com/server/15/admin_manual/installation/server_tuning.html#enable-php-opcache But I am more than happy that it was fixed in the server. Cheers. |
@tessus Another question, I hope it's okay I ask it here, is the recommended OPcache size value:
|
I couldn't find that one when I worked on it.
I actually changed it to 128MB, because I had an instance with some apps enabled that where quite have and reached over the 64 MB. Does that make sense to you? |
@MorrisJobke I am not sure how this OPcache size is handled. Usually a cache should be not much larger than the amount that is actually used, since larger cache reduces performance for the individual request usually. So if there is any way to have the recommended cache size dependant on the actual amount/size of PHP files of the instance, this would be beneficial. In case it is also a question how much the performance decreases if single scripts are not cached due to max size reached. |
This is not how a cache works. In that case eviction occurs (by some alogorithm like LRU, LFU, FIFO, ...) and the new csript will be optimized and added to the cache. Thus the perf hit only amounts to removing data from memory. That's it. |
@tessus Btw. couldn't some method from opcache.php be used to check currently used OPcache size and file count and recommending the next power of two in admin panel in case max size is full or close to? Perhaps I should open a new issue about this, also based on some new evaluation how much cache is used when installing large amounts of apps. |
Hmm, I worked in DB2 development for many years and data is always manipulated or read from bufferpools (except large objects). This means that data has first to be fetched into the bufferpool to be used. This also means the larger the bufferpool, the better it is for performance. I don't see a bigger OPcache memory allocation to be detrimental to performance. e.g. the |
@tessus But lets see how much OPcache is actually used by Nextcloud:
|
+ DietPi-Software | Nextcloud: Do not set "opcache.enable_cli=1" any more, which is not recommended since Nextcloud v16.0.1: nextcloud/documentation#1439
+ DietPi-Patch | Nextcloud: Do not set "opcache.enable_cli=1" any more, which is not recommended since Nextcloud v16.0.1: nextcloud/documentation#1439
@MichaIng thx for the link.
I really would have to look at the source code, but something seems not quite right here. Anyway, I really do not want to go off-topic, thus you can always drop me an email to talk about database engine internals.
Yes, if you tune the parameters accordingly. However, as you can see, you did not hit the limit of files. |
Ah sorry, I wanted to ask if theoretically all However from the actual OPcache usage it can be taken as result that |
@MichaIng you are on the correct path already. files which are not served by php-fpm or the php module will never be in the cache. You can always use blacklists for settings files. The suggested value of 1 for |
We have this in place to have a somewhat okayish caching (for bigger installations this still caches all the files of one second). On the other side we do sometimes changes to the config from the CLI and as CLI and Webserver use different caches the admin needs to be aware of either a) waiting 60 seconds or b) purging the cache of the webserver after one of these changes. Both options are unfortunately hard to teach to 10s of thousands of administrators out there. :/ I know that it is not a nice and perfect solution but it is at least a quite good one. Sadly we need to go sometimes a way of compromises. If we would have full control we would only invalidate the cache after an upgrade, app update or config cache, but unfortunately that is not easy with CLI and web server administration in one product (and we are not even taking about multiple web servers that have then similar things to respect). |
Thanks nevertheless for the deep dive into the mechanics of caching and how to improve here. We are happy to make this better when the scenarios we are serving under are fully supported. |
Just found that the recommended (by Nextcloud) However I still think it would be beneficial to use opcache_get_status() to check for actual usage before recommending (max size + files) values. This would also cover cases where other websites with large code base are active beside Nextcloud, so that the currently recommended values might be too low. |
Mind to open a ticket in the server repo with this? |
Makes sense, done: nextcloud/server#15522 |
I agree that recommendations should be made which are best for nextcloud. And when it comes to performance I totally agree that these recommendations should be followed and even a warning given in the admin settings. I'm glad though that you decided not to emit a warning when |
Yep - was also my idea back then. If the admin knows what it does then we are fine with a different value. |
There is also a recommendation for Should this be removed too? https://www.php.net/manual/en/apc.configuration.php#ini.apc.enable-cli |
This is a big YES - definitely !!!! The following is stated in the docs for this parameter: Mostly for testing and debugging. Setting this enables APC for the CLI version of PHP. Under normal circumstances, it is not ideal to create, populate and destroy the APC cache on every CLI request, but for various test scenarios it is useful to be able to enable APC for the CLI version of PHP easily. |
But indeed it does not make sense on first thought. |
So, this article is wrong?
https://pierre-schmitz.com/using-opcache-to-speed-up-your-cli-scripts/
No, this article is correct. The article talks about `opcache.file_cache`, which is used to write the compiled data into a file, so should still be available after the script has ended. That parameter was never mentioned in the Nextcloud documentation though and by default it is not active.
One would have to run some perf tests to see if that would really help with speeding up the `occ` command.
…--
regards Helmut K. C. Tessarek
(sent from a mobile device)
|
Sounds promising, although one has to be aware that this means doubled RAM usage (if cache is created in tmpfs) and most likely doubled initial cache creation effort, since both, SHM and file cache needs to be created. It probably makes more sense when used with |
What about this warning? It's still in the official manual (https://github.com/nextcloud/documentation/blob/dcd10b19cc705c6343e25b96d1adbbc49ac46a33/admin_manual/configuration_server/caching_configuration.rst#memory-caching) |
To evaluate this it would be important to know how APCu cache is actually used in Nextcloud. Some background jobs and CLI commands are quite time consuming compared to the cache init and destruction that happens in a fraction of a second, like all those file scanning, preview generation, database scan/migration tasks. If there is any repeatedly (during same job execution) used data written to this cache, which would otherwise be written and read from disk, then APCu would be useful, otherwise not. So far I see apps |
Thank you @michaelng , so I better leave this option off. It would be nice if documentation would be more precise in that point. But I understand that it is difficult to keep everything up to date... |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Sorry to jump in here, but it's an interesting discussion 🤓 @tessus Can you shed some light on why an admin would choose |
@te-online This all depends on the app, how often the same file is accessed and often changes happen to PHP source file. Using a value of 60s is for production and not for a development system. When you develop an application you either
There is also the option of manually invlidating a cached script. During revalidation the following happens: A checksum is created for the file that is accessed. Then this checksum is compared to the checksum in the cache. If the checksums match, the cache is used, otherwise the cache if invalidated and the source file is compiled and put in the cache. So, if you don't change the files every few seconds, this overhead can become noticeable. I say "can", because it also depends on the load of your system and your HW specs. e.g. is your system CPU bound... For prod systems a value 60 should be fine. If that's not the case, there are still the options of not caching certain files or invalidating them manually. |
@tessus Thank you so much for your detailed explanation. It makes more sense to me now. I think that maybe something is missing from Nextcloud's invalidation, because technically it should be possible to flag the stale files after app updates, right? But that's a different issue, I guess... 😅 |
@te-online You are welcome.
Right, but in such a case waiting 60 seconds is also not really a problem. How often does that happen anyway? Or you could just restart the fpm process. That's what I do, if there are many changes at once. I've setup a separate php-fpm master process for Nextcloud. |
Upstream no longer recommends enabling the opcache cli. See the following: - nextcloud/documentation#1439 - nextcloud/server#15468
Upstream no longer recommends enabling the opcache cli. See the following: - nextcloud/documentation#1439 - nextcloud/server#15468 (cherry picked from commit 9353fb2)
I've been meaning to open an issue for this for a while now, but never got around to it.
The recommendation to set
opcache.enable_cli=1
is actually bad for performance. I am not sure who came up with this, but I reckon that whoever it was did not understand what it meant.Enabling OPcache for CLI has the following effect: it will optimize the CLI script (which takes of course more time the first time to do). However, in the case of a CLI script, it is always the first time for every single invocation of the script. The cache only lives until the process terminates, so as soon as the script ends the optimizations are gone.
The only effect it had was that the script took longer to run, because optimization were done during runtime.
You do not have to take my word for it. You can read up on this topic in several articles or contact the PHP developers.
(Full disclosure: There are certain exceptions where perf can be improved for CLI scripts, but please note that those do not come into play for
occ
or any CLI script that is run by nextcloud.)Not only the documentation is wrong here, also the check in
settings -> admin -> overview
. It is rather annoying to get a warning every time, even though the settings are actually better for performance.But I guess that's a separate ticket, which I will happily open as soon as we have established that my concerns are well-founded.
The text was updated successfully, but these errors were encountered: