From 14583621c352eb11fbd4f398bf6107c744cfc6f8 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 9 Jul 2005 15:23:36 +0000 Subject: optimizations --- src/plugins/stats/functions.c | 99 ++++++++++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 38 deletions(-) diff --git a/src/plugins/stats/functions.c b/src/plugins/stats/functions.c index 1a325082..6e1c84c0 100644 --- a/src/plugins/stats/functions.c +++ b/src/plugins/stats/functions.c @@ -36,6 +36,12 @@ static GNUNET_TCP_SOCKET * sock; static Mutex lock; +static long connectionGoal; + +static long long banddown; + +static long long bandup; + static int getStatValue(long long * value, long long * lvalue, cron_t * dtime, @@ -64,28 +70,53 @@ static int getStatValue(long long * value, return SYSERR; } -static int getConnectedNodesStat(const void * closure, - gfloat ** data) { - long long val; +static void updateConnectionGoal(void * unused) { char * cmh; - long cval; + char * availableDown; + char * availableUp; MUTEX_LOCK(&lock); cmh = getConfigurationOptionValue(sock, "gnunetd", "connection-max-hosts"); + availableDown = getConfigurationOptionValue(sock, + "LOAD", + "MAXNETDOWNBPSTOTAL"); + availableUp = getConfigurationOptionValue(sock, + "LOAD", + "MAXNETUPBPSTOTAL"); MUTEX_UNLOCK(&lock); - if (cmh == NULL) + if (cmh == NULL) + connectionGoal = 0; + else + connectionGoal = atol(cmh); + if (availableDown == NULL) + banddown = 0; + else + banddown = atol(availableDown); + if (availableUp == NULL) + bandup = 0; + else + bandup = atol(availableUp); + + FREENONNULL(cmh); + FREENONNULL(availableDown); + FREENONNULL(availableUp); +} + +static int getConnectedNodesStat(const void * closure, + gfloat ** data) { + long long val; + + if (connectionGoal == 0) return SYSERR; - cval = atol(cmh); - FREE(cmh); if (OK != getStatValue(&val, NULL, NULL, dgettext("GNUnet", "# of connected peers"))) return SYSERR; - data[0][0] = 0.8 * val / cval; + data[0][0] = 0.8 * val / connectionGoal; return OK; } @@ -113,9 +144,7 @@ static int getTrafficRecvStats(const void * closure, long long lnoise; long long lcontent; long long lqueries; - long long band; cron_t dtime; - char * available; char * buffer; int i; @@ -159,30 +188,24 @@ static int getTrafficRecvStats(const void * closure, lqueries = 0; } FREE(buffer); - MUTEX_LOCK(&lock); - available = getConfigurationOptionValue(sock, - "LOAD", - "MAXNETDOWNBPSTOTAL"); - MUTEX_UNLOCK(&lock); - if (available == NULL) + if (banddown == 0) return SYSERR; - band = atol(available) * dtime / cronSECONDS; - FREE(available); + total -= ltotal; noise -= lnoise; queries -= lqueries; content -= lcontent; - if (band <= 0) { + if (banddown < 0) { data[0][0] = 0.0; data[0][1] = 0.0; data[0][2] = 0.0; data[0][3] = 0.0; return OK; } - data[0][0] = 0.8 * noise / band; /* red */ - data[0][1] = 0.8 * (content+noise) / band; /* green */ - data[0][2] = 0.8 * (queries+content+noise) / band; /* yellow */ - data[0][3] = 0.8 * total / band; /* blue */ + data[0][0] = 0.8 * noise / (banddown * dtime / cronSECONDS); /* red */ + data[0][1] = 0.8 * (content+noise) / (banddown * dtime / cronSECONDS); /* green */ + data[0][2] = 0.8 * (queries+content+noise) / (banddown * dtime / cronSECONDS); /* yellow */ + data[0][3] = 0.8 * total / (banddown * dtime / cronSECONDS); /* blue */ /*printf("I: %f %f %f\n", data[0][0], data[0][1], @@ -201,9 +224,7 @@ static int getTrafficSendStats(const void * closure, long long lnoise; long long lcontent; long long lqueries; - long long band; cron_t dtime; - char * available; char * buffer; int i; @@ -247,30 +268,23 @@ static int getTrafficSendStats(const void * closure, lqueries = 0; } FREE(buffer); - MUTEX_LOCK(&lock); - available = getConfigurationOptionValue(sock, - "LOAD", - "MAXNETUPBPSTOTAL"); - MUTEX_UNLOCK(&lock); - if (available == NULL) + if (bandup == 0) return SYSERR; - band = atol(available) * dtime / cronSECONDS; - FREE(available); total -= ltotal; noise -= lnoise; queries -= lqueries; content -= lcontent; - if (band <= 0) { + if (bandup < 0) { data[0][0] = 0.0; data[0][1] = 0.0; data[0][2] = 0.0; data[0][3] = 0.0; return OK; } - data[0][0] = 0.8 * noise / band; /* red */ - data[0][1] = 0.8 * (noise + content) / band; /* green */ - data[0][2] = 0.8 * (noise + content + queries) / band; /* yellow */ - data[0][3] = 0.8 * total / band; /* yellow */ + data[0][0] = 0.8 * noise / (bandup * dtime / cronSECONDS); /* red */ + data[0][1] = 0.8 * (noise + content) / (bandup*dtime / cronSECONDS); /* green */ + data[0][2] = 0.8 * (noise + content + queries) / (bandup*dtime / cronSECONDS); /* yellow */ + data[0][3] = 0.8 * total / (bandup*dtime / cronSECONDS); /* yellow */ /* printf("O: %f %f %f\n", data[0][0], data[0][1], @@ -380,13 +394,22 @@ void init_functions() { UPDATE_INTERVAL = 30 * cronSECONDS; sock = getClientSocket(); MUTEX_CREATE(&lock); + updateStatValues(NULL); + updateConnectionGoal(NULL); addCronJob(&updateStatValues, UPDATE_INTERVAL, UPDATE_INTERVAL, NULL); + addCronJob(&updateConnectionGoal, + 5 * cronMINUTES, + 5 * cronMINUTES, + NULL); } void done_functions() { + delCronJob(&updateConnectionGoal, + 5 * cronMINUTES, + NULL); delCronJob(&updateStatValues, UPDATE_INTERVAL, NULL); -- cgit v1.2.3