-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using own executor service #61
Changes from 3 commits
f5b5887
aa36937
7c7b6e1
066f398
713c127
38c2c5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,12 +34,15 @@ | |
import hudson.security.ACL; | ||
import java.util.Date; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.ScheduledThreadPoolExecutor; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
import java.util.concurrent.locks.Condition; | ||
import java.util.concurrent.locks.Lock; | ||
import java.util.concurrent.locks.ReentrantLock; | ||
import javax.servlet.http.HttpServletRequest; | ||
import jenkins.util.Timer; | ||
|
||
import hudson.util.DaemonThreadFactory; | ||
import hudson.util.NamingThreadFactory; | ||
import org.acegisecurity.context.SecurityContext; | ||
import org.acegisecurity.context.SecurityContextHolder; | ||
import org.apache.commons.lang.StringUtils; | ||
|
@@ -126,6 +129,11 @@ public abstract class SCMEvent<P> { | |
@CheckForNull | ||
private final String origin; | ||
|
||
/** | ||
* The scheduled executor thread pool. This is initialized lazily since it may be never needed. | ||
*/ | ||
private static ScheduledExecutorService executorService; | ||
|
||
/** | ||
* Constructor to use when the timestamp is available from the external SCM. | ||
* | ||
|
@@ -198,10 +206,13 @@ protected SCMEvent(SCMEvent<P> copy) { | |
* @return a {@link ScheduledExecutorService}. | ||
*/ | ||
@NonNull | ||
protected static ScheduledExecutorService executorService() { | ||
// Future-proofing, if we find out that events are drowning Timer then we may need to move them to their | ||
// own dedicated ScheduledExecutorService thread pool | ||
return Timer.get(); | ||
protected static synchronized ScheduledExecutorService executorService() { | ||
if (executorService == null) { | ||
// corePoolSize is set to 10, but will only be created if needed. | ||
// ScheduledThreadPoolExecutor "acts as a fixed-sized pool using corePoolSize threads" | ||
executorService = new ScheduledThreadPoolExecutor(10, new NamingThreadFactory(new DaemonThreadFactory(), "SCMEvent")); | ||
} | ||
return executorService; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we'll need a See https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/hudson/init/Terminator.java |
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that
Timer
is also wrapped in utilities toACL.SYSTEM
SafeTimerTask
Thread.contextClassLoader
Whether any of those issues are important for this usage, I have no idea offhand. But perhaps
Timer
should get a utility factoryfor easy reuse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one does everything except logging errors if we are not using
SafeTimerTask
I can use exactly the same as in timer... but I choose to use that one for some purpose..
It was so long ago I dont even remember why..
But I remember it was not accident..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And
Timer
is in core so I cannot change it from here..There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not do the impersonation or context class loader maintenance.
Of course, but we can have a core PR, and via JEP-305 it is even straightforward to have an
on-hold
PR in the plugin which verifies its usage.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that there was change in Timer.. ok.. so it does more now..
So it would be great to move it somewhere in one place..
And maybe it would be easier and better to just allow changing size of timer pool via variable or something?
Here https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/jenkins/util/Timer.java#L47
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A thread dump would be the background we need to analyze why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can get thread dump.. just need to wait for busy day..
But all waits here https://github.com/kohsuke/github-api/blob/master/src/main/java/org/kohsuke/github/RateLimitHandler.java#L39
We are just got rate limit badly..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And while we dont have problems with waiting for GH..
We have problem that nothing else (that relies on
Timer
) on jenkins is working..There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need the thread dump to see what caller is to blame.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Webhook processing is going into this pool..
And there is issue with GH processing itself (sometimes rate limiting is not resetting)..
But not that easy to grasp..
And would be best to fix somewhere here..
https://github.com/kohsuke/github-api/blob/master/src/main/java/org/kohsuke/github/GitHub.java#L316
Once for good :)