-
Notifications
You must be signed in to change notification settings - Fork 1.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
Fix query timeout handling by checking searchContext.isSearchTimedOut() #16882
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@jed326 @sohami @kkewwei it seems like when we were adapting to concurrent search, the exception driven flow was changed to state driven one, and the leaves are being processed even when the search request has exceeded the time budget (timed out).
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 @reta, I will have more time to take a closer look at this later this week.
From what I recall off the top of my head the
cancellable.checkCancelled();
right below this should already be doing the timeout checking and then throwing theQueryPhase.TimeExceededException
. ThesearchContext.setSearchTimedOut(true);
logic was needed because with concurrent search any exceptions thrown insearchLeaf
would be handled by the LuceneTaskExecutor
and it was difficult to figure out from the query phase thread if the search had actually timed out or not.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 @jed326 , I will look closely as well, but
cancellable.checkCancelled()
seems to be somehow not short-circuiting the search, I could clearly see that by checking how long tests are taking w/o this change.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.
That's definitely strange. I do see that
searchLeaf
gets called for each leaf even post the timeout and we leave it tocancellable.checkCancelled()
to throw an exception which we than catch for each leaf. I wonder if this repeated exception handling is what is causing it to take longer?Maybe we should even have the
searchContext.isSearchTimedOut()
check in thesearch
method above so we can short circuit those for loops when the timeout is hit?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.
What I've seen, the timeout is hit by first
searchLeaf
call (those are called in loop), so the check insearch
method may not need this check (I think)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.
@reta, In the next code:
cancellable.checkCancelled()
(line 316) will do the timeout check, it looks like duplicate work.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.
Currently the only reason I can think why this would be the case is because
cancellable.checkCancelled()
involves throwing and catching an exception which is slowing things down. I think we may need to run this piece of code through a profiler to understand 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.
@jed326 @kkewwei thanks for the feedback folks, will spend more time looking into the cause