Bug 36138 - mod_jk load balance algorithm that accounts for current worker load
Summary: mod_jk load balance algorithm that accounts for current worker load
Alias: None
Product: Tomcat Connectors
Classification: Unclassified
Component: Common (show other bugs)
Version: unspecified
Hardware: All other
: P2 enhancement (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
Depends on:
Blocks: 37245
  Show dependency tree
Reported: 2005-08-11 06:11 UTC by Chris Lamprecht
Modified: 2008-10-05 03:09 UTC (History)
0 users

New load balancing algorithm for mod_jk (18.05 KB, patch)
2005-08-11 06:12 UTC, Chris Lamprecht
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Lamprecht 2005-08-11 06:11:44 UTC
This is the mod_jk patch I mentioned on the tomcat-dev mailing list on August 

The patch adds a new lb.method option 'B' for 'Busyness'.  The algorithm picks 
the lbworker with the lowest current load, based on how many requests the 
worker is currently serving (the "Busy" column in the jkstatus page).  This 
number is divided by the worker's lbfactor, and the lowest value (least busy) 
worker is picked.  

We tested about 25-30 threads against 6 load-balanced tomcats with requests 
that take about 250ms each to complete.  Using the "Busyness" algorithm 
improved our throughput from 12-16 requests per second to 60+ requests per 
second, and watching the jkstatus page showed that all servers were 
kept "evenly" busy.  If one particular server started lagging, its Busy value 
increased, so it received fewer requests.  If a request is received when none 
of the workers are busy, this algorithm is effectively an evenly-weighted 

Note that we found some race conditions with the code that updates the various 
lb status values, especially the lbworker "busy" value, which our algorithm 
requires to be accurate.  To fix this, we had to refactor some of the shared 
memory and critical-section locking code, by moving the lock into 
get_most_suitable_worker() (jk_lb_worker.c).  We also found some problems that 
would cause the 'busy' value to be set to less than zero (displaying MAX_INT - 
1, for example, in jkstatus).

We fixed this by setting the busy value to 0 if it is ever less than 0.  See 
jk_lb_worker.c lines 389-400.

Finally, we added a new column to the jkstatus page.  The "Ssc" column now 
reports the number of times the worker was reused from sticky session.  See 
jk_shm.c line 89, and jk_lb_worker.c line 584.  

We have load-tested this patch under apache 2.0.50, and we've also been 
running it in a busy production site for almost a week.  

This patch is donated by Andrew Hudson and Chris Lamprecht.
Comment 1 Chris Lamprecht 2005-08-11 06:12:45 UTC
Created attachment 16009 [details]
New load balancing algorithm for mod_jk
Comment 2 Shankar Unni 2006-02-27 22:50:22 UTC
fixed summary back - someone (mohan@...) accidentally munged it.
Comment 3 Mladen Turk 2006-03-16 07:55:29 UTC
Commited to the trunk.
I have modified couple of things, mostly removing extra stuff added to shm.