Commit 68c24d5
authored
fix(cache): make updating the max cost of posting cache work again (#9526)
Updating the max cost of the posting list cache is not wired up. It just
calls an empty function. This PR adds a method to `MemoryLayer`, that
allows updating the max cost of its cache. The old function is deleted
and the function call is replaced with a call to the new method.
Updating the MaxCost is critical because it is the mechanism that actually enforces the memory limit in the underlying cache (Ristretto). Without this PR, changing the cacheMB setting was effectively a "placebo"—the number changed in the configuration, but the cache's behavior remained exactly the same.
Implications:
1. "Cost" equals "Memory Usage"
In Dgraph's usage of Ristretto (the cache library), the "cost" of an item is calculated to represent its approximate memory size in bytes. Therefore, MaxCost is the memory capacity of the cache.
Before the fix: The UpdateMaxCost function was empty. If you changed cacheMB from 1GB to 8GB via the API, the configuration variable updated, but the cache's internal capacity (MaxCost) stayed at 1GB.
After the fix: The new cacheMB value is converted to bytes and passed to ml.cache.data.UpdateMaxCost(), instantly resizing the cache's capacity.
2. Runtime Memory Management (No Restarts)
This feature allows operators to tune memory usage dynamically without downtime. This is vital for two main scenarios:
Relieving Memory Pressure (Scaling Down): If a Dgraph Alpha is running close to its memory limit and risking an OOM (Out of Memory) crash, an operator can lower cacheMB.
Without this fix: The cache would ignore the reduction and keep holding onto memory, potentially leading to a crash.
With this fix: The cache immediately evicts items to drop its usage below the new limit, stabilizing the server.
Improving Performance (Scaling Up): If a server has spare RAM and query latency is high due to cache misses, an operator can increase cacheMB.
Without this fix: The cache would not grow to use the extra memory, and performance would not improve.
With this fix: The cache expands, storing more posting lists and improving query speeds.1 parent 8c2875f commit 68c24d5
3 files changed
+10
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | 49 | | |
53 | 50 | | |
54 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
405 | 405 | | |
406 | 406 | | |
407 | 407 | | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
408 | 415 | | |
409 | 416 | | |
410 | 417 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
153 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
154 | 156 | | |
155 | 157 | | |
156 | 158 | | |
| |||
0 commit comments