I have a Jenkins pipeline job that does the following:
- Create a list of jobs, each of which is a single shell operation which takes a non trivial amount of time
- Run the jobs in the list in parallel
If the jobs take, for example, 10, 5, 7 and 8 minutes then I would expect this stage of the job to take about 10 minutes to complete (the duration of the longest single job with a little extra time for setup and teardown of the parallel operation). However I see something much closer to 30 minutes. A cut-down version of the Jenkinsfile which still shows the problem is below.
node('docker-centos7') { stage('Build') { sh "date" jobs = [:] ["foo", "bar", "baz", "qux"].each { vals -> jobs[vals] = { sh "date +start_${vals}_%F_%T; for i in \$(seq 1 600); do sleep 1; date +${vals}_%F_%T; done; date +done_${vals}_%F_%T;" } } parallel jobs sh "date" } }
This should start 4 parallel jobs which each take 10 minutes but on my server this takes > 30 minutes to run. The output of this job on my server clearly shows that there is a lengthy delay between the last job completing and the final sh "date" call.
+ date +done_baz_%F_%T done_baz_2024-02-28_15:23:57 [Pipeline] } [Pipeline] } [Pipeline] } [Pipeline] } [Pipeline] // parallel + date Wed Feb 28 15:44:48 GMT 2024
I have some evidence that this might be related to the amount of output that the job produces, if I replace the loop that prints 600 messages with a 1 second delay between each with a single 600 second wait then the extra delay goes away.