Skip to content

Commit 43982fe

Browse files
committed
feature: expose the packing_worker and replica_2_9_workers flags
1 parent 64415ac commit 43982fe

File tree

8 files changed

+38
-22
lines changed

8 files changed

+38
-22
lines changed

apps/arweave/include/ar_config.hrl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@
126126
-define(DEFAULT_REPLICA_2_9_WORKERS, 8).
127127
-endif.
128128

129+
%% The number of packing workers.
130+
-define(DEFAULT_PACKING_WORKERS, erlang:system_info(dirty_cpu_schedulers_online)).
131+
129132
%% @doc Startup options with default values.
130133
-record(config, {
131134
init = false,
@@ -195,7 +198,6 @@
195198
get_tx => ?MAX_PARALLEL_GET_TX_REQUESTS
196199
},
197200
disk_cache_size = ?DISK_CACHE_SIZE,
198-
packing_rate,
199201
max_nonce_limiter_validation_thread_count
200202
= ?DEFAULT_MAX_NONCE_LIMITER_VALIDATION_THREAD_COUNT,
201203
max_nonce_limiter_last_step_validation_thread_count
@@ -222,6 +224,7 @@
222224
pool_server_address = not_set,
223225
pool_api_key = not_set,
224226
pool_worker_name = not_set,
227+
packing_workers = ?DEFAULT_PACKING_WORKERS,
225228
replica_2_9_workers = ?DEFAULT_REPLICA_2_9_WORKERS,
226229
%% Undocumented/unsupported options
227230
chunk_storage_file_size = ?CHUNK_GROUP_SIZE,

apps/arweave/src/ar.erl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,16 @@ show_help() ->
266266
)
267267
)},
268268
{"packing_rate",
269-
"The maximum number of chunks per second to pack or unpack. "
270-
"The default value is determined based on the number of CPU cores."},
269+
"DEPRECATED. Does not affect anything. Use packing_workers instead."},
270+
{"packing_workers (num)",
271+
"The number of packing workers to spawn. The default is the number of "
272+
"logical CPU cores."},
273+
{"replica_2_9_workers (num)", io_lib:format(
274+
"The number of replica 2.9 workers to spawn. Replica 2.9 workers are used "
275+
"to generate entropy the replica.2.9 format. At most one worker will be "
276+
"active per physical disk at a time. Default: ~B",
277+
[?DEFAULT_REPLICA_2_9_WORKERS]
278+
)},
271279
{"max_vdf_validation_thread_count", io_lib:format("\tThe maximum number "
272280
"of threads used for VDF validation. Default: ~B",
273281
[?DEFAULT_MAX_NONCE_LIMITER_VALIDATION_THREAD_COUNT])},
@@ -565,8 +573,10 @@ parse_cli_args(["max_disk_pool_data_root_buffer_mb", Num | Rest], C) ->
565573
parse_cli_args(Rest, C#config{ max_disk_pool_data_root_buffer_mb = list_to_integer(Num) });
566574
parse_cli_args(["disk_cache_size_mb", Num | Rest], C) ->
567575
parse_cli_args(Rest, C#config{ disk_cache_size = list_to_integer(Num) });
568-
parse_cli_args(["packing_rate", Num | Rest], C) ->
569-
parse_cli_args(Rest, C#config{ packing_rate = list_to_integer(Num) });
576+
parse_cli_args(["packing_rate", _Num | Rest], C) ->
577+
?LOG_WARNING("Deprecated option found 'packing_rate': "
578+
" this option has been removed and is now a no-op.", []),
579+
parse_cli_args(Rest, C#config{ });
570580
parse_cli_args(["max_vdf_validation_thread_count", Num | Rest], C) ->
571581
parse_cli_args(Rest,
572582
C#config{ max_nonce_limiter_validation_thread_count = list_to_integer(Num) });
@@ -931,7 +941,6 @@ start_for_tests(TestType, Config) ->
931941
data_dir = ".tmp/data_" ++ atom_to_list(TestType) ++ "_main_" ++ UniqueName,
932942
port = ar_test_node:get_unused_port(),
933943
disable = [randomx_jit],
934-
packing_rate = 20,
935944
auto_join = false
936945
},
937946
start(TestConfig).

apps/arweave/src/ar_config.erl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,9 @@ parse_options([{<<"disk_cache_size_mb">>, D} | Rest], Config) when is_integer(D)
518518
parse_options(Rest, Config#config{ disk_cache_size = D });
519519

520520
parse_options([{<<"packing_rate">>, D} | Rest], Config) when is_integer(D) ->
521-
parse_options(Rest, Config#config{ packing_rate = D });
521+
?LOG_WARNING("Deprecated option found 'packing_rate': "
522+
" this option has been removed and is a no-op.", []),
523+
parse_options(Rest, Config);
522524

523525
parse_options([{<<"max_nonce_limiter_validation_thread_count">>, D} | Rest], Config)
524526
when is_integer(D) ->

apps/arweave/src/ar_device_lock.erl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
-record(state, {
1515
store_id_to_device = #{},
1616
device_locks = #{},
17-
initialized = false
17+
initialized = false,
18+
num_replica_2_9_workers = 0
1819
}).
1920

2021
-type device_mode() :: prepare | sync | repack.
@@ -83,7 +84,10 @@ start_link() ->
8384

8485
init([]) ->
8586
gen_server:cast(self(), initialize_state),
86-
{ok, #state{}}.
87+
{ok, Config} = application:get_env(arweave, config),
88+
?LOG_INFO([{event, starting_device_lock_server},
89+
{num_replica_2_9_workers, Config#config.replica_2_9_workers}]),
90+
{ok, #state{num_replica_2_9_workers = Config#config.replica_2_9_workers}}.
8791

8892
handle_call(get_state, _From, State) ->
8993
{reply, State, State};
@@ -170,10 +174,10 @@ get_system_device(StorageModule) ->
170174
end.
171175

172176
do_acquire_lock(Mode, StoreID, State) ->
177+
MaxPrepareLocks = State#state.num_replica_2_9_workers,
173178
Device = maps:get(StoreID, State#state.store_id_to_device),
174179
DeviceLock = maps:get(Device, State#state.device_locks, sync),
175180
PrepareLocks = count_prepare_locks(State),
176-
MaxPrepareLocks = 8,
177181
{Acquired, NewDeviceLock} = case Mode of
178182
sync ->
179183
%% Can only aquire a sync lock if the device is in sync mode

apps/arweave/src/ar_packing_server.erl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,12 @@ init([]) ->
273273
H1String = io_lib:format("~.3f", [H1 / 1000]),
274274
ar:console("Hashing benchmark~nH0: ~s ms~nH1/H2: ~s ms~n", [H0String, H1String]),
275275
?LOG_INFO([{event, hash_benchmark}, {h0_ms, H0String}, {h1_ms, H1String}]),
276-
Schedulers = erlang:system_info(dirty_cpu_schedulers_online),
277-
SpawnSchedulers = Schedulers,
278-
ar:console("~nStarting ~B packing threads.~n", [SpawnSchedulers]),
279-
?LOG_INFO([{event, starting_packing_threads}, {num_threads, SpawnSchedulers}]),
276+
NumWorkers = Config#config.packing_workers,
277+
ar:console("~nStarting ~B packing threads.~n", [NumWorkers]),
278+
?LOG_INFO([{event, starting_packing_threads}, {num_threads, NumWorkers}]),
280279
Workers = queue:from_list(
281-
[spawn_link(fun() -> worker(PackingState) end) || _ <- lists:seq(1, SpawnSchedulers)]),
280+
[spawn_link(fun() -> worker(PackingState) end) || _ <- lists:seq(1, NumWorkers)]),
282281
ets:insert(?MODULE, {buffer_size, 0}),
283-
{ok, Config} = application:get_env(arweave, config),
284282
MaxSize =
285283
case Config#config.packing_cache_size_limit of
286284
undefined ->
@@ -296,7 +294,7 @@ init([]) ->
296294
ets:insert(?MODULE, {buffer_size_limit, MaxSize}),
297295
timer:apply_interval(200, ?MODULE, record_buffer_size_metric, []),
298296
{ok, #state{
299-
workers = Workers, num_workers = SpawnSchedulers }}.
297+
workers = Workers, num_workers = NumWorkers }}.
300298

301299
handle_call(Request, _From, State) ->
302300
?LOG_WARNING([{event, unhandled_call}, {module, ?MODULE}, {request, Request}]),

apps/arweave/test/ar_config_tests.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ test_parse_config() ->
6969
tx_validators = 3,
7070
post_tx_timeout = 50,
7171
max_emitters = 4,
72+
replica_2_9_workers = 16,
73+
packing_workers = 25,
7274
tx_propagation_parallelization = undefined,
7375
sync_jobs = 10,
7476
header_sync_jobs = 1,
@@ -117,7 +119,6 @@ test_parse_config() ->
117119
gateway_arql := 3,
118120
get_sync_record := 10
119121
},
120-
packing_rate = 20,
121122
max_nonce_limiter_validation_thread_count = 2,
122123
max_nonce_limiter_last_step_validation_thread_count = 3,
123124
nonce_limiter_server_trusted_peers = ["127.0.0.1", "2.3.4.5", "6.7.8.9:1982"],

apps/arweave/test/ar_config_tests_config_fixture.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@
100100
"gateway_arql": 3
101101
},
102102
"packing_rate": 20,
103+
"replica_2_9_workers": 16,
104+
"packing_workers": 25,
103105
"max_nonce_limiter_validation_thread_count": 2,
104106
"max_nonce_limiter_last_step_validation_thread_count": 3,
105107
"vdf_server_trusted_peer": "127.0.0.1",

apps/arweave/test/ar_test_node.erl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ try_boot_peer(TestType, Node, Retries) ->
139139
Cmd = io_lib:format(
140140
"erl +S ~B:~B -pa ~s -config config/sys.config -noshell " ++
141141
"-name ~s -setcookie ~s -run ar main debug port ~p " ++
142-
"data_dir .tmp/data_~s_~s no_auto_join packing_rate 20 " ++
142+
"data_dir .tmp/data_~s_~s no_auto_join " ++
143143
"> ~s-~s.out 2>&1 &",
144144
[Schedulers, Schedulers, string:join(Paths, " "), NodeName, Cookie, Port,
145145
atom_to_list(TestType), NodeName, Node, get_node_namespace()]),
@@ -226,7 +226,6 @@ update_config(Config) ->
226226
auto_join = Config#config.auto_join,
227227
mining_addr = Config#config.mining_addr,
228228
sync_jobs = Config#config.sync_jobs,
229-
packing_rate = Config#config.packing_rate,
230229
disk_pool_jobs = Config#config.disk_pool_jobs,
231230
header_sync_jobs = Config#config.header_sync_jobs,
232231
enable = Config#config.enable ++ BaseConfig#config.enable,
@@ -322,7 +321,6 @@ base_cm_config(Peers) ->
322321
auto_join = true,
323322
mining_addr = RewardAddr,
324323
sync_jobs = 2,
325-
packing_rate = 20,
326324
disk_pool_jobs = 2,
327325
header_sync_jobs = 2,
328326
enable = [search_in_rocksdb_when_mining, serve_tx_data_without_limits,
@@ -598,7 +596,6 @@ start(B0, RewardAddr, Config, StorageModules) ->
598596
storage_modules = StorageModules,
599597
disk_space_check_frequency = 1000,
600598
sync_jobs = 2,
601-
packing_rate = 20,
602599
disk_pool_jobs = 2,
603600
header_sync_jobs = 2,
604601
enable = [search_in_rocksdb_when_mining, serve_tx_data_without_limits,

0 commit comments

Comments
 (0)