Long-outstanding commit. (Hopefully) Final version before running experiments for...
[distributedratelimiting.git] / drl / estimate.c
index 21edcbf..3cbf95a 100644 (file)
@@ -38,7 +38,7 @@ static void estimate(identity_t *ident, const double estintms) {
 
     time_difference = timeval_subtract(now, ident->common.last_update);
 
-    if (time_difference > 1.05 * (estintms / 1000 * ident->mainloop_intervals)) {
+    if (time_difference > .01 + (estintms / 1000 * ident->mainloop_intervals)) {
         printlog(LOG_WARN, "Missed interval: Scheduled for %.2f ms, actual %.2fms\n",
                  estintms * ident->mainloop_intervals, time_difference * 1000);
     }
@@ -125,8 +125,8 @@ static double allocate_fps_over_limit(identity_t *ident) {
 static inline uint32_t close_enough(uint32_t limit) {
     uint32_t difference = limit - (limit * CLOSE_ENOUGH);
 
-    if (difference < 2500) {
-        return (limit - 2500);
+    if (difference < 10240) {
+        return (limit - 10240);
     } else {
         return (limit * CLOSE_ENOUGH);
     }
@@ -219,6 +219,7 @@ static uint32_t allocate_fps(identity_t *ident, double total_weight,
         }
         Old flowstart code.
 #endif
+        //printf("rate is %d, close enough is %d, difference is %d\n", table->rate, close_enough(ident->locallimit), close_enough(ident->locallimit) - table->rate);
 
         /* Boost low-limits so that they have room to grow. */
         if (table->rate < FLOW_START_THRESHOLD) {
@@ -564,19 +565,47 @@ static uint32_t allocate_fps_old(identity_t *ident, double total_weight) {
  */
 static double allocate_grd(identity_t *ident, double aggdemand) {
     double dropprob;
-    double global_limit = (double) (ident->limit);
+    double global_limit = ident->limit;
+    double min_dropprob = ident->drop_prob * GRD_BIG_DROP;
+
+    struct timeval tv;
+    double time_now;
+    common_accounting_t *table = &ident->common;
+
+    gettimeofday(&tv, NULL);
+    time_now = (double) tv.tv_sec + (double) ((double) tv.tv_usec / (double) 1000000);
 
     if (aggdemand > global_limit) {
         dropprob = (aggdemand-global_limit)/aggdemand;
     } else {
         dropprob = 0.0;
     }
-    
+
+    if (dropprob > 0.01 && dropprob < min_dropprob) {
+        dropprob = min_dropprob;
+    }
+
     if (system_loglevel == LOG_DEBUG) {
         printf("local rate: %d, aggregate demand: %.3f, drop prob: %.3f\n",
            ident->common.rate, aggdemand, dropprob);
     }
 
+    if (table->max_flow_rate > 0) {
+        printlog(LOG_WARN, "%.2f %d 0 0 %.2f %d %d %d %d %d %d %d %d %.2f ID:%d %.3f\n",
+             time_now, table->inst_rate, aggdemand,
+             table->num_flows, table->num_flows_5k, table->num_flows_10k,
+             table->num_flows_20k, table->num_flows_50k, table->avg_rate,
+             table->max_flow_rate, table->max_flow_rate_flow_hash, dropprob,
+             ident->id, (double) table->rate / (double) table->max_flow_rate);
+    } else {
+        printlog(LOG_WARN, "%.2f %d 0 0 %.2f %d %d %d %d %d %d %d %d %.2f ID:%d 0\n",
+             time_now, table->inst_rate, aggdemand,
+             table->num_flows, table->num_flows_5k, table->num_flows_10k,
+             table->num_flows_20k, table->num_flows_50k, table->avg_rate,
+             table->max_flow_rate, table->max_flow_rate_flow_hash, dropprob,
+             ident->id);
+    }
+
     return dropprob;
 }
 
@@ -617,7 +646,6 @@ static void allocate(limiter_t *limiter, identity_t *ident) {
         /* Update other limiters with our weight by writing to comm layer. */
         write_local_value(&ident->comm, ident->localweight);
     } else {
-        ident->locallimit = 0; /* Unused with GRD. */
         ident->last_drop_prob = ident->drop_prob;
         ident->drop_prob = allocate_grd(ident, comm_val);
         
@@ -739,17 +767,11 @@ static void enforce(limiter_t *limiter, identity_t *ident) {
                 }
 
                 /* Make the call to tc. */
-#ifdef DELAY40MS
                 snprintf(cmd, CMD_BUFFER_SIZE,
-                         "/sbin/tc qdisc change dev eth0 parent 1:1%x handle 1%x netem loss %.4f delay 40ms",
+                         "/sbin/tc qdisc change dev eth0 parent 1:1%x handle 1%x netem loss %.4f delay %dms",
                          ident->leaves[i]->xid, ident->leaves[i]->xid,
-                         (100 * ident->leaves[i]->drop_prob));
-#else
-                snprintf(cmd, CMD_BUFFER_SIZE,
-                         "/sbin/tc qdisc change dev eth0 parent 1:1%x handle 1%x netem loss %.4f delay 0ms",
-                         ident->leaves[i]->xid, ident->leaves[i]->xid,
-                         (100 * ident->leaves[i]->drop_prob));
-#endif
+                         (100 * ident->leaves[i]->drop_prob), ident->leaves[i]->delay);
+
                 if (do_enforcement) {
                     ret = system(cmd);