From fd2e0e870ca16f9b6d41acc4adac0c2a3e8beb16 Mon Sep 17 00:00:00 2001 From: Martin Sumner Date: Mon, 25 Feb 2019 23:35:12 +0000 Subject: [PATCH] Align cache with default Stop L0 from growing too large i.e. 127 * 4K is more than 10 times bigger than the default. --- priv/leveled.schema | 2 +- src/leveled_bookie.erl | 22 +++++++--------------- src/leveled_pmem.erl | 6 ++++-- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/priv/leveled.schema b/priv/leveled.schema index 4498573..241ee33 100644 --- a/priv/leveled.schema +++ b/priv/leveled.schema @@ -21,7 +21,7 @@ %% @doc The key size of the Bookie's in-memory cache {mapping, "leveled.cache_size", "leveled.cache_size", [ - {default, 4000}, + {default, 2500}, {datatype, integer}, hidden ]}. diff --git a/src/leveled_bookie.erl b/src/leveled_bookie.erl index d7e5d4a..5b57e19 100644 --- a/src/leveled_bookie.erl +++ b/src/leveled_bookie.erl @@ -2187,21 +2187,13 @@ maybepush_ledgercache(MaxCacheSize, Cache, Penciller) -> -spec maybe_withjitter(integer(), integer()) -> boolean(). %% @doc -%% Push down randomly, but the closer to the maximum size, the more likely a -%% push should be -maybe_withjitter(CacheSize, MaxCacheSize) -> - if - CacheSize > MaxCacheSize -> - R = leveled_rand:uniform(7 * MaxCacheSize), - if - (CacheSize - MaxCacheSize) > R -> - true; - true -> - false - end; - true -> - false - end. +%% Push down randomly, but the closer to 4 * the maximum size, the more likely +%% a push should be +maybe_withjitter(CacheSize, MaxCacheSize) when CacheSize > MaxCacheSize -> + R = leveled_rand:uniform(4 * MaxCacheSize), + (CacheSize - MaxCacheSize) > R; +maybe_withjitter(_CacheSize, _MaxCacheSize) -> + false. -spec get_loadfun(book_state()) -> fun(). diff --git a/src/leveled_pmem.erl b/src/leveled_pmem.erl index e2de638..17b9277 100644 --- a/src/leveled_pmem.erl +++ b/src/leveled_pmem.erl @@ -44,6 +44,8 @@ -include_lib("eunit/include/eunit.hrl"). +-define(MAX_CACHE_LINES, 31). % Must be less than 128 + % -type index_array() :: array:array(). -type index_array() :: any()|none. % To live with OTP16 @@ -55,9 +57,9 @@ -spec cache_full(list()) -> boolean(). %% @doc -%% If there are already 127 entries in the cache then the cache is full +%% If there are already 31 entries in the cache then the cache is full cache_full(L0Cache) -> - length(L0Cache) == 127. + length(L0Cache) == ?MAX_CACHE_LINES. -spec prepare_for_index(index_array(), leveled_codec:segment_hash()) -> index_array().