move clientCron onto a separate timer #1387
Open
+64
−85
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.
The
serverCron()
function contains a variety of maintenance functions and is set up as a timer job, configured to run at a certain rate (hz). The default rate is 10hz (every 100ms).One of the things that
serverCron()
does is to perform maintenance functions on connected clients. Since the number of clients is variable, and can be very large, this could cause latency spikes when the 100msserverCron()
task gets invoked. To combat those latency spikes, a feature called "dynamic-hz" was introduced. This feature will runserverCron()
more often, if there are more clients. The clients get processed up to 200 at a time. The delay forserverCron()
is shortened with the goal of processing all of the clients every second.The result of this is that some of the other (non-client) maintenance functions also get (unnecessarily) run more often. Like
cronUpdateMemoryStats()
anddatabasesCron()
. Logically, it doesn't make sense to run these functions more often, just because we happen to have more clients attached.This PR separates client activities onto a separate, variable, timer. The "dynamic-hz" feature is eliminated. Now,
serverCron
will run at a standard configured rate. The separate clients cron will automatically adjust based on the number of clients. This has the added benefit that often, the 2 crons will fire during separate event loop invocations and will usually avoid the combined latency impact of doing both maintenance activities together.The new timer follows the same rules which were established with the dynamic HZ feature.
MAX_CLIENTS_PER_CLOCK_TICK
)CLIENTS_CRON_MIN_ITERATIONS
)The delay (ms) for the new timer is also more precise, computing the number of milliseconds needed to achieve the goal of reaching all of the clients every second. The old dynamic-hz feature just performs a doubling of the HZ until the clients processing rate is achieved (i.e. delays of 100ms, 50ms, 25ms, 12ms...)