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

Function serverCron

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

Source from the content-addressed store, hash-verified

2044 */
2045
2046int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
2047 int j;
2048 UNUSED(eventLoop);
2049 UNUSED(id);
2050 UNUSED(clientData);
2051
2052 /* Software watchdog: deliver the SIGALRM that will reach the signal
2053 * handler if we don't return here fast enough. */
2054 if (server.watchdog_period) watchdogScheduleSignal(server.watchdog_period);
2055
2056 /* Update the time cache. */
2057 updateCachedTime(1);
2058
2059 server.hz = server.config_hz;
2060 /* Adapt the server.hz value to the number of configured clients. If we have
2061 * many clients, we want to call serverCron() with an higher frequency. */
2062 if (server.dynamic_hz) {
2063 while (listLength(server.clients) / server.hz >
2064 MAX_CLIENTS_PER_CLOCK_TICK)
2065 {
2066 server.hz *= 2;
2067 if (server.hz > CONFIG_MAX_HZ) {
2068 server.hz = CONFIG_MAX_HZ;
2069 break;
2070 }
2071 }
2072 }
2073
2074 run_with_period(100) {
2075 long long stat_net_input_bytes, stat_net_output_bytes;
2076 atomicGet(server.stat_net_input_bytes, stat_net_input_bytes);
2077 atomicGet(server.stat_net_output_bytes, stat_net_output_bytes);
2078
2079 trackInstantaneousMetric(STATS_METRIC_COMMAND,server.stat_numcommands);
2080 trackInstantaneousMetric(STATS_METRIC_NET_INPUT,
2081 stat_net_input_bytes);
2082 trackInstantaneousMetric(STATS_METRIC_NET_OUTPUT,
2083 stat_net_output_bytes);
2084 }
2085
2086 /* We have just LRU_BITS bits per object for LRU information.
2087 * So we use an (eventually wrapping) LRU clock.
2088 *
2089 * Note that even if the counter wraps it's not a big problem,
2090 * everything will still work but some object will appear younger
2091 * to Redis. However for this to happen a given object should never be
2092 * touched for all the time needed to the counter to wrap, which is
2093 * not likely.
2094 *
2095 * Note that you can change the resolution altering the
2096 * LRU_CLOCK_RESOLUTION define. */
2097 unsigned int lruclock = getLRUClock();
2098 atomicSet(server.lruclock,lruclock);
2099
2100 cronUpdateMemoryStats();
2101
2102 /* We received a SIGTERM, shutting down here in a safe way, as it is
2103 * not ok doing so inside the signal handler. */

Callers

nothing calls this directly

Calls 15

watchdogScheduleSignalFunction · 0.85
updateCachedTimeFunction · 0.85
trackInstantaneousMetricFunction · 0.85
getLRUClockFunction · 0.85
cronUpdateMemoryStatsFunction · 0.85
prepareForShutdownFunction · 0.85
zmalloc_used_memoryFunction · 0.85
clientsCronFunction · 0.85
databasesCronFunction · 0.85
hasActiveChildProcessFunction · 0.85
ldbPendingChildrenFunction · 0.85

Tested by

no test coverage detected