Skip to content
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

Merged

Conversation

DaveCTurner
Copy link
Contributor

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.

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.
@DaveCTurner DaveCTurner added :Distributed Indexing/Distributed A catch all label for anything in the Distributed Area. Please avoid if you can. >refactoring v8.7.0 labels Feb 2, 2023
@elasticsearchmachine elasticsearchmachine added the Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. label Feb 2, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

@DaveCTurner
Copy link
Contributor Author

I particularly would like to use this generalisation in #92373, although I think we will find other uses too.

Copy link
Member

@pxsalehi pxsalehi left a 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?

Comment on lines -260 to -251
private static void awaitBarrier(CyclicBarrier barrier) {
try {
barrier.await(10, TimeUnit.SECONDS);
} catch (Exception e) {
throw new AssertionError("unexpected", e);
}
}
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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)

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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);
Copy link
Member

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?

Copy link
Contributor Author

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>> {
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will be using it in #92373 which is already quite a big change so I'd like to have prerequisites like this reviewed separately. It also came up in a discussion about search execution so I wanted to have the code somewhere visible. I'm happy to delay merging it until #92373 is closer to ready tho.

@pxsalehi pxsalehi self-requested a review February 2, 2023 10:19
@DaveCTurner DaveCTurner merged commit e837ff7 into elastic:main Feb 6, 2023
@DaveCTurner DaveCTurner deleted the 2023-02-02-ThrottledTaskRunner branch February 6, 2023 09:53
@pxsalehi
Copy link
Member

pxsalehi commented Feb 6, 2023

Does this also need to change like #93446?

@DaveCTurner There were two EsExecutors.newScaling executors here in the test which do not seem to have the fix that you had in #93446. Is it not needed here to prevent flaky tests?

DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Feb 6, 2023
@DaveCTurner
Copy link
Contributor Author

Ah sorry you're right, I forgot about this new test suite. I opened #93505.

elasticsearchmachine pushed a commit that referenced this pull request Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Indexing/Distributed A catch all label for anything in the Distributed Area. Please avoid if you can. >refactoring Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. v8.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants