Repository navigation
Conversation
remember it once for all threads, so a host signal still reaches its handler if it lands on a different PHP thread
|
4 core workload:
Benchmarked and table generated by gpt, but I got very similar numbers in manual wrk runs, so I think it's more or less correct in the realm of local hardware not being the most stable.
cc @Girgias |
iliaal
left a comment
There was a problem hiding this comment.
Please fix the NTS timeout regression before merging. I’d also like deployments with a tight pending-signal limit to be able to keep execution timers enabled without retaining them between requests.
| static const struct itimerspec disarmed = {0}; | ||
| zend_cached_timer *cache = TIMER_CACHE; | ||
| if (cache && cache->pid == EG(pid) && CAN_CACHE_TIMER() | ||
| && timer_settime(EG(max_execution_timer_timer), 0, &disarmed, NULL) == 0) { |
There was a problem hiding this comment.
A disarmed timer still consumes one RLIMIT_SIGPENDING slot for the real UID. With the limit set to 1, two php -S processes under the same UID can serve one request each, sequentially, on master. Here the first server keeps the slot while idle, and the second fails at request startup with EAGAIN.
Isn't the limit ridiculously high on Linux? That's the reason it's only enabled there. I could check limits on init once before but what's really a sane number where we say reuse is ok? If we check it per request against the currently active number of threads, I would imagine it's going to eat the savings of reusing them. |
|
The limit is high here too, and other processes under the same real UID share it. I’d keep reuse on by default and let admins disable just reuse at startup. That avoids both a threshold and a per-request check. |
|
So I figured out why it's so high on linux and it's because it uses RLIMIT_NPROC, i.e. how many processes can exist at a time. Since fpm doesn't check the rlimit for whether it can fork X children, I don't think it's worth an extra setting here either. What I still want to do here though is maybe not disarm and already disarmed timer. The other two comments look sensible and I'll change it. |
|
@dunglas is there a reason the execution timer is directly exposed to extensions? If we made it private we could track the current timer state in a single variable and conditionally skip pid checks or timer disarms when we know we don't need to do anything to the timer. |
After looking at this for a bit, I don't think this is worth addressing either. I wanted to do a startup check to support FreeBSD, but it seems to have a hard limit of 32 per process and we don't have a max-threads setting in php. If anything, we could introduce a setting to it at runtime, but the performance benefit isn't large enough to warrant that for a niche OS that's already missing out on many optimisations anyhow. In Linux the startup check isn't very useful, because the quote is shared with other processes on the system. And generally so high, it would be asinine of a user to set it low enough to impact php threads/processes without the expectation of breaking their OS. FPM also doesn't check process limit availability before trying to fork, it just handles the failure. |
logic on master: each request creates a timer, sets time limit, deletes the timer
logic here: each thread creates a timer, each request sets time limit, then after the request sets time limit to zero. timer is reused by the next request.
this skips noticeable overhead, especially in threaded scenarios (first measurement in frankenphp ~4% for hello world), but also in NTS (if max execution timers are enabled)
FreeBSD excluded for now because of https://github.com/freebsd/freebsd-src/blob/main/sys/sys/timers.h#L65
closes #12324
cc @dunglas