Prevent unnecessarily frequent default expunge operations#588
Prevent unnecessarily frequent default expunge operations#588madmajestro wants to merge 1 commit intokrakjoe:masterfrom
Conversation
|
This is my suggestion for reducing high CPU usage caused by frequently executed default expunge operations. In my tests, this seemed effective. The number of cleanups and defragmentations decreased, while the number of expunges remained constant. |
php_apc.c
Outdated
| STD_PHP_INI_ENTRY("apc.gc_ttl", "3600", PHP_INI_SYSTEM, OnUpdateLong, gc_ttl, zend_apcu_globals, apcu_globals) | ||
| STD_PHP_INI_ENTRY("apc.ttl", "0", PHP_INI_SYSTEM, OnUpdateLong, ttl, zend_apcu_globals, apcu_globals) | ||
| STD_PHP_INI_ENTRY("apc.smart", "0", PHP_INI_SYSTEM, OnUpdateLong, smart, zend_apcu_globals, apcu_globals) | ||
| STD_PHP_INI_ENTRY("apc.smart", "1", PHP_INI_SYSTEM, OnUpdateLong, smart, zend_apcu_globals, apcu_globals) |
There was a problem hiding this comment.
Perhaps it would be better to remove apc.smart and use a different name like apc.expunge_percentage, instead of changing the behavior of apc.smart again. Which do you think is better?
There was a problem hiding this comment.
Probably it's best to not use apc.smart. Nobody really understands what this undocumented option does...
There was a problem hiding this comment.
Yes, I think so too. Do you have any concerns about removing apc.smart completely and replacing it with a setting called apc.expunge_threshold?
There was a problem hiding this comment.
Fixed.
- I decided to use
apc.expunge_thresholdas a new configuration setting and removedapc.smart. apc.expunge_thresholdis specified in thousandths of SHM that must be free.- The default value is 5 (0.5%), as this prevented all worst-case scenarios during my test runs.
|
Even if it works well with 1 %, it would also be reasonable to use thousendth instead of percent. If the general concept is ok, i could do some additional testing + tuning with values lower than 1 %. |
ec5ebc9 to
6dce289
Compare
413d821 to
fc927ca
Compare
nikic
left a comment
There was a problem hiding this comment.
Having the option specify the value in thousands is a bit weird. Might it make more sense to make this a floating point value?
fc927ca to
d9744bd
Compare
|
Fixed. Yes, that's a good idea. It's easier to understand and more flexible. |
php_apc.c
Outdated
| return FAILURE; | ||
| } | ||
|
|
||
| double *p = (double *) ZEND_INI_GET_ADDR(); |
There was a problem hiding this comment.
Why does this use a different approach (ZEND_INI_GET_ADDR instead of using APCG) than the other ini settings?
There was a problem hiding this comment.
Changed.
By using ZEND_INI_GET_ADDR, the OnUpdatePercentage function was also be usable for other INI settings that must be specified as a percentage. However, since there is currently no other INI setting that requires a percentage, I've removed the use of ZEND_INI_GET_ADDR. As soon as there are multiple percentage values, we can consider using ZEND_INI_GET_ADDR again.
e4b458a to
727b662
Compare
A full cache wipe is now performed if too little SHM has been freed by removing expired entries during the default expunge operation. This is intended to prevent unnecessarily frequent calls of the default expunge operation, which should reduce cpu load in some cases. The new configuration setting apc.expunge_threshold defaults to 0.5 (0.5%) and specifies the percentage of SHM that must be available after expired entries have been removed during the default expunge operation. Since apc.expunge_threshold replaces apc.smart, apc.smart has been removed.
727b662 to
84af7d5
Compare
|
I wonder whether it would make sense to create a release from the current master branch before merging this. |
I agree. It probably wouldn't hurt, but this is the safer approach. But please take a look at #606 before creating a release. |
|
@nikic |
Oops, fixed. |
A full cache wipe is now performed if too little SHM has been freed by removing expired entries during the default expunge operation. This is intended to prevent unnecessarily frequent calls of the default expunge operation, which should reduce cpu load in some cases. The new configuration setting apc.expunge_threshold defaults to 5 (0.5%) and specifies the thousandth of SHM that must be available after expired entries have been removed during the default expunge operation. Since apc.expunge_threshold replaces apc.smart, apc.smart has been removed.