Repository navigation
Add OPcache restart hook, fired when a restart is carried out - #23828
Conversation
0d0f55a to
66964a1
Compare
66964a1 to
6f9dc98
Compare
|
Rebased. The hook is now called after the SHM lock is released, which is what dstogov asked for the first hook in #15590. @arnaud-lb could you have a look? php/frankenphp#2634 is merged and reports scheduled restarts with the existing hook. This new hook is what's missing to report that the restart really happened. |
zend_accel_schedule_restart_hook tells an observer that a restart of OPcache's shared memory is coming, but not whether or when it happens: the restart runs later, at request startup, on whichever thread or process first finds the cache unused, and it can stay pending for a long time. This adds zend_accel_restart_hook, called on that thread once per restart, right after the restart completed, with the same reason. A threaded SAPI needs it for its logs and metrics, since the restart rewinds shared memory that other threads may still reference.
6f9dc98 to
1fa25ab
Compare
arnaud-lb
left a comment
There was a problem hiding this comment.
under ZTS the restart rewinds shared memory that other threads may still reference
I'm assuming this is related to #24276? I want to get this other PR merged as well.
php/frankenphp#2634 mentions that the metric will be removed once opcache handles restarts safely under ZTS. Should I still merge this PR or do you want to wait and see if #24276 fixes the issue?
|
I think adding this hook would still be nice, it's small enough. |
|
Please merge it, #24276 makes this hook more useful, not less. With #24276, a restart waits until no thread uses SHM. A FrankenPHP worker uses SHM for its whole life. So the restart waits until all workers are restarted, and regular requests run uncached meanwhile. A worker that boots before the restart happened also stays uncached until its next restart. FrankenPHP will have to restart its workers when a restart is scheduled. This hook is how it knows that the restart really happened, so that it can restart the workers that booted too early. The note in our docs was written before #24276, we'll update it. |
|
Thank you! |
After #15590, which added
zend_accel_schedule_restart_hook.That hook says a restart of OPcache's shared memory is coming, not that it happened: the restart runs later, at request startup, on whichever thread or process first finds the cache unused, and it can stay pending for a long time. This adds
zend_accel_restart_hook, called on that thread once per restart, right after it completed and the SHM lock is released, with the same reason.FrankenPHP needs it for its logs and metrics: under ZTS the restart rewinds shared memory that other threads may still reference, so the exact moment matters for post-mortems, and the scheduling event alone doesn't tell an operator whether the restart ran at all.