14
votes

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?

5
Closed as off-topic, is that for real? I'm sorry to say I don't often write these types of comments, but -1 to the mods for that. The question clearly states a specific problem and is asking for a configuration solution.Ed Randall

5 Answers

21
votes

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.

4
votes

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.

2
votes

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 Parametertized 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.

1
votes

You may also use the Throttle Concurrent Builds plugin to restrict how many instances of a job can run in parallel on the same node

0
votes

I have two labels -- one for small tasks and one for big tasks. I have one executor for the big task and 4 for the small tasks. This does balance things a little.