Skip to content

Commit

Permalink
GH-2799 add a hard ceiling (32MB) of free memory required before over…
Browse files Browse the repository at this point in the history
…flowing, regardless of block size

Signed-off-by: Håvard Ottestad <[email protected]>
  • Loading branch information
hmottestad committed Apr 23, 2021
1 parent e7cd926 commit 508e9ee
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ abstract class MemoryOverflowModel extends AbstractModel {

private static final int LARGE_BLOCK = 10000;

// To reduce the chance of OOM we will always overflow once we get close to running out of memory even if we think
// we have space for one more block. The limit is currently set at 32 MB
private static final int MIN_AVAILABLE_MEM_BEFORE_OVERFLOWING = 32 * 1024 * 1024;

final Logger logger = LoggerFactory.getLogger(MemoryOverflowModel.class);

private LinkedHashModel memory;
Expand Down Expand Up @@ -243,9 +247,11 @@ private synchronized void checkMemoryOverflow() {
if (blockSize > maxBlockSize) {
maxBlockSize = blockSize;
}

// Sync if either the estimated size of the next block is larger than remaining memory, or
// if less than 15% of the heap is still free (this last condition to avoid GC overhead limit)
if (freeToAllocateMemory < Math.min(0.15 * maxMemory, maxBlockSize)) {
if (freeToAllocateMemory < MIN_AVAILABLE_MEM_BEFORE_OVERFLOWING ||
freeToAllocateMemory < Math.min(0.15 * maxMemory, maxBlockSize)) {
logger.debug("syncing at {} triples. max block size: {}", size, maxBlockSize);
overflowToDisk();
}
Expand Down

0 comments on commit 508e9ee

Please sign in to comment.