From 9943a3d868d1f2ffa098ce0f304566085ad41f48 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 9 May 2018 11:24:33 -0400 Subject: [PATCH] TT#36180 scale timer interval according to runtimes Also slow down XMLRPC callbacks to avoid excessive CPU usage Change-Id: Ie318997bacfacc6d9806d72ff42310cfd19f49b2 --- daemon/call.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/daemon/call.c b/daemon/call.c index cca122c8f..5ec72fa0b 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -306,6 +306,8 @@ void xmlrpc_kill_calls(void *p) { const char *url; while (xh->tags_urls && xh->tags_urls->next) { + usleep(10000); + tag = xh->tags_urls->data; url = xh->tags_urls->next->data; @@ -517,6 +519,19 @@ static void call_timer(void *ptr) { unsigned int pt; endpoint_t ep; u_int64_t offers, answers, deletes; + struct timeval tv_start; + + // timers are run in a single thread, so no locking required here + static struct timeval last_run; + static long long interval = 1000000; // usec + + gettimeofday(&tv_start, NULL); + + // ready to start? + if (timeval_diff(&tv_start, &last_run) < interval) + return; + + last_run = tv_start; ZERO(hlp); hlp.addr_sfd = g_hash_table_new(g_endpoint_hash, g_endpoint_eq); @@ -652,6 +667,22 @@ next: kill_calls_timer(hlp.del_scheduled, NULL); kill_calls_timer(hlp.del_timeout, rtpe_config.b2b_url); + + struct timeval tv_stop; + gettimeofday(&tv_stop, NULL); + long long duration = timeval_diff(&tv_stop, &tv_start); + ilog(LOG_DEBUG, "timer run time = %llu.%06llu sec", duration / 1000000, duration % 1000000); + + // increase timer run duration if runtime was within 10% of the interval + if (duration > interval / 10) { + interval *= 2; + ilog(LOG_INFO, "Increasing timer run interval to %llu seconds", interval / 1000000); + } + // or if the runtime was less than 2% of the interval, decrease the interval + else if (interval > 1000000 && duration < interval / 50) { + interval /= 2; + ilog(LOG_INFO, "Decreasing timer run interval to %llu seconds", interval / 1000000); + } } #undef DS