Skip to content

Commit

Permalink
[FIXED JENKINS-23904] SlowRequestCheck= kills UI performance and pegs…
Browse files Browse the repository at this point in the history
… CPU at 100%

- Made the timings for this configurable by a system property

- Only collect thread dump if there is a slow request
  • Loading branch information
stephenc committed Jul 22, 2014
1 parent 2b43d35 commit 1499fe2
Showing 1 changed file with 22 additions and 9 deletions.
Expand Up @@ -24,6 +24,21 @@
*/
@Extension
public class SlowRequestChecker extends PeriodicWork {
/**
* How often to run the slow request checker
* @since 2.12
*/
public static final int RECURRENCE_PERIOD_SEC =
Integer.getInteger(SlowRequestChecker.class.getName()+".RECURRENCE_PERIOD_SEC", 3);

/**
* Time in milliseconds that's considered too slow for requests.
* Starting with a bit conservative value to catch serious offenders first.
* If this value is less than twice {@link #RECURRENCE_PERIOD_SEC} then that will be used instead.
*/
public static final int THRESHOLD =
Integer.getInteger(SlowRequestChecker.class.getName()+".THRESHOLD_MS", 10000);

@Inject
SlowRequestFilter filter;

Expand All @@ -36,23 +51,26 @@ public class SlowRequestChecker extends PeriodicWork {

@Override
public long getRecurrencePeriod() {
return TimeUnit.SECONDS.toMillis(3);
return TimeUnit.SECONDS.toMillis(RECURRENCE_PERIOD_SEC);
}

@Override
protected void doRun() throws Exception {
ThreadInfo[] threads;
threads = Functions.getThreadInfos();
ThreadInfo[] threads = null;

final long now = System.currentTimeMillis();

long iota = System.currentTimeMillis();

final long recurrencePeriosMillis = TimeUnit.SECONDS.toMillis(RECURRENCE_PERIOD_SEC);
long thresholdMillis = recurrencePeriosMillis > THRESHOLD ?
recurrencePeriosMillis * 2 : THRESHOLD;

OUTER:
for (InflightRequest req : filter.tracker.values()) {
long totalTime = now - req.startTime;

if (totalTime> THRESHOLD) {
if (totalTime> thresholdMillis) {
if (threads==null)
threads = Functions.getThreadInfos();

Expand Down Expand Up @@ -88,9 +106,4 @@ protected void doRun() throws Exception {
}
}

/**
* Time in milliseconds that's considered too slow for requests.
* Starting with a bit conservative value to catch serious offenders first.
*/
public static final int THRESHOLD = 10000;
}

0 comments on commit 1499fe2

Please sign in to comment.