Repository navigation
mod_proxy: make proxy_mutex a thread mutex local to each child - #1103
Merged
Merged
Conversation
proxy_mutex serializes the definition, initialization and sync of the run-time workers. Those are per-process data, allocated from per-process pools, so a cross-process lock is not needed. Create it as a thread mutex in pconf at post_config, for each child to inherit unlocked, and no longer init it in child_init. The "proxy" Mutex type stays registered so that existing Mutex directives naming it are still accepted; they have no effect. * modules/proxy/mod_proxy.c (proxy_mutex): Move to proxy_util.c. (proxy_post_config): Create it with proxy_util_post_config(). (child_init): Drop apr_global_mutex_child_init(). (proxy_pre_config): Say why the "proxy" type is still registered. * modules/proxy/proxy_util.c (proxy_mutex): A static thread mutex, with APR_HAS_THREADS only. (proxy_util_post_config): New, creates it. (proxy_mutex_lock, proxy_mutex_unlock): New helpers, no-ops without APR_HAS_THREADS. (ap_proxy_define_worker_ex, ap_proxy_initialize_worker, ap_proxy_sync_balancer): Use them. * modules/proxy/proxy_util.h (proxy_util_post_config): New internal declaration. * docs/manual/mod/core.xml (Mutex): List the "proxy" mutex, without effect. * changes-entries/proxy-mutex-thread.txt: New entry.
Without APR_HAS_THREADS, PROXY_THREAD_LOCK/UNLOCK() (and so PROXY_WORKERS_LOCK/UNLOCK()) expanded to a constant, which used as a statement is a "statement with no effect", and some status variables were undeclared or unused. * modules/proxy/mod_proxy.h (PROXY_THREAD_LOCK, PROXY_THREAD_UNLOCK): Call the internal inline ap_proxy__nolock() returning APR_SUCCESS without threads. * modules/proxy/proxy_util.h (PROXY_WORKERS_LOCK, PROXY_WORKERS_UNLOCK): Same as PROXY_THREAD_LOCK/UNLOCK() without threads. * modules/proxy/proxy_util.c (ap_proxy_initialize_balancer): Declare rv with or without threads. * modules/proxy/mod_proxy_balancer.c (find_best_worker, proxy_balancer_pre_request, proxy_balancer_post_request): Declare rv with threads only.
* docs/manual/mod/core.xml (Mutex): Add the proxy-balancer-shm mutex of mod_proxy_balancer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
proxy_mutex serializes the definition, initialization and sync of the
run-time workers (balancer-manager additions and, since #1084, every
run-time worker definition). What it protects is per-process data, each
child's own balancers and workers and the pools they are allocated from,
so a cross-process lock only costs system calls and a system resource
(a lock file, semaphore or shared memory, depending on the mechanism).
Changes:
pconf at post_config so that each child inherits it unlocked; no child
init anymore. Without APR_HAS_THREADS it's a no-op.
Mutex ... proxydirectives are still accepted; they have no effect anymore.
undeclared
rvsince 2019, and "statement with no effect" errors fromPROXY_THREAD_LOCK/UNLOCK() used as statements).
proxy_mutex.
anymore) and mod_proxy_balancer's proxy-balancer-shm mutex, which was
missing (it serializes run-time worker additions in shared memory).
This is meant as a small, backportable step (no API change). A further
trunk change could remove proxy_mutex entirely: give each balancer its
own pool (shared by its vhost copies) for its run-time workers, allocated
under the balancer's thread lock that the callers already hold, so that
no run-time allocation happens from a pool shared by all balancers
anymore. That would make the locking rule structural rather than
implicit, and allow removing workers at run time later (with per-worker
pools); it wouldn't change performance though, proxy_mutex being taken
only around run-time additions and first initializations.