Skip to content

Commit 4d2c5fd

Browse files
essenmichaelklishin
authored andcommitted
Use better default memory allocators
We have settled on the following configuration for memory allocators after testing many different combinations: +MBas ageffcbf +MHas ageffcbf +MBlmbcs 512 +MHlmbcs 512 +MMmcs 30 They reduce the memory usage and help RabbitMQ reclaim memory, at the cost of a slight decrease in performance due to an increased number of memory operations. We need to start Erlang with these values in order to figure out whether they are supported. The allocator strategies we recommend were introduced in Erlang/OTP 20.2.3. The values can be overriden using RABBITMQ_SERVER_ERL_ARGS. cc @gerhard (cherry picked from commit ced1c03)
1 parent 313c52b commit 4d2c5fd

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

scripts/rabbitmq-server

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,25 @@ if [ ! -f "${RABBITMQ_SCHEMA_DIR}/rabbit.schema" ]; then
120120
cp "${RABBITMQ_HOME}/priv/schema/rabbit.schema" "${RABBITMQ_SCHEMA_DIR}"
121121
fi
122122

123+
# The default allocation strategy RabbitMQ is using was introduced
124+
# in Erlang/OTP 20.2.3. Earlier Erlang versions fail to start with
125+
# this configuration. We therefore need to ensure that erl accepts
126+
# these values before we can use them.
127+
#
128+
# The defaults are meant to reduce RabbitMQ's memory usage and help
129+
# it reclaim memory at the cost of a slight decrease in performance
130+
# (due to an increase in memory operations). These defaults can be
131+
# overriden using the RABBITMQ_SERVER_ERL_ARGS variable.
132+
RABBITMQ_DEFAULT_ALLOC_ARGS="+MBas ageffcbf +MHas ageffcbf +MBlmbcs 512 +MHlmbcs 512 +MMmcs 30"
133+
134+
${ERL_DIR}erl ${RABBITMQ_DEFAULT_ALLOC_ARGS} \
135+
-boot "${CLEAN_BOOT_FILE}" \
136+
-noinput -eval 'halt(0)' 2>/dev/null
137+
138+
if [ $? != 0 ] ; then
139+
RABBITMQ_DEFAULT_ALLOC_ARGS=
140+
fi
141+
123142
set -e
124143

125144
RABBITMQ_CONFIG_FILE_NOEX="${RABBITMQ_CONFIG_FILE%.*}"
@@ -213,6 +232,7 @@ start_rabbitmq_server() {
213232
${RABBITMQ_CONFIG_ARG} \
214233
+W w \
215234
+A ${RABBITMQ_IO_THREAD_POOL_SIZE} \
235+
${RABBITMQ_DEFAULT_ALLOC_ARGS} \
216236
${RABBITMQ_SERVER_ERL_ARGS} \
217237
+K true \
218238
-kernel inet_default_connect_options "[{nodelay,true}]" \

scripts/rabbitmq-server.bat

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,27 @@ if ERRORLEVEL 2 (
7272
set RABBITMQ_DIST_ARG=-kernel inet_dist_listen_min !RABBITMQ_DIST_PORT! -kernel inet_dist_listen_max !RABBITMQ_DIST_PORT!
7373
)
7474

75+
rem The default allocation strategy RabbitMQ is using was introduced
76+
rem in Erlang/OTP 20.2.3. Earlier Erlang versions fail to start with
77+
rem this configuration. We therefore need to ensure that erl accepts
78+
rem these values before we can use them.
79+
rem
80+
rem The defaults are meant to reduce RabbitMQ's memory usage and help
81+
rem it reclaim memory at the cost of a slight decrease in performance
82+
rem (due to an increase in memory operations). These defaults can be
83+
rem overriden using the RABBITMQ_SERVER_ERL_ARGS variable.
84+
85+
set RABBITMQ_DEFAULT_ALLOC_ARGS=+MBas ageffcbf +MHas ageffcbf +MBlmbcs 512 +MHlmbcs 512 +MMmcs 30
86+
87+
"!ERLANG_HOME!\bin\erl.exe" ^
88+
!RABBITMQ_DEFAULT_ALLOC_ARGS! ^
89+
-boot !CLEAN_BOOT_FILE! ^
90+
-noinput -eval "halt(0)"
91+
92+
if ERRORLEVEL 1 (
93+
set RABBITMQ_DEFAULT_ALLOC_ARGS=
94+
)
95+
7596
if not exist "!RABBITMQ_SCHEMA_DIR!" (
7697
mkdir "!RABBITMQ_SCHEMA_DIR!"
7798
)
@@ -173,6 +194,7 @@ if "!ENV_OK!"=="false" (
173194
!RABBITMQ_NAME_TYPE! !RABBITMQ_NODENAME! ^
174195
+W w ^
175196
+A "!RABBITMQ_IO_THREAD_POOL_SIZE!" ^
197+
!RABBITMQ_DEFAULT_ALLOC_ARGS! ^
176198
!RABBITMQ_SERVER_ERL_ARGS! ^
177199
!RABBITMQ_LISTEN_ARG! ^
178200
-kernel inet_default_connect_options "[{nodelay, true}]" ^

scripts/rabbitmq-service.bat

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,27 @@ if ERRORLEVEL 3 (
160160
set RABBITMQ_DIST_ARG=-kernel inet_dist_listen_min !RABBITMQ_DIST_PORT! -kernel inet_dist_listen_max !RABBITMQ_DIST_PORT!
161161
)
162162

163+
rem The default allocation strategy RabbitMQ is using was introduced
164+
rem in Erlang/OTP 20.2.3. Earlier Erlang versions fail to start with
165+
rem this configuration. We therefore need to ensure that erl accepts
166+
rem these values before we can use them.
167+
rem
168+
rem The defaults are meant to reduce RabbitMQ's memory usage and help
169+
rem it reclaim memory at the cost of a slight decrease in performance
170+
rem (due to an increase in memory operations). These defaults can be
171+
rem overriden using the RABBITMQ_SERVER_ERL_ARGS variable.
172+
173+
set RABBITMQ_DEFAULT_ALLOC_ARGS=+MBas ageffcbf +MHas ageffcbf +MBlmbcs 512 +MHlmbcs 512 +MMmcs 30
174+
175+
"!ERLANG_HOME!\bin\erl.exe" ^
176+
!RABBITMQ_DEFAULT_ALLOC_ARGS! ^
177+
-boot !CLEAN_BOOT_FILE! ^
178+
-noinput -eval "halt(0)"
179+
180+
if ERRORLEVEL 1 (
181+
set RABBITMQ_DEFAULT_ALLOC_ARGS=
182+
)
183+
163184
if not exist "!RABBITMQ_SCHEMA_DIR!" (
164185
mkdir "!RABBITMQ_SCHEMA_DIR!"
165186
)
@@ -254,6 +275,7 @@ set ERLANG_SERVICE_ARGUMENTS= ^
254275
!RABBITMQ_CONFIG_ARG! ^
255276
+W w ^
256277
+A "!RABBITMQ_IO_THREAD_POOL_SIZE!" ^
278+
!RABBITMQ_DEFAULT_ALLOC_ARGS! ^
257279
!RABBITMQ_SERVER_ERL_ARGS! ^
258280
!RABBITMQ_LISTEN_ARG! ^
259281
-kernel inet_default_connect_options "[{nodelay,true}]" ^

0 commit comments

Comments
 (0)