X-Git-Url: http://git.onelab.eu/?p=distributedratelimiting.git;a=blobdiff_plain;f=drl%2Festimate.c;h=bfe22c5cbb6477a0999d3ffb150f8712713266b4;hp=ed08447b1b378413532acc2b5bf1427ae8f213d0;hb=9891ed21bcd3ff9f72a92e867ac7e8e0b9abb533;hpb=19bf89f36a91be2fdd4a0b6c7099f7515507e1e1 diff --git a/drl/estimate.c b/drl/estimate.c index ed08447..bfe22c5 100644 --- a/drl/estimate.c +++ b/drl/estimate.c @@ -18,8 +18,12 @@ #include "ratetypes.h" /* needs util and pthread.h */ #include "logging.h" -static int underlimit_flowcount_count = 0; -static int underlimit_normal_count = 0; +#define PRINT_COUNTER_RESET (0) + +extern uint8_t system_loglevel; +static int printcounter = PRINT_COUNTER_RESET - 1; + +uint8_t do_enforcement = 0; /** * Called for each identity each estimate interval. Uses flow table information @@ -101,8 +105,8 @@ static double allocate_fps_over_limit(identity_t *ident) { if (ident->common.max_flow_rate > 0) { ideal_weight = (double) ident->locallimit / (double) ident->common.max_flow_rate; - printlog(LOG_DEBUG, "%.3f %d %d FlowCount, TotalRate, MaxRate\n", - ideal_weight, ident->common.rate, ident->common.max_flow_rate); + printlog(LOG_DEBUG, "%.3f %d %d %d FlowCount, Limit, MaxRate, TotalRate\n", + ideal_weight, ident->locallimit, ident->common.max_flow_rate, ident->common.rate); } else { ideal_weight = 1; } @@ -118,7 +122,7 @@ static uint32_t allocate_fps(identity_t *ident, double total_weight) { common_accounting_t *ftable = &ident->common; /* Common flow table info */ uint32_t local_rate = ftable->rate; uint32_t ideallocal = 0; - double peer_weights; /* sum of weights of all other limiters */ + double peer_weights; /* sum of weights of all other limiters */ double idealweight = 0; double last_portion = 0; double this_portion = 0; @@ -155,7 +159,8 @@ static uint32_t allocate_fps(identity_t *ident, double total_weight) { if (local_rate <= 0) { idealweight = 0; - } else if (dampen_increase == 0 && (ident->locallimit <= 0 || local_rate < ident->locallimit || ident->flowstart)) { + } else if (dampen_increase == 0 && + (ident->locallimit <= 0 || local_rate < (ident->locallimit * CLOSE_ENOUGH) || ident->flowstart)) { /* We're under the limit - all flows are bottlenecked. */ idealweight = allocate_fps_under_limit(ident, local_rate, peer_weights); ideal_over = allocate_fps_over_limit(ident); @@ -165,11 +170,9 @@ static uint32_t allocate_fps(identity_t *ident, double total_weight) { idealweight = ideal_over; regime = 3; dampen = 2; - underlimit_flowcount_count += 1; } else { regime = 1; dampen = 0; - underlimit_normal_count += 1; } /* Apply EWMA */ @@ -228,14 +231,31 @@ static uint32_t allocate_fps(identity_t *ident, double total_weight) { printlog(LOG_DEBUG, "%.3f %.3f IdealUnd IdealOve\n",ideal_under,ideal_over); - printf("local_rate: %d, idealweight: %.3f, localweight: %.3f, total_weight: %.3f\n", + if (system_loglevel == LOG_DEBUG) { + printf("local_rate: %d, idealweight: %.3f, localweight: %.3f, total_weight: %.3f\n", local_rate, idealweight, ident->localweight, total_weight); + } + + if (printcounter <= 0) { + struct timeval tv; + double time_now; + + gettimeofday(&tv, NULL); + time_now = (double) tv.tv_sec + (double) ((double) tv.tv_usec / (double) 1000000); + + printlog(LOG_WARN, "%.2f %d %.2f %.2f %.2f %d %d %d %d %d %d %d %d", time_now, ftable->inst_rate, + idealweight, ident->localweight, total_weight, ftable->num_flows, ftable->num_flows_5k, + ftable->num_flows_10k, ftable->num_flows_20k, ftable->num_flows_50k, ftable->avg_rate, + ftable->max_flow_rate, ftable->max_flow_rate_flow_hash); + + printcounter = PRINT_COUNTER_RESET; + } else { + printcounter -= 1; + } //printf("Dampen: %d, dampen_increase: %d, peer_weights: %.3f, regime: %d\n", // dampen, dampen_increase, peer_weights, regime); - //printf("normal_count: %d, flowcount_count: %d\n", underlimit_normal_count, underlimit_flowcount_count); - if (regime == 3) { printlog(LOG_DEBUG, "MIN: min said to use flow counting, which was %.3f when other method said %.3f.\n", ideal_over, ideal_under); @@ -260,8 +280,10 @@ static double allocate_grd(identity_t *ident, double aggdemand) { dropprob = 0.0; } - printf("local rate: %d, aggregate demand: %.3f, drop prob: %.3f\n", + if (system_loglevel == LOG_DEBUG) { + printf("local rate: %d, aggregate demand: %.3f, drop prob: %.3f\n", ident->common.rate, aggdemand, dropprob); + } return dropprob; } @@ -349,7 +371,7 @@ static void enforce(limiter_t *limiter, identity_t *ident) { * FLOW_START_THRESHOLD. */ if (ident->locallimit < FLOW_START_THRESHOLD) { - ident->locallimit = FLOW_START_THRESHOLD * 2; + ident->locallimit = FLOW_START_THRESHOLD; } /* Do not allow the node to set a limit higher than its @@ -358,17 +380,26 @@ static void enforce(limiter_t *limiter, identity_t *ident) { ident->locallimit = limiter->nodelimit; } - printf("FPS: Setting local limit to %d\n", ident->locallimit); + if (system_loglevel == LOG_DEBUG) { + printf("FPS: Setting local limit to %d\n", ident->locallimit); + } printlog(LOG_DEBUG, "%d Limit ID:%d\n", ident->locallimit, ident->id); + if (printcounter == PRINT_COUNTER_RESET) { + printlog(LOG_WARN, "%d\n", ident->locallimit); + } + snprintf(cmd, CMD_BUFFER_SIZE, "/sbin/tc class change dev eth0 parent 1:%x classid 1:%x htb rate 8bit ceil %dbps quantum 1600", ident->htb_parent, ident->htb_node, ident->locallimit); - ret = system(cmd); + if (do_enforcement) { + ret = system(cmd); - if (ret) { - /* FIXME: call failed. What to do? */ + if (ret) { + /* FIXME: call failed. What to do? */ + printlog(LOG_CRITICAL, "***TC call failed?***\n"); + } } break; @@ -412,10 +443,13 @@ static void enforce(limiter_t *limiter, identity_t *ident) { ident->leaves[i]->xid, ident->leaves[i]->xid, (100 * ident->leaves[i]->drop_prob)); #endif - ret = system(cmd); + if (do_enforcement) { + ret = system(cmd); - if (ret) { - /* FIXME: call failed. What to do? */ + if (ret) { + /* FIXME: call failed. What to do? */ + printlog(LOG_CRITICAL, "***TC call failed?***\n"); + } } } @@ -485,6 +519,7 @@ void handle_estimation(void *arg) { sigemptyset(&signal_mask); sigaddset(&signal_mask, SIGHUP); + sigaddset(&signal_mask, SIGUSR1); pthread_sigmask(SIG_BLOCK, &signal_mask, NULL); /* Determine the number of intervals we should wait before hitting the