-
Notifications
You must be signed in to change notification settings - Fork 982
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
Make LRUQueryCache respect Accountable queries on eviction and consisten… #12614
Conversation
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 for finding and fixing this bug! I left one small request for change but looks good to me otherwise.
@@ -385,7 +385,9 @@ public void clearQuery(Query query) { | |||
|
|||
private void onEviction(Query singleton) { | |||
assert lock.isHeldByCurrentThread(); | |||
onQueryEviction(singleton, LINKED_HASHTABLE_RAM_BYTES_PER_ENTRY + QUERY_DEFAULT_RAM_BYTES_USED); | |||
var ramBytesUsedByQuery = LINKED_HASHTABLE_RAM_BYTES_PER_ENTRY; | |||
ramBytesUsedByQuery += singleton instanceof Accountable accountableQuery ? accountableQuery.ramBytesUsed() : QUERY_DEFAULT_RAM_BYTES_USED; |
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.
Can we pull this out into a separate queryRamBytesUsed(Query q)
method, given that it's used twice?
Can you run |
987d564
to
9b96da8
Compare
Thanks for reviewing! I ran tidy and made some refactoring |
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.
Looks great, thank you! One more request: can you add an entry to lucene/CHANGES.txt
in the 'Bug Fixes' section for Lucene 9.9.0?
9b96da8
to
ec6c3fd
Compare
…tency check (#12614) Given a query that implements Accountable, the LRUQueryCache would increment its internal accounting by the amount reported by Accountable.ramBytesUsed(), but only decrement on eviction by the default used for all other queries. This meant that the cache could eventually think it had run out of space, even if there were no queries in it at all. This commit ensures that queries that implement Accountable are always accounted for correctly.
…tency check (apache#12614) Given a query that implements Accountable, the LRUQueryCache would increment its internal accounting by the amount reported by Accountable.ramBytesUsed(), but only decrement on eviction by the default used for all other queries. This meant that the cache could eventually think it had run out of space, even if there were no queries in it at all. This commit ensures that queries that implement Accountable are always accounted for correctly.
I am also facing the same issue after the upgrade of elastic to 8.10 from 8.7. |
@gtroitskiy @romseygeek |
…cy check
Root cause
onQueryCache
increasesramBytesUsed
for specified amount, that is being calculated with respect to query beingAccountable
or not.Unfortunately,
onQueryEviction
does not the same. If some heavy accountable query hasramBytesUsed()
greater thanQUERY_DEFAULT_RAM_BYTES_USED
, the deltaghostBytes = ramBytesUsed() - QUERY_DEFAULT_RAM_BYTES_USED
remains in totalLRUQueryCache#ramBytesUsed
forever.Hit rate drops to 0
since total sum of ghost bytes monotonously increases with each cached accountable query (>QUERY_DEFAULT_RAM_BYTES_USED), eventually it becomes greater than
maxRamBytesUsed
, and each newly cached query immediately evicts from the cache.Current behavior of LRUQueryCache for some real service in production [though not fully optimized]
maxRamBytesUsed
. Started eviction. From now on size of cached queries decreases to compensate increasing ghost bytes.maxRamBytesUsed
. If any new query was cached, it evicted at the same time. Cache size is 0. Hit rate is 0.After fix
![image](https://private-user-images.githubusercontent.com/1190066/272130269-03aa65f1-f07b-412e-b52d-11fc9db55bde.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA3MTQxNTQsIm5iZiI6MTcyMDcxMzg1NCwicGF0aCI6Ii8xMTkwMDY2LzI3MjEzMDI2OS0wM2FhNjVmMS1mMDdiLTQxMmUtYjUyZC0xMWZjOWRiNTViZGUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcxMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MTFUMTYwNDE0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MGMzNWJhNTg1ZGRmN2VmMTlkMjI4YmZiMDNmYjVjNGM0Njk2YjQyZjBlMTk2ZmVhOTgyZjIwYWNmMGY1YjNiNiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.fAjH_S_wDJ4csipyQG7d49Bx0jOM9QbovR9tL3LR2Zg)