[3.0.4 Backport] Periodic high response times on REST API due to persistent config polling
Description
Overview
The persistent config code that checks for config updates periodically (every 10 seconds by default) acquires a lock on ServerContext prior to discovering/fetching database configs from buckets, despite not needing the lock until SG is about to apply the configs.
This can cause REST API response times to periodically spike up to a few seconds if the requests align with the ServerContext lock, whilst SG is fetching database configs from each bucket on server.
Example
Proposed fix
Move the lock in fetchAndLoadConfigs down to after we've fetched the configs from the bucket, but before we're about to apply them to the node.
Build sync_gateway-3.0.4-4 contains sync_gateway commit b806361 with commit message: : Backport : Fix periodic high response times on REST API due to persistent config polling (#5672)
Ben Brooks July 15, 2022 at 5:01 PM
Make sure the backport includes the follow up fixes to be made in - see comments.
Fixed
Pinned fields
Click on the next to a field label to start pinning.
Overview
The persistent config code that checks for config updates periodically (every 10 seconds by default) acquires a lock on ServerContext prior to discovering/fetching database configs from buckets, despite not needing the lock until SG is about to apply the configs.
This can cause REST API response times to periodically spike up to a few seconds if the requests align with the ServerContext lock, whilst SG is fetching database configs from each bucket on server.
Example
Proposed fix
Move the lock in
fetchAndLoadConfigs
down to after we've fetched the configs from the bucket, but before we're about to apply them to the node.