-
Notifications
You must be signed in to change notification settings - Fork 24.7k
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
EQL: Add CircuitBreaker for sequence queries #74381
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ae1dc91
EQL: Add Circuit Breaker for sequence queries
matriv d1ea4fe
Use batch ram accouning for sequence matcher
matriv 3ba5da5
clean up ram accounting
matriv 3f994ca
Call to CB in batches
matriv cbcd6db
Remove accounting for temp objects
matriv 2b9904e
Fix imports
matriv ba3117d
Merge remote-tracking branch 'upstream/master' into cb-eql
matriv c412097
Add comments, remove cb calls for trim()
matriv 309c59f
Add unit test
matriv 6485744
remove limit and stats from counting
matriv b7a5404
Address review pt1
matriv 367c42d
move the ram accounting in SequnceMatcher
matriv 118e13f
Merge remote-tracking branch 'upstream/master' into cb-eql
matriv 3c4469c
address review
matriv 700bc97
fix test
matriv 168f745
Merge remote-tracking branch 'upstream/master' into cb-eql
matriv b246745
Add low level unit test
matriv d149f65
address comments
matriv 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
|
||
package org.elasticsearch.xpack.eql.execution.sequence; | ||
|
||
import org.apache.lucene.util.Accountable; | ||
import org.apache.lucene.util.RamUsageEstimator; | ||
import org.elasticsearch.common.logging.LoggerMessageFormat; | ||
import org.elasticsearch.xpack.eql.execution.search.Ordinal; | ||
|
||
|
@@ -18,13 +20,15 @@ | |
* Dedicated collection for mapping a key to a list of sequences | ||
* The list represents the sequence for each stage (based on its index) and is fixed in size | ||
*/ | ||
class KeyToSequences { | ||
class KeyToSequences implements Accountable { | ||
|
||
/** | ||
* Utility class holding the sequencegroup/until tuple that also handles | ||
* lazy initialization. | ||
*/ | ||
private class SequenceEntry { | ||
private static class SequenceEntry implements Accountable { | ||
|
||
private static final long SHALLOW_SIZE = RamUsageEstimator.shallowSizeOfInstance(SequenceEntry.class); | ||
|
||
private final SequenceGroup[] groups; | ||
// created lazily | ||
|
@@ -52,6 +56,16 @@ void until(Ordinal ordinal) { | |
} | ||
until.add(ordinal); | ||
} | ||
|
||
@Override | ||
public long ramBytesUsed() { | ||
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. Since the ram used is computed in a batch, there's no point in keeping track per remote/until/add method. It's either incremental or a batch - currently it's a mix. |
||
long size = SHALLOW_SIZE; | ||
if (until != null) { | ||
size += until.ramBytesUsed(); | ||
} | ||
size += RamUsageEstimator.sizeOf(groups); | ||
return size; | ||
} | ||
} | ||
|
||
private final int listSize; | ||
|
@@ -133,6 +147,11 @@ public void clear() { | |
keyToSequences.clear(); | ||
} | ||
|
||
@Override | ||
public long ramBytesUsed() { | ||
return RamUsageEstimator.sizeOfMap(keyToSequences); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return LoggerMessageFormat.format(null, "Keys=[{}]", keyToSequences.size()); | ||
|
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
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.
Same as above - since the fields are final and this method is going to be called multiple times it's worth considering caching the long (and thus increasing its memory size) to save on virtual calls.
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 already cached, as it's computed once and saved in a static variable.
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.
The method is incorrect - the timestamp and implicitTiebreaker need to be accounted (the tiebreaker comparable is only a reference so shallow).
Either these are accounted for or there's no point in tracking Ordinal at all.
It would be useful to see the impact the accounting takes on the call tree though some basic profiling.
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.
Those are accounted with the
RamUsageEstimator.shallowSizeOfInstance(Ordinal.class)
, all 3 fields, and the tiebreaker just as an object Reference.