Added a check to see if the sending rate is within 1% of the limit rather than
[distributedratelimiting.git] / drl / estimate.c
index e55639b..17a0fd8 100644 (file)
@@ -18,9 +18,8 @@
 #include "ratetypes.h" /* needs util and pthread.h */
 #include "logging.h"
 
 #include "ratetypes.h" /* needs util and pthread.h */
 #include "logging.h"
 
-static int underlimit_flowcount_count = 0;
-static int underlimit_normal_count = 0;
 extern uint8_t system_loglevel;
 extern uint8_t system_loglevel;
+static int printcounter = 8;
 
 /**
  * Called for each identity each estimate interval.  Uses flow table information
 
 /**
  * Called for each identity each estimate interval.  Uses flow table information
@@ -156,7 +155,8 @@ static uint32_t allocate_fps(identity_t *ident, double total_weight) {
 
     if (local_rate <= 0) {
         idealweight = 0;
 
     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);
         /* 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);
@@ -166,11 +166,9 @@ static uint32_t allocate_fps(identity_t *ident, double total_weight) {
             idealweight = ideal_over;
             regime = 3;
             dampen = 2;
             idealweight = ideal_over;
             regime = 3;
             dampen = 2;
-            underlimit_flowcount_count += 1;
         } else {
             regime = 1;
             dampen = 0;
         } else {
             regime = 1;
             dampen = 0;
-            underlimit_normal_count += 1;
         }
 
         /* Apply EWMA */
         }
 
         /* Apply EWMA */
@@ -234,11 +232,16 @@ static uint32_t allocate_fps(identity_t *ident, double total_weight) {
             local_rate, idealweight, ident->localweight, total_weight);
     }
 
             local_rate, idealweight, ident->localweight, total_weight);
     }
 
+    if (printcounter <= 0) {
+        printlog(LOG_WARN, "%d %.1f %.1f %.1f\n", local_rate, idealweight, ident->localweight, total_weight);
+        printcounter = 8;
+    } else {
+        printcounter -= 1;
+    }
+
     //printf("Dampen: %d, dampen_increase: %d, peer_weights: %.3f, regime: %d\n",
     //       dampen, dampen_increase, peer_weights, regime);
 
     //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);
     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);
@@ -354,7 +357,7 @@ static void enforce(limiter_t *limiter, identity_t *ident) {
              * FLOW_START_THRESHOLD. */
 
             if (ident->locallimit < FLOW_START_THRESHOLD) {
              * 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
             }
 
             /* Do not allow the node to set a limit higher than its
@@ -367,6 +370,7 @@ static void enforce(limiter_t *limiter, identity_t *ident) {
                 printf("FPS: Setting local limit to %d\n", ident->locallimit);
             }
             printlog(LOG_DEBUG, "%d Limit ID:%d\n", ident->locallimit, ident->id);
                 printf("FPS: Setting local limit to %d\n", ident->locallimit);
             }
             printlog(LOG_DEBUG, "%d Limit ID:%d\n", ident->locallimit, ident->id);
+            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",
 
             snprintf(cmd, CMD_BUFFER_SIZE,
                      "/sbin/tc class change dev eth0 parent 1:%x classid 1:%x htb rate 8bit ceil %dbps quantum 1600",