Align cache with default

Stop L0 from growing too large i.e. 127 * 4K is more than 10 times bigger than the default.
This commit is contained in:
Martin Sumner 2019-02-25 23:35:12 +00:00
parent aea20de4b9
commit fd2e0e870c
3 changed files with 12 additions and 18 deletions

View file

@ -21,7 +21,7 @@
%% @doc The key size of the Bookie's in-memory cache %% @doc The key size of the Bookie's in-memory cache
{mapping, "leveled.cache_size", "leveled.cache_size", [ {mapping, "leveled.cache_size", "leveled.cache_size", [
{default, 4000}, {default, 2500},
{datatype, integer}, {datatype, integer},
hidden hidden
]}. ]}.

View file

@ -2187,21 +2187,13 @@ maybepush_ledgercache(MaxCacheSize, Cache, Penciller) ->
-spec maybe_withjitter(integer(), integer()) -> boolean(). -spec maybe_withjitter(integer(), integer()) -> boolean().
%% @doc %% @doc
%% Push down randomly, but the closer to the maximum size, the more likely a %% Push down randomly, but the closer to 4 * the maximum size, the more likely
%% push should be %% a push should be
maybe_withjitter(CacheSize, MaxCacheSize) -> maybe_withjitter(CacheSize, MaxCacheSize) when CacheSize > MaxCacheSize ->
if R = leveled_rand:uniform(4 * MaxCacheSize),
CacheSize > MaxCacheSize -> (CacheSize - MaxCacheSize) > R;
R = leveled_rand:uniform(7 * MaxCacheSize), maybe_withjitter(_CacheSize, _MaxCacheSize) ->
if false.
(CacheSize - MaxCacheSize) > R ->
true;
true ->
false
end;
true ->
false
end.
-spec get_loadfun(book_state()) -> fun(). -spec get_loadfun(book_state()) -> fun().

View file

@ -44,6 +44,8 @@
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
-define(MAX_CACHE_LINES, 31). % Must be less than 128
% -type index_array() :: array:array(). % -type index_array() :: array:array().
-type index_array() :: any()|none. % To live with OTP16 -type index_array() :: any()|none. % To live with OTP16
@ -55,9 +57,9 @@
-spec cache_full(list()) -> boolean(). -spec cache_full(list()) -> boolean().
%% @doc %% @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) -> cache_full(L0Cache) ->
length(L0Cache) == 127. length(L0Cache) == ?MAX_CACHE_LINES.
-spec prepare_for_index(index_array(), leveled_codec:segment_hash()) -spec prepare_for_index(index_array(), leveled_codec:segment_hash())
-> index_array(). -> index_array().