Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I modify the Load Balancing behavior Jenkins uses to control slaves?

We use Jenkins for our CI build system. We also use 'concurrent builds' so that Jenkins will build each change independently. This means we often have 5 or 6 builds of the same job running simultaneously. To accommodate this, we have 4 slaves each with 12 executors.

The problem is that Jenkins doesn't really 'load balance' among its slaves. It tries to build a job on the same slave that it previously built on (presumably to reduce the time syncing from source control). This is a problem because Jenkins will build all 6 instances of our build on the same slave (or more likely between 2 slaves). One build machine gets bogged down and runs very slowly while the rest of them sit idle.

How do I configure the load balancing behavior of Jenkins, and how it controls its slaves?

like image 533
Jay Spang Avatar asked Jun 13 '12 22:06

Jay Spang


3 Answers

We were facing a similar issue. So I've put together a plugin that changes the Load Balancer in Jenkins to select a node that currently has the least load - https://plugins.jenkins.io/leastload/

Any feedback is appreciated.

like image 106
bstick12 Avatar answered Oct 17 '22 10:10

bstick12


If you do not find a plugin that does it automatically, here's an idea of what you can do:

  • Install Node Label Parameter plugin

  • Add SLAVE parameter to your jobs

  • Restrict jobs to run on ${SLAVE}

  • Add a trigger job that will do the following:

    • Analyze load distribution via a System Groovy Script and decide on which node to start next build.
    • Dispatch the build on that node with Parameterized Trigger plugin by assigning appropriate value to SLAVE parameter.

In order to analyze load distribution you need to install Groovy plugin and familiarize yourself with Jenkins Main Module API. Here are some useful initial pointers.

like image 34
malenkiy_scot Avatar answered Oct 17 '22 09:10

malenkiy_scot


If your build machines cannot comfortably handle more than 1 build, why configure them with 12 executors? If that is indeed the case, you should reduce the number of executors to 1. My Jenkins has 30 slaves, each with 1 executor.

like image 34
sti Avatar answered Oct 17 '22 09:10

sti