[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r11456: Track weighted fractional uptime in addition to weighted mtb (in tor/trunk: . doc src/or)



Author: nickm
Date: 2007-09-17 14:27:43 -0400 (Mon, 17 Sep 2007)
New Revision: 11456

Modified:
   tor/trunk/
   tor/trunk/doc/TODO
   tor/trunk/src/or/rephist.c
Log:
 r14447@Kushana:  nickm | 2007-09-17 13:31:50 -0400
 Track weighted fractional uptime in addition to weighted mtbf: we want to use mtbf for stable, but fractional uptime for guard.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r14447] on c95137ef-5f19-0410-b913-86e773d04f59

Modified: tor/trunk/doc/TODO
===================================================================
--- tor/trunk/doc/TODO	2007-09-17 15:07:10 UTC (rev 11455)
+++ tor/trunk/doc/TODO	2007-09-17 18:27:43 UTC (rev 11456)
@@ -165,6 +165,9 @@
        (high expected time to failure) or good guard qualities (high
        fractional uptime).
      - AKA Track uptime as %-of-time-up, as well as time-since-last-down
+       o Implement tracking
+       - Make uptime info persist too.
+       - Base Guard on weighted fractional uptime.
     - Make TrackHostExits expire TrackHostExitsExpire seconds after their
        *last* use, not their *first* use.
     - Limit to 2 dir, 2 OR, N SOCKS connections per IP.

Modified: tor/trunk/src/or/rephist.c
===================================================================
--- tor/trunk/src/or/rephist.c	2007-09-17 15:07:10 UTC (rev 11455)
+++ tor/trunk/src/or/rephist.c	2007-09-17 18:27:43 UTC (rev 11456)
@@ -75,6 +75,10 @@
   time_t start_of_run;
   /** Sum of weights for runs in weighted_run_length. */
   double total_run_weights;
+  /* === For fractional uptime tracking: */
+  time_t start_of_downtime;
+  unsigned long weighted_uptime;
+  unsigned long total_weighted_time;
 
   /** Map from hex OR2 identity digest to a link_history_t for the link
    * from this OR to OR2. */
@@ -287,6 +291,11 @@
   if (hist && !hist->start_of_run) {
     hist->start_of_run = when;
   }
+  if (hist && hist->start_of_downtime) {
+    long down_length = when - hist->start_of_downtime;
+    hist->total_weighted_time += down_length;
+    hist->start_of_downtime = 0;
+  }
 }
 
 /** We have just decided that this router is unreachable, meaning
@@ -303,7 +312,13 @@
     hist->weighted_run_length += run_length;
     hist->total_run_weights += 1.0;
     hist->start_of_run = 0;
+
+    hist->weighted_uptime += run_length;
+    hist->total_weighted_time += run_length;
   }
+  if (hist && !hist->start_of_downtime) {
+    hist->start_of_downtime = when;
+  }
 }
 
 /** Helper: Discount all old MTBF data, if it is time to do so.  Return
@@ -340,6 +355,9 @@
     hist->weighted_run_length =
       (unsigned long)(hist->weighted_run_length * alpha);
     hist->total_run_weights *= alpha;
+
+    hist->weighted_uptime *= alpha;
+    hist->total_weighted_time *= alpha;
   }
 
   return stability_last_downrated + STABILITY_INTERVAL;
@@ -366,6 +384,23 @@
   return total / total_weights;
 }
 
+/** DOCDOC */
+static double
+get_weighted_fractional_uptime(or_history_t *hist, time_t when)
+{
+  unsigned long total = hist->total_weighted_time;
+  unsigned long up = hist->weighted_uptime;
+
+  if (hist->start_of_run) {
+    long run_length = (when - hist->start_of_run);
+    up += run_length;
+    total += run_length;
+  } else if (hist->start_of_downtime) {
+    total += (when - hist->start_of_downtime);
+  }
+  return ((double) up) / total;
+}
+
 /** Return an estimated MTBF for the router whose identity digest is
  * <b>id</b>. Return 0 if the router is unknown. */
 double
@@ -378,6 +413,17 @@
   return get_stability(hist, when);
 }
 
+/** DOCDOC */
+double
+rep_hist_get_weighted_fractional_uptime(const char *id, time_t when)
+{
+  or_history_t *hist = get_or_history(id);
+  if (!hist)
+    return 0.0;
+
+  return get_weighted_fractional_uptime(hist, when);
+}
+
 /** Return true if we've been measuring MTBFs for long enough to
  * prounounce on Stability. */
 int