Skip to content

Commit 475e86b

Browse files
author
Daniil Fedotov
committed
Merge branch 'master' into rabbitmq-server-567
2 parents 5545152 + b907d34 commit 475e86b

16 files changed

+294
-89
lines changed

LICENSE

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
This package, the RabbitMQ server is licensed under the MPL. For the
22
MPL, please see LICENSE-MPL-RabbitMQ.
33

4-
The files `mochinum.erl' and `mochiweb_util.erl` are (c) 2007 Mochi Media, Inc and
5-
licensed under a MIT license, see LICENSE-MIT-Mochi.
6-
74
If you have any questions regarding licensing, please contact us at
85

LICENSE-MIT-Mochi

Lines changed: 0 additions & 9 deletions
This file was deleted.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PROJECT = rabbit
22
VERSION ?= $(call get_app_version,src/$(PROJECT).app.src)
33

44
DEPS = ranch lager rabbit_common rabbitmq_cli
5-
TEST_DEPS = rabbitmq_ct_helpers amqp_client meck proper
5+
TEST_DEPS = rabbitmq_ct_helpers rabbitmq_ct_client_helpers amqp_client meck proper
66

77
dep_rabbitmq_cli = git_rmq rabbitmq-cli $(current_rmq_ref) $(base_rmq_ref) rabbitmq-cli-integration
88

docs/rabbitmq.conf.example

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,21 @@
380380
##
381381
# queue_index_embed_msgs_below = 4kb
382382

383+
## Whether or not to enable background periodic GC of all
384+
## Erlang processes in "waiting" state.
385+
##
386+
## Disabling background GC may reduce latency for client operations,
387+
## keeping it enabled may reduce median RAM usage.
388+
##
389+
# background_gc_enabled = true
390+
391+
## Target (desired) interval (in milliseconds) at which we run background GC.
392+
## The actual interval will vary depending on how long it takes to execute
393+
## the operation (can be higher than this interval). Values less than
394+
## 30000 milliseconds are not recommended.
395+
##
396+
# background_gc_target_interval = 60000
397+
383398
## ----------------------------------------------------------------------------
384399
## Advanced Erlang Networking/Clustering Options.
385400
##
@@ -615,7 +630,7 @@
615630

616631
## File rotation config. No rotation by defualt.
617632
## DO NOT SET rotation date to ''. Leave unset if require "" value
618-
# log.file.rotation.date = $D0
633+
# log.file.rotation.date = $D0
619634
# log.file.rotation.size = 0
620635

621636

docs/rabbitmq.config.example

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,22 @@
331331
%% Size in bytes below which to embed messages in the queue index. See
332332
%% http://www.rabbitmq.com/persistence-conf.html
333333
%%
334-
%% {queue_index_embed_msgs_below, 4096}
334+
%% {queue_index_embed_msgs_below, 4096},
335+
336+
%% Whether or not to enable background periodic GC of all
337+
%% Erlang processes in "waiting" state.
338+
%%
339+
%% Disabling background GC may reduce latency for client operations,
340+
%% keeping it enabled may reduce median RAM usage.
341+
%%
342+
%% {background_gc_enabled, true},
343+
%%
344+
%% Target (desired) interval (in milliseconds) at which we run background GC.
345+
%% The actual interval will vary depending on how long it takes to execute
346+
%% the operation (can be higher than this interval). Values less than
347+
%% 30000 milliseconds are not recommended.
348+
%%
349+
%% {background_gc_target_interval, 60000}
335350

336351
]},
337352

priv/schema/rabbitmq.schema

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,20 @@ end}.
910910
{mapping, "queue_index_embed_msgs_below", "rabbit.queue_index_embed_msgs_below",
911911
[{datatype, bytesize}]}.
912912

913+
%% Whether or not to enable background GC.
914+
%%
915+
%% {background_gc_enabled, true}
916+
917+
{mapping, "background_gc_enabled", "rabbit.background_gc_enabled",
918+
[{datatype, {enum, [true, false]}}]}.
919+
920+
%% Interval (in milliseconds) at which we run background GC.
921+
%%
922+
%% {background_gc_target_interval, 60000}
923+
924+
{mapping, "background_gc_target_interval", "rabbit.background_gc_target_interval",
925+
[{datatype, integer}]}.
926+
913927
% ==========================
914928
% Lager section
915929
% ==========================

rabbitmq-components.mk

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ dep_rabbitmq_clusterer = git_rmq rabbitmq-clusterer $(current_rmq
2929
dep_rabbitmq_cli = git_rmq rabbitmq-cli $(current_rmq_ref) $(base_rmq_ref) master
3030
dep_rabbitmq_codegen = git_rmq rabbitmq-codegen $(current_rmq_ref) $(base_rmq_ref) master
3131
dep_rabbitmq_consistent_hash_exchange = git_rmq rabbitmq-consistent-hash-exchange $(current_rmq_ref) $(base_rmq_ref) master
32+
dep_rabbitmq_ct_client_helpers = git_rmq rabbitmq-ct-client-helpers $(current_rmq_ref) $(base_rmq_ref) master
3233
dep_rabbitmq_ct_helpers = git_rmq rabbitmq-ct-helpers $(current_rmq_ref) $(base_rmq_ref) master
3334
dep_rabbitmq_delayed_message_exchange = git_rmq rabbitmq-delayed-message-exchange $(current_rmq_ref) $(base_rmq_ref) master
3435
dep_rabbitmq_dotnet_client = git_rmq rabbitmq-dotnet-client $(current_rmq_ref) $(base_rmq_ref) master
@@ -72,12 +73,16 @@ dep_toke = git_rmq toke $(current_rmq_ref) $(base_r
7273

7374
dep_rabbitmq_public_umbrella = git_rmq rabbitmq-public-umbrella $(current_rmq_ref) $(base_rmq_ref) master
7475

75-
# FIXME: As of 2015-11-20, we depend on Ranch 1.2.1, but erlang.mk
76-
# defaults to Ranch 1.1.0. All projects depending indirectly on Ranch
77-
# needs to add "ranch" as a BUILD_DEPS. The list of projects needing
78-
# this workaround are:
79-
# o rabbitmq-web-stomp
80-
dep_ranch = git https://github.com/ninenines/ranch 1.2.1
76+
# Third-party dependencies version pinning.
77+
#
78+
# We do that in this file, which is copied in all projects, to ensure
79+
# all projects use the same versions. It avoids conflicts and makes it
80+
# possible to work with rabbitmq-public-umbrella.
81+
82+
dep_cowboy_commit = 1.0.3
83+
dep_mochiweb = git git://github.com/basho/mochiweb.git v2.9.0p2
84+
dep_ranch_commit = 1.2.1
85+
dep_webmachine_commit = 1.10.8p2
8186

8287
RABBITMQ_COMPONENTS = amqp_client \
8388
rabbit \
@@ -92,6 +97,7 @@ RABBITMQ_COMPONENTS = amqp_client \
9297
rabbitmq_cli \
9398
rabbitmq_codegen \
9499
rabbitmq_consistent_hash_exchange \
100+
rabbitmq_ct_client_helpers \
95101
rabbitmq_ct_helpers \
96102
rabbitmq_delayed_message_exchange \
97103
rabbitmq_dotnet_client \

scripts/rabbitmq-defaults

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,15 @@ SCHEMA_DIR=${SYS_PREFIX}/var/lib/rabbitmq/schema
4444

4545
PLUGINS_DIR="${RABBITMQ_HOME}/plugins"
4646

47+
# RABBIT_HOME can contain a version number, so default plugins
48+
# directory can be hard to find if we want to package some plugin
49+
# separately. When RABBITMQ_HOME points to a standard location where
50+
# it's usally being installed by package managers, we add
51+
# "/usr/lib/rabbitmq/plugins" to plugin search path.
52+
case "$RABBITMQ_HOME" in
53+
/usr/lib/rabbitmq/*)
54+
PLUGINS_DIR="/usr/lib/rabbitmq/plugins:$PLUGINS_DIR"
55+
;;
56+
esac
57+
4758
CONF_ENV_FILE=${SYS_PREFIX}/etc/rabbitmq/rabbitmq-env.conf

scripts/rabbitmq-env

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ rmq_realpath() {
5757
fi
5858
}
5959

60+
path_contains_existing_directory() {
61+
local path="${1:?}"
62+
local dir
63+
local rc
64+
local IFS="
65+
"
66+
for dir in $(echo "$path" | tr ':' '\n'); do
67+
if [ -d "$dir" ]; then
68+
return 0
69+
fi
70+
done
71+
return 1
72+
}
73+
6074
RABBITMQ_HOME="$(rmq_realpath "${RABBITMQ_SCRIPTS_DIR}/..")"
6175
ESCRIPT_DIR="${RABBITMQ_HOME}/escript"
6276

@@ -108,8 +122,9 @@ fi
108122
rmq_normalize_path() {
109123
local path=$1
110124

111-
# Remove redundant slashes and strip a trailing slash
112-
echo "$path" | sed -e 's#/\{2,\}#/#g' -e 's#/$##'
125+
# Remove redundant slashes and strip a trailing slash for a
126+
# PATH-like vars - ':' is the delimiter
127+
echo "$path" | sed -e 's#/\{2,\}#/#g' -e 's#/$##' -e 's#/:#:#g'
113128
}
114129

115130
rmq_normalize_path_var() {
@@ -265,9 +280,8 @@ if [ "${RABBITMQ_DEV_ENV}" ]; then
265280
RABBITMQ_ENABLED_PLUGINS_FILE="${enabled_plugins_file}"
266281
fi
267282
fi
268-
269-
270-
if [ -d "${RABBITMQ_PLUGINS_DIR}" ]; then
283+
284+
if path_contains_existing_directory "${RABBITMQ_PLUGINS_DIR}" ; then
271285
# RabbitMQ was started with "make run-broker" from its own
272286
# source tree. Take rabbit_common from the plugins directory.
273287
ERL_LIBS="${RABBITMQ_PLUGINS_DIR}:${ERL_LIBS}"
@@ -291,7 +305,7 @@ if [ "${RABBITMQ_DEV_ENV}" ]; then
291305
ERL_LIBS="${DEPS_DIR_norm}:${ERL_LIBS}"
292306
fi
293307
else
294-
if [ -d "${RABBITMQ_PLUGINS_DIR}" ]; then
308+
if path_contains_existing_directory "${RABBITMQ_PLUGINS_DIR}" ; then
295309
# RabbitMQ was started from its install directory. Take
296310
# rabbit_common from the plugins directory.
297311
ERL_LIBS="${RABBITMQ_PLUGINS_DIR}:${ERL_LIBS}"

src/background_gc.erl

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
terminate/2, code_change/3]).
2626

2727
-define(MAX_RATIO, 0.01).
28-
-define(IDEAL_INTERVAL, 60000).
2928
-define(MAX_INTERVAL, 240000).
3029

3130
-record(state, {last_interval}).
@@ -45,7 +44,9 @@ run() -> gen_server2:cast(?MODULE, run).
4544

4645
%%----------------------------------------------------------------------------
4746

48-
init([]) -> {ok, interval_gc(#state{last_interval = ?IDEAL_INTERVAL})}.
47+
init([]) ->
48+
{ok, IdealInterval} = application:get_env(rabbit, background_gc_target_interval),
49+
{ok, interval_gc(#state{last_interval = IdealInterval})}.
4950

5051
handle_call(Msg, _From, State) ->
5152
{stop, {unexpected_call, Msg}, {unexpected_call, Msg}, State}.
@@ -65,14 +66,22 @@ terminate(_Reason, State) -> State.
6566
%%----------------------------------------------------------------------------
6667

6768
interval_gc(State = #state{last_interval = LastInterval}) ->
69+
{ok, IdealInterval} = application:get_env(rabbit, background_gc_target_interval),
6870
{ok, Interval} = rabbit_misc:interval_operation(
6971
{?MODULE, gc, []},
70-
?MAX_RATIO, ?MAX_INTERVAL, ?IDEAL_INTERVAL, LastInterval),
72+
?MAX_RATIO, ?MAX_INTERVAL, IdealInterval, LastInterval),
7173
erlang:send_after(Interval, self(), run),
7274
State#state{last_interval = Interval}.
7375

7476
gc() ->
75-
[garbage_collect(P) || P <- processes(),
76-
{status, waiting} == process_info(P, status)],
77-
garbage_collect(), %% since we will never be waiting...
77+
Enabled = rabbit_misc:get_env(rabbit, background_gc_enabled, true),
78+
case Enabled of
79+
true ->
80+
[garbage_collect(P) || P <- processes(),
81+
{status, waiting} == process_info(P, status)],
82+
%% since we will never be waiting...
83+
garbage_collect();
84+
false ->
85+
ok
86+
end,
7887
ok.

src/rabbit.app.src

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,7 @@
117117
]},
118118

119119
%% rabbitmq-server-973
120-
{lazy_queue_explicit_gc_run_operation_threshold, 250}
120+
{lazy_queue_explicit_gc_run_operation_threshold, 250},
121+
{background_gc_enabled, true},
122+
{background_gc_target_interval, 60000}
121123
]}]}.

src/rabbit.erl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
stop_and_halt/0, await_startup/0, status/0, is_running/0, alarms/0,
2323
is_running/1, environment/0, rotate_logs/0, force_event_refresh/1,
2424
start_fhc/0]).
25-
-export([start/2, stop/1, prep_stop/1]).
25+
-export([start/2, stop/1]).
2626
-export([start_apps/1, stop_apps/1]).
2727
-export([log_locations/0, config_files/0, decrypt_config/2]). %% for testing and mgmt-agent
2828

@@ -727,17 +727,15 @@ start(normal, []) ->
727727
Error
728728
end.
729729

730-
prep_stop(_State) ->
730+
stop(_State) ->
731731
ok = rabbit_alarm:stop(),
732732
ok = case rabbit_mnesia:is_clustered() of
733733
true -> ok;
734734
false -> rabbit_table:clear_ram_only_tables()
735735
end,
736736
ok.
737737

738-
stop(_) -> ok.
739-
740-
-spec boot_error(atom(), term()) -> no_return().
738+
-spec boot_error(term(), not_available | [tuple()]) -> no_return().
741739

742740
boot_error(_, {could_not_start, rabbit, {{timeout_waiting_for_tables, _}, _}}) ->
743741
AllNodes = rabbit_mnesia:cluster_nodes(all),

0 commit comments

Comments
 (0)