Skip to content

Commit

Permalink
Allow configuration of heap and vheap sizes
Browse files Browse the repository at this point in the history
for WAL and servers
  • Loading branch information
kjnilsson committed May 23, 2024
1 parent 6b48b15 commit eaabaab
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/ra.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
-define(WAL_DEFAULT_MAX_SIZE_BYTES, 256 * 1000 * 1000).
-define(WAL_DEFAULT_MAX_BATCH_SIZE, 8192).
-define(MIN_BIN_VHEAP_SIZE, 46422).
-define(MIN_HEAP_SIZE, 233).
%% define a minimum allowable wal size. If anyone tries to set a really small
%% size that is smaller than the logical block size the pre-allocation code may
%% fail
Expand Down
2 changes: 2 additions & 0 deletions src/ra_log_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ make_wal_conf(#{data_dir := DataDir,
PreAlloc = maps:get(wal_pre_allocate, Cfg, false),
MinBinVheapSize = maps:get(wal_min_bin_vheap_size, Cfg,
?MIN_BIN_VHEAP_SIZE),
MinHeapSize = maps:get(wal_min_heap_size, Cfg, ?MIN_HEAP_SIZE),
CompressMemTables = maps:get(compress_mem_tables, Cfg, false),
#{name => WalName,
names => Names,
Expand All @@ -86,6 +87,7 @@ make_wal_conf(#{data_dir := DataDir,
hibernate_after => HibAfter,
garbage_collect => Gc,
pre_allocate => PreAlloc,
min_heap_size => MinHeapSize,
min_bin_vheap_size => MinBinVheapSize,
compress_mem_tables => CompressMemTables
}.
4 changes: 4 additions & 0 deletions src/ra_log_wal.erl
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
hibernate_after => non_neg_integer(),
max_batch_size => non_neg_integer(),
garbage_collect => boolean(),
min_heap_size => non_neg_integer(),
min_bin_vheap_size => non_neg_integer(),
compress_mem_tables => boolean()
}.
Expand Down Expand Up @@ -242,6 +243,7 @@ init(#{dir := Dir} = Conf0) ->
write_strategy := WriteStrategy,
sync_method := SyncMethod,
garbage_collect := Gc,
min_heap_size := MinHeapSize,
min_bin_vheap_size := MinBinVheapSize,
compress_mem_tables := CompressMemTables,
names := #{wal := WalName,
Expand All @@ -256,6 +258,7 @@ init(#{dir := Dir} = Conf0) ->
% writers
process_flag(message_queue_data, off_heap),
process_flag(min_bin_vheap_size, MinBinVheapSize),
process_flag(min_heap_size, MinHeapSize),
CRef = ra_counters:new(WalName, ?COUNTER_FIELDS),
% wait for the segment writer to process anything in flight
ok = ra_log_segment_writer:await(SegWriter),
Expand Down Expand Up @@ -971,6 +974,7 @@ merge_conf_defaults(Conf) ->
garbage_collect => false,
sync_method => datasync,
min_bin_vheap_size => ?MIN_BIN_VHEAP_SIZE,
min_heap_size => ?MIN_HEAP_SIZE,
compress_mem_tables => false}, Conf).

to_binary(Term) ->
Expand Down
5 changes: 4 additions & 1 deletion src/ra_server_proc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,12 @@ do_init(#{id := Id,
system_config := SysConf} = maps:merge(config_defaults(Id),
Config0),
MsgQData = maps:get(message_queue_data, SysConf, off_heap),
MinBinVheapSize = maps:get(server_min_bin_vheap_size, SysConf, ?MIN_BIN_VHEAP_SIZE),
MinBinVheapSize = maps:get(server_min_bin_vheap_size, SysConf,
?MIN_BIN_VHEAP_SIZE),
MinHeapSize = maps:get(server_min_heap_size, SysConf, ?MIN_BIN_VHEAP_SIZE),
process_flag(message_queue_data, MsgQData),
process_flag(min_bin_vheap_size, MinBinVheapSize),
process_flag(min_heap_size, MinHeapSize),
#{cluster := Cluster} = ServerState = ra_server:init(Config),
LogId = ra_server:log_id(ServerState),
UId = ra_server:uid(ServerState),
Expand Down
6 changes: 6 additions & 0 deletions src/ra_system.erl
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@
default_max_pipeline_count => non_neg_integer(),
default_max_append_entries_rpc_batch_size => non_neg_integer(),
message_queue_data => on_heap | off_heap,
wal_min_heap_size => non_neg_integer(),
wal_min_bin_vheap_size => non_neg_integer(),
server_min_bin_vheap_size => non_neg_integer(),
server_min_heap_size => non_neg_integer(),
compress_mem_tables => boolean(),
low_priority_commands_flush_size => non_neg_integer(),
low_priority_commands_in_memory_size => non_neg_integer(),
Expand Down Expand Up @@ -97,6 +99,8 @@ default_config() ->
WalPreAllocate = application:get_env(ra, wal_pre_allocate, false),
WalMinBinVheapSize = application:get_env(ra, wal_min_bin_vheap_size,
?MIN_BIN_VHEAP_SIZE),
WalMinHeapSize = application:get_env(ra, wal_min_heap_size, ?MIN_HEAP_SIZE),
ServerMinHeapSize = application:get_env(ra, server_min_heap_size, ?MIN_HEAP_SIZE),
ServerMinBinVheapSize = application:get_env(ra, server_min_bin_vheap_size,
?MIN_BIN_VHEAP_SIZE),
DefaultMaxPipelineCount = application:get_env(ra, default_max_pipeline_count,
Expand Down Expand Up @@ -124,6 +128,7 @@ default_config() ->
wal_garbage_collect => WalGarbageCollect,
wal_pre_allocate => WalPreAllocate,
wal_sync_method => WalSyncMethod,
wal_min_heap_size => WalMinHeapSize,
wal_min_bin_vheap_size => WalMinBinVheapSize,
segment_max_entries => SegmentMaxEntries,
segment_max_pending => SegmentMaxPending,
Expand All @@ -134,6 +139,7 @@ default_config() ->
compress_mem_tables => CompressMemTables,
snapshot_chunk_size => SnapshotChunkSize,
server_min_bin_vheap_size => ServerMinBinVheapSize,
server_min_heap_size => ServerMinHeapSize,
receive_snapshot_timeout => ReceiveSnapshotTimeout,
low_priority_commands_flush_size => LowPriorityCommandsFlushSize,
low_priority_commands_in_memory_size => LowPriorityInMemSize,
Expand Down

0 comments on commit eaabaab

Please sign in to comment.