-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Extract ThrottledTaskRunner #93436
Extract ThrottledTaskRunner #93436
Conversation
Generalizes `PrioritizedThrottledTaskRunner` slightly: - The throttling behaviour is also useful for tasks which do not complete synchronously. The new `ThrottledTaskRunner` passes a `Releasable` to each task, which until released will prevent spawning further tasks. - The only part that needs the tasks to be `Comparable<>` is the queue. Letting the caller specify the queue means that we can also use the throttling without the prioritisation.
Pinging @elastic/es-distributed (Team:Distributed) |
I particularly would like to use this generalisation in #92373, although I think we will find other uses too. |
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.
Thanks David. Added some questions. Aside from using theActionListener<Releasable>
there doesn't seem to be a lot of changes in terms of concurrency to the task runner itself? Is that correct?
private static void awaitBarrier(CyclicBarrier barrier) { | ||
try { | ||
barrier.await(10, TimeUnit.SECONDS); | ||
} catch (Exception e) { | ||
throw new AssertionError("unexpected", e); | ||
} | ||
} |
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.
Aside from getting rid of this, is there any other advantage in introducing TestBarrier
?
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.
No, it's just about those pointless checked exceptions.
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 do this separately too, there's lots of other spots where this is useful)
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.
TBH, I find the class unnecessary. A utility function which takes a timeout parameter will do as well. But I'm fine with leaving it, if you'd like.
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.
Ok, I'll do this in a separate PR
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.
If you find it useful, it's perfectly fine here. I was just trying to understand why we need it at all. 😄
public void setUp() throws Exception { | ||
super.setUp(); | ||
maxThreads = between(1, 10); | ||
executor = EsExecutors.newScaling("test", 1, maxThreads, 0, TimeUnit.MILLISECONDS, false, threadFactory, threadContext); |
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.
Does this also need to change like #93446?
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.
Yes.
|
||
import java.util.concurrent.Executor; | ||
|
||
public class ThrottledTaskRunner extends AbstractThrottledTaskRunner<ActionListener<Releasable>> { |
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.
Is this used anywhere? If not, could we introduce it, when it is needed?
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.
@DaveCTurner There were two |
The same fix as in elastic#93446, which was missed in elastic#93436
Ah sorry you're right, I forgot about this new test suite. I opened #93505. |
Generalizes
PrioritizedThrottledTaskRunner
slightly:The throttling behaviour is also useful for tasks which do not complete synchronously. The new
ThrottledTaskRunner
passes aReleasable
to each task, which until released will prevent spawning further tasks.The only part that needs the tasks to be
Comparable<>
is the queue. Letting the caller specify the queue means that we can also use the throttling without the prioritisation.