Skip to content

Commit

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

- Provide a means to completely disable the slow request checker both at startup and in a running Jenkins
  • Loading branch information
stephenc committed Jul 22, 2014
1 parent 1499fe2 commit 8c8df7a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
Expand Up @@ -39,6 +39,14 @@ public class SlowRequestChecker extends PeriodicWork {
public static final int THRESHOLD =
Integer.getInteger(SlowRequestChecker.class.getName()+".THRESHOLD_MS", 10000);

/**
* Provide a means to disable the slow request checker. This is a volatile non-final field as if you run into
* issues in a running Jenkins you may need to disable without restarting Jenkins.
*
* @since 2.12
*/
public static volatile boolean DISABLED = Boolean.getBoolean(SlowRequestChecker.class.getName()+".DISABLED");

@Inject
SlowRequestFilter filter;

Expand All @@ -56,6 +64,9 @@ public long getRecurrencePeriod() {

@Override
protected void doRun() throws Exception {
if (DISABLED) {
return;
}
ThreadInfo[] threads = null;

final long now = System.currentTimeMillis();
Expand Down
Expand Up @@ -27,14 +27,18 @@ public class SlowRequestFilter implements Filter {
final ConcurrentMap<Thread,InflightRequest> tracker = new ConcurrentHashMap<Thread, InflightRequest>();

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
Thread t = Thread.currentThread();
InflightRequest req = new InflightRequest((HttpServletRequest) request);
tracker.put(t, req);
try {
chain.doFilter(request,response);
} finally {
req.ended = true;
tracker.remove(t);
if (SlowRequestChecker.DISABLED) {
chain.doFilter(request, response);
} else {
Thread t = Thread.currentThread();
InflightRequest req = new InflightRequest((HttpServletRequest) request);
tracker.put(t, req);
try {
chain.doFilter(request, response);
} finally {
req.ended = true;
tracker.remove(t);
}
}
}

Expand All @@ -47,7 +51,9 @@ public void destroy() {
@Initializer
public static void init() throws ServletException {
Injector inj = Jenkins.getInstance().getInjector();
if (inj==null) return;
if (inj == null) {
return;
}
PluginServletFilter.addFilter(inj.getInstance(SlowRequestFilter.class));
}
}

0 comments on commit 8c8df7a

Please sign in to comment.