| 2380 | |
| 2381 | void unblockChildThreadIfNecessary(); |
| 2382 | int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) { |
| 2383 | int j; |
| 2384 | UNUSED(eventLoop); |
| 2385 | UNUSED(id); |
| 2386 | UNUSED(clientData); |
| 2387 | |
| 2388 | if (g_pserver->maxmemory && g_pserver->m_pstorageFactory) |
| 2389 | performEvictions(false); |
| 2390 | |
| 2391 | /* If another threads unblocked one of our clients, and this thread has been idle |
| 2392 | then beforeSleep won't have a chance to process the unblocking. So we also |
| 2393 | process them here in the cron job to ensure they don't starve. |
| 2394 | */ |
| 2395 | if (listLength(g_pserver->rgthreadvar[IDX_EVENT_LOOP_MAIN].unblocked_clients)) |
| 2396 | { |
| 2397 | processUnblockedClients(IDX_EVENT_LOOP_MAIN); |
| 2398 | } |
| 2399 | |
| 2400 | /* Software watchdog: deliver the SIGALRM that will reach the signal |
| 2401 | * handler if we don't return here fast enough. */ |
| 2402 | if (g_pserver->watchdog_period) watchdogScheduleSignal(g_pserver->watchdog_period); |
| 2403 | |
| 2404 | g_pserver->hz = g_pserver->config_hz; |
| 2405 | /* Adapt the g_pserver->hz value to the number of configured clients. If we have |
| 2406 | * many clients, we want to call serverCron() with an higher frequency. */ |
| 2407 | if (g_pserver->dynamic_hz) { |
| 2408 | while (listLength(g_pserver->clients) / g_pserver->hz > |
| 2409 | MAX_CLIENTS_PER_CLOCK_TICK) |
| 2410 | { |
| 2411 | g_pserver->hz += g_pserver->hz; // *= 2 |
| 2412 | if (g_pserver->hz > CONFIG_MAX_HZ) { |
| 2413 | g_pserver->hz = CONFIG_MAX_HZ; |
| 2414 | break; |
| 2415 | } |
| 2416 | } |
| 2417 | } |
| 2418 | |
| 2419 | /* A cancelled child thread could be hung waiting for us to read from a pipe */ |
| 2420 | unblockChildThreadIfNecessary(); |
| 2421 | |
| 2422 | run_with_period(100) { |
| 2423 | long long stat_net_input_bytes, stat_net_output_bytes; |
| 2424 | stat_net_input_bytes = g_pserver->stat_net_input_bytes.load(std::memory_order_relaxed); |
| 2425 | stat_net_output_bytes = g_pserver->stat_net_output_bytes.load(std::memory_order_relaxed); |
| 2426 | |
| 2427 | long long stat_numcommands; |
| 2428 | __atomic_load(&g_pserver->stat_numcommands, &stat_numcommands, __ATOMIC_RELAXED); |
| 2429 | trackInstantaneousMetric(STATS_METRIC_COMMAND,stat_numcommands); |
| 2430 | trackInstantaneousMetric(STATS_METRIC_NET_INPUT, |
| 2431 | stat_net_input_bytes); |
| 2432 | trackInstantaneousMetric(STATS_METRIC_NET_OUTPUT, |
| 2433 | stat_net_output_bytes); |
| 2434 | } |
| 2435 | |
| 2436 | /* We have just LRU_BITS bits per object for LRU information. |
| 2437 | * So we use an (eventually wrapping) LRU clock. |
| 2438 | * |
| 2439 | * Note that even if the counter wraps it's not a big problem, |
nothing calls this directly
no test coverage detected