[Checkins] SVN: zc.resumelb/trunk/src/zc/resumelb/ Changed the load-balancing algorithm to try just a little bit harder

jim cvs-admin at zope.org
Mon Apr 23 17:25:41 UTC 2012


Log message for revision 125238:
  Changed the load-balancing algorithm to try just a little bit harder
  to keep work with skilled workers by not penalizing workers for
  their first outstanding request. (In other words, when adjusting
  worker scrores chacking a maximum backlog, we subtract 1 from the
  worker's backlog if it's non-zero.
  

Changed:
  U   zc.resumelb/trunk/src/zc/resumelb/README.txt
  U   zc.resumelb/trunk/src/zc/resumelb/lb.py
  U   zc.resumelb/trunk/src/zc/resumelb/pool.test

-=-
Modified: zc.resumelb/trunk/src/zc/resumelb/README.txt
===================================================================
--- zc.resumelb/trunk/src/zc/resumelb/README.txt	2012-04-23 16:46:28 UTC (rev 125237)
+++ zc.resumelb/trunk/src/zc/resumelb/README.txt	2012-04-23 17:25:37 UTC (rev 125238)
@@ -250,6 +250,12 @@
   parameter to be used, which allows new workers to be better
   utilized.
 
+- Changed the load-balancing algorithm to try just a little bit harder
+  to keep work with skilled workers by not penalizing workers for
+  their first outstanding request. (In other words, when adjusting
+  worker scrores chacking a maximum backlog, we subtract 1 from the
+  worker's backlog if it's non-zero.
+
 0.3.0 (2012-03-28)
 ------------------
 

Modified: zc.resumelb/trunk/src/zc/resumelb/lb.py
===================================================================
--- zc.resumelb/trunk/src/zc/resumelb/lb.py	2012-04-23 16:46:28 UTC (rev 125237)
+++ zc.resumelb/trunk/src/zc/resumelb/lb.py	2012-04-23 17:25:37 UTC (rev 125238)
@@ -228,8 +228,9 @@
         for score, worker in skilled:
             if (worker.mbacklog - min_backlog) > max_backlog:
                 continue
-            backlog = worker.backlog + 1
-            score /= backlog
+            backlog = worker.backlog
+            if backlog > 1:
+                score /= backlog
             if (score > best_score):
                 best_score = score
                 best_worker = worker

Modified: zc.resumelb/trunk/src/zc/resumelb/pool.test
===================================================================
--- zc.resumelb/trunk/src/zc/resumelb/pool.test	2012-04-23 16:46:28 UTC (rev 125237)
+++ zc.resumelb/trunk/src/zc/resumelb/pool.test	2012-04-23 17:25:37 UTC (rev 125238)
@@ -174,9 +174,9 @@
 
 When a worker is done doing its work, we put it back in the pool:
 
-    >>> for i in range(8):
+    >>> for i in range(7):
     ...     pool.put(w1)
-    >>> for i in range(8):
+    >>> for i in range(7):
     ...     pool.put(w3)
 
     >>> pool # doctest: +ELLIPSIS
@@ -184,7 +184,7 @@
       bar: w2(0.5,1.0)
       foo: w1(0.5,2.29...), w3(0.5,2.29...), w5(0.5,1.57...)
     Backlogs:
-      overall backlog: 1 Decayed: 8.41... Avg: 1.68...
+      overall backlog: 3 Decayed: 9.41... Avg: 1.88...
       0: [w1, w3, w4]
       1: [w2]
       2: [w5]
@@ -198,44 +198,43 @@
 normally be done by workers periodically, after collecting performance
 data.
 
-    >>> pool.new_resume(w1, {'foo': 6.0})
+    >>> pool.new_resume(w1, {'foo': 5.9})
     >>> pool.new_resume(w2, {'bar': 2.0, 'foo': 2.0})
     >>> pool.new_resume(w3, {'foo': 3.8})
 
     >>> pool # doctest: +ELLIPSIS
     Request classes:
       bar: w2(2.0,1.0)
-      foo: w5(0.5,1.57...), w2(2.0,1.0), w3(3.8,2.29...), w1(6.0,1.96...)
+      foo: w5(0.5,1.57...), w2(2.0,1.0), w3(3.8,2.29...), w1(5.9,1.96...)
     Backlogs:
-      overall backlog: 2 Decayed: 8.00... Avg: 1.60...
+      overall backlog: 4 Decayed: 9.0... Avg: 1.8...
       0: [w3, w4]
       1: [w1, w2]
       2: [w5]
 
     >>> pool.get('foo')
-    w3
-    >>> pool.get('foo')
     w1
     >>> pool.get('foo')
-    w1
+    w3
+    >>> pool.get('foo')
+    w3
 
     >>> pool # doctest: +ELLIPSIS
     Request classes:
       bar: w2(2.0,1.0)
-      foo: w5(0.5,1.57...), w2(2.0,1.0), w3(3.8,1.96...), w1(6.0,2.23...)
+      foo: w5(0.5,1.5...), w2(2.0,1.0), w3(3.8,1.97...), w1(5.9,1.9...)
     Backlogs:
-      overall backlog: 5 Decayed: 7.31... Avg: 1.46...
+      overall backlog: 7 Decayed: 8.5... Avg: 1.7...
       0: [w4]
-      1: [w2, w3]
-      2: [w5]
-      3: [w1]
+      1: [w2]
+      2: [w1, w3, w5]
 
     >>> pool.get('foo')
-    w3
-    >>> pool.get('foo')
     w1
     >>> pool.get('foo')
-    w3
+    w2
+    >>> pool.get('foo')
+    w1
 
     >>> pool.put(w1)
     >>> pool.put(w3)
@@ -245,17 +244,16 @@
     >>> pool.put(w3)
     >>> pool # doctest: +ELLIPSIS
     Request classes:
-      bar: w2(2.0,1.0)
-      foo: w5(0.5,1.57...), w2(2.0,1.0), w3(3.8,1.40...), w1(6.0,2.75...)
+      bar: w2(2.0,1.5...)
+      foo: w5(0.5,1.5...), w2(2.0,1.5...), w3(3.8,1.2...), w1(5.9,2.7...)
     Backlogs:
-      overall backlog: 2 Decayed: 6.39... Avg: 1.27...
+      overall backlog: 4 Decayed: 7.9... Avg: 1.5...
       0: [w3, w4]
-      1: [w2]
-      2: [w5]
+      2: [w2, w5]
       3: [w1]
 
     >>> [pool.get('foo') for i in range(5)]
-    [w3, w3, w1, w3, w2]
+    [w3, w3, w1, w3, w1]
 
 Worker disconnect
 =================
@@ -269,7 +267,7 @@
       bar: w2(2.0,1.57...)
       foo: w5(0.5,1.57...), w2(2.0,1.57...)
     Backlogs:
-      overall backlog: 0 Decayed: 5.57... Avg: 1.85...
+      overall backlog: 1 Decayed: 7.1... Avg: 2.3...
       0: [w4]
       2: [w2, w5]
 



More information about the checkins mailing list