[tor-commits] [nyx/master] Limit locking for updates

atagar at torproject.org atagar at torproject.org
Tue Sep 22 17:08:40 UTC 2015


commit 4f24a6c593ac7e34bf419585389d02b9d7959c6d
Author: Damian Johnson <atagar at torproject.org>
Date:   Sat Aug 1 13:37:12 2015 -0700

    Limit locking for updates
    
    Narrowing the scope where we hold a lock for updates. For most bits we don't
    need any self references. Also making it a no-op if connections are unchanged.
---
 nyx/connections/conn_panel.py |   37 ++++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 17 deletions(-)

diff --git a/nyx/connections/conn_panel.py b/nyx/connections/conn_panel.py
index 629a559..c16f874 100644
--- a/nyx/connections/conn_panel.py
+++ b/nyx/connections/conn_panel.py
@@ -459,22 +459,23 @@ class ConnectionPanel(panel.Panel, threading.Thread):
     """
 
     conn_resolver = nyx.util.tracker.get_connection_tracker()
+    current_resolution_count = conn_resolver.run_counter()
 
     if not conn_resolver.is_alive():
       return  # if we're not fetching connections then this is a no-op
+    elif current_resolution_count == self._last_resource_fetch:
+      return  # no new connections to process
 
-    current_resolution_count = conn_resolver.run_counter()
-
-    with self._vals_lock:
-      new_entries = [entries.ConnectionPanelEntry.from_connection(conn) for conn in conn_resolver.get_value()]
+    new_entries = [entries.ConnectionPanelEntry.from_connection(conn) for conn in conn_resolver.get_value()]
 
-      for circ in tor_controller().get_circuits([]):
-        # Skips established single-hop circuits (these are for directory
-        # fetches, not client circuits)
+    for circ in tor_controller().get_circuits([]):
+      # Skips established single-hop circuits (these are for directory
+      # fetches, not client circuits)
 
-        if not (circ.status == 'BUILT' and len(circ.path) == 1):
-          new_entries.append(entries.ConnectionPanelEntry.from_circuit(circ))
+      if not (circ.status == 'BUILT' and len(circ.path) == 1):
+        new_entries.append(entries.ConnectionPanelEntry.from_circuit(circ))
 
+    with self._vals_lock:
       # update stats for client and exit connections
 
       for entry in new_entries:
@@ -494,13 +495,15 @@ class ConnectionPanel(panel.Panel, threading.Thread):
       self.set_sort_order()
       self._last_resource_fetch = current_resolution_count
 
-      if CONFIG['features.connection.resolveApps']:
-        local_ports, remote_ports = [], []
+    if CONFIG['features.connection.resolveApps']:
+      local_ports, remote_ports = [], []
+
+      for entry in new_entries:
+        line = entry.get_lines()[0]
 
-        for line in self._entry_lines:
-          if line.get_type() in (conn_entry.Category.SOCKS, conn_entry.Category.CONTROL):
-            local_ports.append(line.connection.remote_port)
-          elif line.get_type() == conn_entry.Category.HIDDEN:
-            remote_ports.append(line.connection.local_port)
+        if line.get_type() in (conn_entry.Category.SOCKS, conn_entry.Category.CONTROL):
+          local_ports.append(line.connection.remote_port)
+        elif line.get_type() == conn_entry.Category.HIDDEN:
+          remote_ports.append(line.connection.local_port)
 
-        nyx.util.tracker.get_port_usage_tracker().query(local_ports, remote_ports)
+      nyx.util.tracker.get_port_usage_tracker().query(local_ports, remote_ports)





More information about the tor-commits mailing list