Any where from the Run object to find out how much CPU the job is consuming?

248 views
Skip to first unread message

Michael Carter

unread,
Mar 30, 2021, 1:38:17 PM3/30/21
to Jenkins Developers
Basically the use case.

We've got a few jobs doing:

loop {
  retry(10) {
     withCredetials {
         ... some code. that takes about 10ms. or less
     }
  }
}

It's eating up 100% CPU on the master.   I suspect we have other(s)/cases of people doing things like this and I'm trying to add a way to detect the high CPU usage via my plugin.    

Jesse Glick

unread,
Mar 30, 2021, 3:38:03 PM3/30/21
to Jenkins Dev
Run `jstack`? Not sure what this plugin is or how it relates to diagnosing high CPU usage.

Michael Carter

unread,
Mar 30, 2021, 4:21:33 PM3/30/21
to Jenkins Developers
Guess I should have added more context.  

I have users adding this type of code to their pipeline scripts.

loop {
  retry(10) {
     withCredetials {
         ... some code. that takes about 10ms. or less
     }
  }
}

Which of course causes a lot of CPU usage on the master due to the frequent lookups to the identical username/password.    What I'm looking is there a way from inside Jenkins https://javadoc.jenkins-ci.org/hudson/model/Run.html to get at how much CPU/Memory the Pipeline Job is used during it's run?

I want to write a Jenkins Plugin (Like an Action Badge or something) to report on it to screen and save to an external audit DB.  But I first must get the resource usage from inside Jenkins somehow.    

Hence the question can I get to it somehow from https://javadoc.jenkins-ci.org/hudson/model/Run.html or do I have to hook into the onStarted/onCompleted triggers with some sort of monitor?

Jesse Glick

unread,
Mar 30, 2021, 5:00:24 PM3/30/21
to Jenkins Dev
This is not really possible. There is https://github.com/jenkinsci/workflow-cps-plugin/blob/f522e783e917bc0aa0513a29684285b710163905/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java#L357-L387 (which is not an API you may use from another plugin) but the `run` timing measures only CPS VM thread usage, not aggregate time used by steps invoked from that thread, and certainly not memory usage however one might define that (a complex topic).

You might have better success detecting and warning about dumb idioms. Not necessarily with a plugin.

Basil Crow

unread,
Mar 30, 2021, 5:14:31 PM3/30/21
to jenkin...@googlegroups.com
On Tue, Mar 30, 2021 at 1:21 PM Michael Carter
<mikeyca...@gmail.com> wrote:
>
> Which of course causes a lot of CPU usage on the master due to the frequent lookups to the identical username/password.

I suppose you have already concluded that the high CPU usage is caused
by the abovementioned credential lookups. But in case you (or anyone
else) are still investigating other possible causes of high CPU usage,
I have had great success with generating flame graphs from Jenkins
controller Java processes using
https://github.com/jvm-profiling-tools/async-profiler. It's pretty
fascinating to look at the flame graph for a minute or so of execution
of even a healthy Jenkins controller: you get a sense of what your
workload typically looks like and therefore develop a baseline against
which to analyze pathological performance later on. It's even more
fascinating to look at the flame graph for Jenkins initialization,
especially on a busy controller.
Reply all
Reply to author
Forward
0 new messages