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

Limit and monitor warmup memory usage #5568

Merged
merged 21 commits into from
Dec 12, 2024
Merged

Limit and monitor warmup memory usage #5568

merged 21 commits into from
Dec 12, 2024

Conversation

rdettai
Copy link
Contributor

@rdettai rdettai commented Nov 28, 2024

Description

To better control the memory usage during search, we add some tooling around the warmup cache.

How was this PR tested?

Describe how you tested this PR.

TODO

  • validate initial allocation rules
  • docs hide this feature for now

@rdettai rdettai requested a review from fulmicoton November 28, 2024 16:16
@rdettai rdettai force-pushed the memory_log branch 3 times, most recently from 0f7bd50 to c9f34df Compare December 3, 2024 15:47
@rdettai rdettai self-assigned this Dec 11, 2024
fulmicoton and others added 10 commits December 12, 2024 15:16
Due to tantivy limitations, searching a split requires downloading all
of the required data, and keep them in memory. We call this phase
warmup.

Before this PR, the only thing that curbed memory usage was the search
permits: only N split search may happen concurrently.
Unfortunately, the amount of data required here varies vastly.

We need a mechanism to measure and avoid running more split search
when memory is tight.

Just using a semaphore is however not an option. We do not know
beforehands how much memory will be required by a split search, so it could easily
lead to a dead lock.

Instead, this commit builds upon the search permit provider.

The search permit provider is in charge of managing a configurable memory budget for this warmup memory.

We introduce here a configurable "warmup_single_split_initial_allocation".
A new leaf split search cannot be started if this memory is not
available. This initial allocation is meant to be greater than what will
be actually needed most of the time.

The split search then holds this allocation until the end of warmup.
After warmup, we can get the actual memory usage by interrogating the
warmup cache. We can then update the amount of memory held.
(most of the time, this should mean releasing some memory)

In addition, in this PR, at this point, we also release the warmup search permit:

We still have to perform the actual task of searching, but the thread
pool will take care of limiting the number of concurrent task.

Closes #5355
Also attach the permit to the actual memory cache to ensure memory is freed at the right moment.
Adding an extra generic field into the cache to optionally allow permit tracking is weird.
Instead, we make the directory generic on the type of cache and use a wrapped cache
when tracking is necessary.
@rdettai rdettai merged commit 3ec6a07 into main Dec 12, 2024
4 of 5 checks passed
@rdettai rdettai deleted the memory_log branch December 12, 2024 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants