MCPcopy Create free account
hub / github.com/F-Stack/f-stack / whileBlockedCron

Function whileBlockedCron

app/redis-6.2.6/src/server.c:2298–2340  ·  view source on GitHub ↗

This function fill in the role of serverCron during RDB or AOF loading, and * also during blocked scripts. * It attempts to do its duties at a similar rate as the configured server.hz, * and updates cronloops variable so that similarly to serverCron, the * run_with_period can be used. */

Source from the content-addressed store, hash-verified

2296 * and updates cronloops variable so that similarly to serverCron, the
2297 * run_with_period can be used. */
2298void whileBlockedCron() {
2299 /* Here we may want to perform some cron jobs (normally done server.hz times
2300 * per second). */
2301
2302 /* Since this function depends on a call to blockingOperationStarts, let's
2303 * make sure it was done. */
2304 serverAssert(server.blocked_last_cron);
2305
2306 /* In case we where called too soon, leave right away. This way one time
2307 * jobs after the loop below don't need an if. and we don't bother to start
2308 * latency monitor if this function is called too often. */
2309 if (server.blocked_last_cron >= server.mstime)
2310 return;
2311
2312 mstime_t latency;
2313 latencyStartMonitor(latency);
2314
2315 /* In some cases we may be called with big intervals, so we may need to do
2316 * extra work here. This is because some of the functions in serverCron rely
2317 * on the fact that it is performed every 10 ms or so. For instance, if
2318 * activeDefragCycle needs to utilize 25% cpu, it will utilize 2.5ms, so we
2319 * need to call it multiple times. */
2320 long hz_ms = 1000/server.hz;
2321 while (server.blocked_last_cron < server.mstime) {
2322
2323 /* Defrag keys gradually. */
2324 activeDefragCycle();
2325
2326 server.blocked_last_cron += hz_ms;
2327
2328 /* Increment cronloop so that run_with_period works. */
2329 server.cronloops++;
2330 }
2331
2332 /* Other cron jobs do not need to be done in a loop. No need to check
2333 * server.blocked_last_cron since we have an early exit at the top. */
2334
2335 /* Update memory stats during loading (excluding blocked scripts) */
2336 if (server.loading) cronUpdateMemoryStats();
2337
2338 latencyEndMonitor(latency);
2339 latencyAddSampleIfNeeded("while-blocked-cron",latency);
2340}
2341
2342extern int ProcessingEventsWhileBlocked;
2343

Callers 1

Calls 2

activeDefragCycleFunction · 0.85
cronUpdateMemoryStatsFunction · 0.85

Tested by

no test coverage detected