Browse Source

TT#36180 scale timer interval according to runtimes

Change-Id: Ie318997bacfacc6d9806d72ff42310cfd19f49b2
changes/54/21154/1
Richard Fuchs 8 years ago
parent
commit
808dd49ffb
1 changed files with 29 additions and 0 deletions
  1. +29
    -0
      daemon/call.c

+ 29
- 0
daemon/call.c View File

@ -497,6 +497,19 @@ static void call_timer(void *ptr) {
unsigned int pt; unsigned int pt;
endpoint_t ep; endpoint_t ep;
u_int64_t offers, answers, deletes; 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); ZERO(hlp);
hlp.addr_sfd = g_hash_table_new(g_endpoint_hash, g_endpoint_eq); hlp.addr_sfd = g_hash_table_new(g_endpoint_hash, g_endpoint_eq);
@ -635,6 +648,22 @@ next:
kill_calls_timer(hlp.del_scheduled, NULL); kill_calls_timer(hlp.del_scheduled, NULL);
kill_calls_timer(hlp.del_timeout, rtpe_config.b2b_url); 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_INFO, "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 #undef DS


Loading…
Cancel
Save