Pipeline - Difference between flyweight and heavyweight Executors

Issue

  • What are flyweight executors?
  • What is the difference between normal (heavyweight) executors and flyweight executors?
  • What is the performance impact of flyweight executors on my running master?

Environment

Related

Resolution

flyweight executors are just threads, running inside of the Jenkins master’s JVM. Flyweight executors are unlimited and will be created automatically when needed, unlike heavyweight executors, which are limited based on their node’s configuration.

Every Pipeline build itself runs on the master, using a flyweight Executor — an uncounted slot that is assumed to not take any significant computational power.

Every Pipeline script itself runs on the master using a flyweight executor (i.e. Java thread). Pipeline steps such as sh and bat will execute on a heavyweight executor when enclosed in a node block, so in a well-designed Pipeline where complicated logic happens only in those steps, the flyweight executor should be idling while steps run on remote agents for most of the build.

Flyweight executors are created on-demand and then removed when they are no longer needed.

The memory usage depends on the complexity of the pipeline.

To reduce the resource usage of flyweight executors, you should use shell steps for any logic in your pipeline that requires significant machine resources. For example, rather than directly calling a Java or Groovy library in your Pipeline, consider moving that logic into a standalone script and executing it via a shell step that calls Groovy from the command line. Using these steps also makes the Pipeline-specific parts easier to test and improves the stability of your Jenkins master overall.

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.