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

[tor-commits] [tor/maint-0.2.2] Only call cull_wedged_cpuworkers once every 60 seconds.



commit 8e388bc39ceb9b1a642359005b320cdc994f8a4e
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Sat Nov 19 18:29:42 2011 -0500

    Only call cull_wedged_cpuworkers once every 60 seconds.
    
    The function is over 10 or 20% on some of Moritz's profiles, depending
    on how you could.
    
    Since it's checking for a multi-hour timeout, this is safe to do.
    
    Fixes bug 4518.
---
 changes/bug4518    |    4 ++++
 src/or/cpuworker.c |   14 ++++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/changes/bug4518 b/changes/bug4518
new file mode 100644
index 0000000..8dcb93b
--- /dev/null
+++ b/changes/bug4518
@@ -0,0 +1,4 @@
+  o Minor bugfixes (performance):
+    - Avoid frequent calls to the fairly expensive cull_wedged_cpuworkers
+      function. This was eating up hideously large amounts of time on some
+      busy servers. Fixes bug 4518.
diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c
index c5e4863..9d196d3 100644
--- a/src/or/cpuworker.c
+++ b/src/or/cpuworker.c
@@ -446,9 +446,19 @@ assign_onionskin_to_cpuworker(connection_t *cpuworker,
 {
   char qbuf[1];
   char tag[TAG_LEN];
+  time_t now = approx_time();
+  static time_t last_culled_cpuworkers = 0;
 
-  cull_wedged_cpuworkers();
-  spawn_enough_cpuworkers();
+  /* Checking for wedged cpuworkers requires a linear search over all
+   * connections, so let's do it only once a minute.
+   */
+#define CULL_CPUWORKERS_INTERVAL 60
+
+  if (last_culled_cpuworkers + CULL_CPUWORKERS_INTERVAL <= now) {
+    cull_wedged_cpuworkers();
+    spawn_enough_cpuworkers();
+    last_culled_cpuworkers = now;
+  }
 
   if (1) {
     if (num_cpuworkers_busy == num_cpuworkers) {



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