-
Notifications
You must be signed in to change notification settings - Fork 7.9k
implement r/w locks to improve performance #16565
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
base: master
Are you sure you want to change the base?
Conversation
Thank you! That looks like a good idea, but I wonder why we would export |
Related regular locks are exported as well, and used outside TSRM (such as the curl extension), so this allows other things to benefit from rwlocks.
I'm not aware of anything similar in Pthreads (I'll have to check), but doing an |
@arnaud-lb or @nielsdos might be best equipped to review this. |
I think that php-src shouldn't access/modify
One case where it might be useful/necessary to update |
@arnaud-lb There are some annoying edge cases whereby the libraries imported by php extensions have configurations which are read from environ. E.g. |
@bwoebi this falls in my second bullet point. This is unsafe in ZTS, as GD will access |
But even if there was synchronization, separate requests could influence each other, couldn't they? Wrt to |
@arnaud-lb I largely agree with you, but php is used by more than just requests (cli tools, job workers, etc). The goal here is to prevent an exclusive lock when simply reading the environment, whether that is a sapi, extension, or user code. |
While investigating some performance issues with FrankenPHP, @AlliBalliBaba discovered that environment access takes an exclusive lock before accessing the environment. This PR makes a small ABI break to
tsrm_env_unlock
andtsrm_env_lock
to indicate whether the environment will be modified. This will take a shared lock for reading (so that multiple threads can read at once) and an exclusive lock on writing.This change should increase performance for ZTS builds (especially those using modern frameworks that make heavy use of environment variables): dunglas/frankenphp#1080 (comment) increasing performance by ~2x under load for the litespeed SAPI.