Skip to content

Commit 1726064

Browse files
Merge pull request #12208 from rabbitmq/qq-otp27-conf
Adjust vheap sizes for message handling processes in OTP 27
2 parents fdc6bd1 + 6a7f8d0 commit 1726064

File tree

7 files changed

+51
-2
lines changed

7 files changed

+51
-2
lines changed

deps/rabbit/app.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ def all_beam_files(name = "all_beam_files"):
194194
"src/rabbit_prelaunch_logging.erl",
195195
"src/rabbit_priority_queue.erl",
196196
"src/rabbit_process.erl",
197+
"src/rabbit_process_flag.erl",
197198
"src/rabbit_queue_consumers.erl",
198199
"src/rabbit_queue_decorator.erl",
199200
"src/rabbit_queue_index.erl",
@@ -452,6 +453,7 @@ def all_test_beam_files(name = "all_test_beam_files"):
452453
"src/rabbit_prelaunch_logging.erl",
453454
"src/rabbit_priority_queue.erl",
454455
"src/rabbit_process.erl",
456+
"src/rabbit_process_flag.erl",
455457
"src/rabbit_queue_consumers.erl",
456458
"src/rabbit_queue_decorator.erl",
457459
"src/rabbit_queue_index.erl",
@@ -733,6 +735,7 @@ def all_srcs(name = "all_srcs"):
733735
"src/rabbit_prelaunch_logging.erl",
734736
"src/rabbit_priority_queue.erl",
735737
"src/rabbit_process.erl",
738+
"src/rabbit_process_flag.erl",
736739
"src/rabbit_queue_consumers.erl",
737740
"src/rabbit_queue_decorator.erl",
738741
"src/rabbit_queue_index.erl",

deps/rabbit/src/rabbit_amqp_session.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ init({ReaderPid, WriterPid, ChannelNum, MaxFrameSize, User, Vhost, ConnName,
391391
outgoing_window = ?UINT(RemoteOutgoingWindow),
392392
handle_max = ClientHandleMax}}) ->
393393
process_flag(trap_exit, true),
394-
process_flag(message_queue_data, off_heap),
394+
rabbit_process_flag:adjust_for_message_handling_proc(),
395395

396396
ok = pg:join(pg_scope(), self(), self()),
397397
Alarms0 = rabbit_alarm:register(self(), {?MODULE, conserve_resources, []}),

deps/rabbit/src/rabbit_channel.erl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,8 @@ update_user_state(Pid, UserState) when is_pid(Pid) ->
484484
init([Channel, ReaderPid, WriterPid, ConnPid, ConnName, Protocol, User, VHost,
485485
Capabilities, CollectorPid, LimiterPid, AmqpParams]) ->
486486
process_flag(trap_exit, true),
487+
rabbit_process_flag:adjust_for_message_handling_proc(),
488+
487489
?LG_PROCESS_TYPE(channel),
488490
?store_proc_name({ConnName, Channel}),
489491
ok = pg_local:join(rabbit_channels, self()),
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
%% This Source Code Form is subject to the terms of the Mozilla Public
2+
%% License, v. 2.0. If a copy of the MPL was not distributed with this
3+
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
%%
5+
%% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
6+
%%
7+
8+
-module(rabbit_process_flag).
9+
10+
11+
-export([adjust_for_message_handling_proc/0
12+
]).
13+
14+
%% Adjust process flags for processes that handle RabbitMQ messages.
15+
%% For example any process that uses the `rabbit_queue_type' module
16+
%% may benefit from this tuning.
17+
%% @returns `ok'
18+
-spec adjust_for_message_handling_proc() -> ok.
19+
adjust_for_message_handling_proc() ->
20+
process_flag(message_queue_data, off_heap),
21+
case code_version:get_otp_version() of
22+
OtpMaj when OtpMaj >= 27 ->
23+
%% 46422 is the default min_bin_vheap_size and for OTP 27 and above
24+
%% we want to substantially increase it for processes that may buffer
25+
%% messages. 32x has proven workable in testing whilst not being
26+
%% ridiculously large
27+
process_flag(min_bin_vheap_size, 46422 * 32),
28+
ok;
29+
_ ->
30+
ok
31+
end.

deps/rabbit/src/rabbit_ra_systems.erl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
-define(COORD_WAL_MAX_SIZE_B, 64_000_000).
2525
-define(QUORUM_AER_MAX_RPC_SIZE, 16).
2626
-define(QUORUM_DEFAULT_WAL_MAX_ENTRIES, 500_000).
27+
%% the default min bin vheap value in OTP 26
28+
-define(MIN_BIN_VHEAP_SIZE_DEFAULT, 46422).
29+
-define(MIN_BIN_VHEAP_SIZE_MULT, 64).
2730

2831
-spec setup() -> ok | no_return().
2932

@@ -107,7 +110,6 @@ ensure_ra_system_started(RaSystem) ->
107110
end.
108111

109112
-spec get_config(ra_system_name()) -> ra_system:config().
110-
111113
get_config(quorum_queues = RaSystem) ->
112114
DefaultConfig = get_default_config(),
113115
Checksums = application:get_env(rabbit, quorum_compute_checksums, true),
@@ -124,7 +126,16 @@ get_config(quorum_queues = RaSystem) ->
124126
AERBatchSize = application:get_env(rabbit, quorum_max_append_entries_rpc_batch_size,
125127
?QUORUM_AER_MAX_RPC_SIZE),
126128
CompressMemTables = application:get_env(rabbit, quorum_compress_mem_tables, true),
129+
MinBinVheapSize = case code_version:get_otp_version() of
130+
OtpMaj when OtpMaj >= 27 ->
131+
?MIN_BIN_VHEAP_SIZE_DEFAULT * ?MIN_BIN_VHEAP_SIZE_MULT;
132+
_ ->
133+
?MIN_BIN_VHEAP_SIZE_DEFAULT
134+
end,
135+
127136
DefaultConfig#{name => RaSystem,
137+
wal_min_bin_vheap_size => MinBinVheapSize,
138+
server_min_bin_vheap_size => MinBinVheapSize,
128139
default_max_append_entries_rpc_batch_size => AERBatchSize,
129140
wal_compute_checksums => WalChecksums,
130141
wal_max_entries => WalMaxEntries,

deps/rabbit_common/src/code_version.erl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ get_forms(Code) ->
116116
throw({no_abstract_code, Reason})
117117
end.
118118

119+
-spec get_otp_version() -> non_neg_integer().
119120
get_otp_version() ->
120121
Version = erlang:system_info(otp_release),
121122
case re:run(Version, "^[0-9][0-9]", [{capture, first, list}]) of

moduleindex.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ rabbit:
696696
- rabbit_prelaunch_logging
697697
- rabbit_priority_queue
698698
- rabbit_process
699+
- rabbit_process_flag
699700
- rabbit_queue_consumers
700701
- rabbit_queue_decorator
701702
- rabbit_queue_index

0 commit comments

Comments
 (0)