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

[tor-commits] [onionoo/master] Simplify weights status updater by taking out threading code.



commit 97fbdee60d66a627fa9b378fc20767864bf275cc
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Fri Mar 14 12:10:39 2014 +0100

    Simplify weights status updater by taking out threading code.
    
    The threading code was never used, because it's broken.  No reason to keep
    it.
---
 .../torproject/onionoo/WeightsStatusUpdater.java   |   69 +++++---------------
 1 file changed, 15 insertions(+), 54 deletions(-)

diff --git a/src/org/torproject/onionoo/WeightsStatusUpdater.java b/src/org/torproject/onionoo/WeightsStatusUpdater.java
index 5e890ef..79296d3 100644
--- a/src/org/torproject/onionoo/WeightsStatusUpdater.java
+++ b/src/org/torproject/onionoo/WeightsStatusUpdater.java
@@ -3,11 +3,9 @@
 package org.torproject.onionoo;
 
 import java.text.SimpleDateFormat;
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.SortedMap;
@@ -66,6 +64,7 @@ public class WeightsStatusUpdater implements DescriptorListener,
 
   private void processRelayNetworkConsensus(
       RelayNetworkStatusConsensus consensus) {
+    // TODO This does not scale for bulk imports.
     this.consensuses.add(consensus);
   }
 
@@ -107,62 +106,24 @@ public class WeightsStatusUpdater implements DescriptorListener,
     }
   }
 
-  // TODO Use 4 workers once threading problems are solved.
-  private static final int HISTORY_UPDATER_WORKERS_NUM = 1;
   private void updateWeightsHistory(long validAfterMillis,
       long freshUntilMillis,
       SortedMap<String, double[]> pathSelectionWeights) {
-    List<HistoryUpdateWorker> historyUpdateWorkers =
-        new ArrayList<HistoryUpdateWorker>();
-    for (int i = 0; i < HISTORY_UPDATER_WORKERS_NUM; i++) {
-      HistoryUpdateWorker historyUpdateWorker =
-          new HistoryUpdateWorker(validAfterMillis, freshUntilMillis,
-          pathSelectionWeights, this);
-      historyUpdateWorkers.add(historyUpdateWorker);
-      historyUpdateWorker.setDaemon(true);
-      historyUpdateWorker.start();
-    }
-    for (HistoryUpdateWorker historyUpdateWorker : historyUpdateWorkers) {
-      try {
-        historyUpdateWorker.join();
-      } catch (InterruptedException e) {
-        /* This is not something that we can take care of.  Just leave the
-         * worker thread alone. */
-      }
-    }
-  }
-
-  private class HistoryUpdateWorker extends Thread {
-    private long validAfterMillis;
-    private long freshUntilMillis;
-    private SortedMap<String, double[]> pathSelectionWeights;
-    private WeightsStatusUpdater parent;
-    public HistoryUpdateWorker(long validAfterMillis,
-        long freshUntilMillis,
-        SortedMap<String, double[]> pathSelectionWeights,
-        WeightsStatusUpdater parent) {
-      this.validAfterMillis = validAfterMillis;
-      this.freshUntilMillis = freshUntilMillis;
-      this.pathSelectionWeights = pathSelectionWeights;
-      this.parent = parent;
-    }
-    public void run() {
-      String fingerprint = null;
-      double[] weights = null;
-      do {
-        fingerprint = null;
-        synchronized (pathSelectionWeights) {
-          if (!pathSelectionWeights.isEmpty()) {
-            fingerprint = pathSelectionWeights.firstKey();
-            weights = pathSelectionWeights.remove(fingerprint);
-          }
-        }
-        if (fingerprint != null) {
-          this.parent.addToHistory(fingerprint, this.validAfterMillis,
-              this.freshUntilMillis, weights);
+    String fingerprint = null;
+    double[] weights = null;
+    do {
+      fingerprint = null;
+      synchronized (pathSelectionWeights) {
+        if (!pathSelectionWeights.isEmpty()) {
+          fingerprint = pathSelectionWeights.firstKey();
+          weights = pathSelectionWeights.remove(fingerprint);
         }
-      } while (fingerprint != null);
-    }
+      }
+      if (fingerprint != null) {
+        this.addToHistory(fingerprint, validAfterMillis,
+            freshUntilMillis, weights);
+      }
+    } while (fingerprint != null);
   }
 
   private SortedMap<String, double[]> calculatePathSelectionProbabilities(



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