Why is the container step slowing down my build?

Article ID:360048585252
1 minute readKnowledge base

Issue

I noticed that when using the container step, my build is getting slower.

Resolution

The container step introduces an overhead because internally it is directly using the Kubernetes API to run commands (while without it, only the remoting protocol is used).

This has two implications:

  1. As the container step makes Kubernetes API call, it can be limited by the Max connections to Kubernetes API. This value is set to 32 by default and you can increase it in the Cloud Configuration (under <jenkins_url>/configureClouds).

  2. The step uses a buffer to send commands to the container. In versions older than 1.27.0 of the Kubernetes Plugin the size of this buffer was 2kb by default. This could lead to fragmentation of calls (and therefore slowness) in some cases. From 1.27.0 onward, the size of the buffer was bumped to 16kb by default. It should fix this slowness.

Workaround

In case you cannot bump the Kubernetes Plugin to version 1.27.0 or greater, you can manually set up the buffer size with: -Dorg.csanchez.jenkins.plugins.kubernetes.pipeline.ContainerExecDecorator.stdinBufferSize=16384. Please review How to add Java arguments to Jenkins? if you need help adding an argument to Jenkins.

Tested product/plugin versions

References