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

[tor-commits] [metrics-web/master] Improve runtime performance of hidserv module.



commit 4448f5fc0de60763d42e724036bda8388435af91
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Fri Nov 22 09:47:20 2019 +0100

    Improve runtime performance of hidserv module.
    
    Fixes #25924.
---
 CHANGELOG.md                                       |  5 ++
 .../metrics/stats/hidserv/Extrapolator.java        | 82 ++++++++++------------
 2 files changed, 43 insertions(+), 44 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index fe74cf5..797d54b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,10 @@
 # Changes in version 1.?.? - 2019-1?-??
 
+ * Medium changes
+   - Improve runtime performance of the hidserv module by storing
+     extrapolated statistics even if computed network fractions are
+     zero, to avoid re-processing these statistics over and over.
+
 
 # Changes in version 1.3.0 - 2019-11-09
 
diff --git a/src/main/java/org/torproject/metrics/stats/hidserv/Extrapolator.java b/src/main/java/org/torproject/metrics/stats/hidserv/Extrapolator.java
index 0dcc638..7a44425 100644
--- a/src/main/java/org/torproject/metrics/stats/hidserv/Extrapolator.java
+++ b/src/main/java/org/torproject/metrics/stats/hidserv/Extrapolator.java
@@ -197,52 +197,46 @@ public class Extrapolator {
           }
         }
 
-        /* If we don't know a single consensus with valid-after time in
-         * the statistics interval, skip this stat. */
-        if (consensuses == 0) {
-          continue;
+        /* Compute means of network fractions, or assume 0.0 if we don't
+         * know a single consensus with valid-after time in the statistics
+         * interval. */
+        double fractionRendRelayedCells = consensuses == 0 ? 0.0
+            : sumFractionRendRelayedCells / consensuses;
+        double fractionDirOnionsSeen = consensuses == 0 ? 0.0
+            : sumFractionDirOnionsSeen / consensuses;
+
+        /* Extrapolate network totals. If we don't know a single
+         * consensus, store an empty statistic anyway to avoid processing
+         * these reported statistics over and over. */
+        ExtrapolatedHidServStats extrapolated =
+            new ExtrapolatedHidServStats(
+            statsDateMillis, fingerprint);
+        if (fractionRendRelayedCells > 0.0) {
+          extrapolated.setFractionRendRelayedCells(
+              fractionRendRelayedCells);
+          /* Extrapolating cells on rendezvous circuits is as easy as
+           * dividing the reported number by the computed network
+           * fraction. */
+          double extrapolatedRendRelayedCells =
+              stats.getRendRelayedCells() / fractionRendRelayedCells;
+          extrapolated.setExtrapolatedRendRelayedCells(
+              extrapolatedRendRelayedCells);
         }
-
-        /* Compute means of network fractions. */
-        double fractionRendRelayedCells =
-            sumFractionRendRelayedCells / consensuses;
-        double fractionDirOnionsSeen =
-            sumFractionDirOnionsSeen / consensuses;
-
-        /* If at least one fraction is positive, extrapolate network
-         * totals. */
-        if (fractionRendRelayedCells > 0.0
-            || fractionDirOnionsSeen > 0.0) {
-          ExtrapolatedHidServStats extrapolated =
-              new ExtrapolatedHidServStats(
-              statsDateMillis, fingerprint);
-          if (fractionRendRelayedCells > 0.0) {
-            extrapolated.setFractionRendRelayedCells(
-                fractionRendRelayedCells);
-            /* Extrapolating cells on rendezvous circuits is as easy as
-             * dividing the reported number by the computed network
-             * fraction. */
-            double extrapolatedRendRelayedCells =
-                stats.getRendRelayedCells() / fractionRendRelayedCells;
-            extrapolated.setExtrapolatedRendRelayedCells(
-                extrapolatedRendRelayedCells);
-          }
-          if (fractionDirOnionsSeen > 0.0) {
-            extrapolated.setFractionDirOnionsSeen(
-                fractionDirOnionsSeen);
-            /* Extrapolating reported unique .onion addresses to the
-             * total number in the network is more difficult.  In short,
-             * each descriptor is stored to 12 (likely) different
-             * directories, so we'll have to divide the reported number by
-             * 12 and then by the computed network fraction of this
-             * directory. */
-            double extrapolatedDirOnionsSeen =
-                stats.getDirOnionsSeen() / (12.0 * fractionDirOnionsSeen);
-            extrapolated.setExtrapolatedDirOnionsSeen(
-                extrapolatedDirOnionsSeen);
-          }
-          extrapolatedStats.add(extrapolated);
+        if (fractionDirOnionsSeen > 0.0) {
+          extrapolated.setFractionDirOnionsSeen(
+              fractionDirOnionsSeen);
+          /* Extrapolating reported unique .onion addresses to the
+           * total number in the network is more difficult.  In short,
+           * each descriptor is stored to 12 (likely) different
+           * directories, so we'll have to divide the reported number by
+           * 12 and then by the computed network fraction of this
+           * directory. */
+          double extrapolatedDirOnionsSeen =
+              stats.getDirOnionsSeen() / (12.0 * fractionDirOnionsSeen);
+          extrapolated.setExtrapolatedDirOnionsSeen(
+              extrapolatedDirOnionsSeen);
         }
+        extrapolatedStats.add(extrapolated);
       }
     }
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits