Skip to content

Commit 215ea6f

Browse files
committed
rabbit_disk_monitor: Add config to tune polling interval
The polling interval (min, max and fast-rate) should be tuned for use on different hardware. For example high-end machines with strong network bandwidth should be tuning the fast-rate higher so that disk space is checked more often, as with stronger resources the disk space could fill up more rapidly than the default 250MB/sec predicts.
1 parent eca7e05 commit 215ea6f

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

deps/rabbit/priv/schema/rabbit.schema

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,20 @@ fun(Conf) ->
12381238
end
12391239
end}.
12401240

1241+
%% Tuning of disk monitor polling parameters
1242+
{mapping, "disk_monitor.fast_rate", "rabbit.disk_monitor_fast_rate", [
1243+
%% Unit: KB/second, for example 250_000 for 250MB/sec.
1244+
{datatype, [integer]}
1245+
]}.
1246+
{mapping, "disk_monitor.min_interval", "rabbit.disk_monitor_min_interval", [
1247+
%% Unit: milliseconds.
1248+
{datatype, [integer]}
1249+
]}.
1250+
{mapping, "disk_monitor.max_interval", "rabbit.disk_monitor_max_interval", [
1251+
%% Unit: milliseconds.
1252+
{datatype, [integer]}
1253+
]}.
1254+
12411255
%% Per-queue-type / per-mount disk alarms
12421256
{mapping, "disk_free_limits.$num.name", "rabbit.disk_free_limits", [
12431257
{datatype, [binary]}

deps/rabbit/src/rabbit_disk_monitor.erl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
-define(DEFAULT_MIN_DISK_CHECK_INTERVAL, 100).
3737
-define(DEFAULT_MAX_DISK_CHECK_INTERVAL, 10000).
3838
-define(DEFAULT_DISK_FREE_LIMIT, 50000000).
39-
%% 250MB/s i.e. 250kB/ms
40-
-define(FAST_RATE, (250 * 1000)).
4139

4240
-record(mount,
4341
{%% name set in configuration
@@ -164,6 +162,10 @@ start_link(Args) ->
164162
init([Limit]) ->
165163
{ok, Retries} = application:get_env(rabbit, disk_monitor_failure_retries),
166164
{ok, Interval} = application:get_env(rabbit, disk_monitor_failure_retry_interval),
165+
MinInterval = application:get_env(rabbit, disk_monitor_min_interval,
166+
?DEFAULT_MIN_DISK_CHECK_INTERVAL),
167+
MaxInterval = application:get_env(rabbit, disk_monitor_max_interval,
168+
?DEFAULT_MAX_DISK_CHECK_INTERVAL),
167169
?ETS_NAME = ets:new(?ETS_NAME, [protected, set, named_table]),
168170
?MOUNT_ETS_NAME = ets:new(?MOUNT_ETS_NAME, [protected, set, named_table,
169171
{keypos, #mount.name}]),
@@ -172,8 +174,8 @@ init([Limit]) ->
172174
limit = Limit,
173175
retries = Retries,
174176
interval = Interval},
175-
State1 = set_min_check_interval(?DEFAULT_MIN_DISK_CHECK_INTERVAL, State0),
176-
State2 = set_max_check_interval(?DEFAULT_MAX_DISK_CHECK_INTERVAL, State1),
177+
State1 = set_min_check_interval(MinInterval, State0),
178+
State2 = set_max_check_interval(MaxInterval, State1),
177179

178180
State3 = enable(State2),
179181

@@ -420,9 +422,13 @@ interval(#state{actual = DataDirAvailable,
420422
(_Path, _Mount, Min) ->
421423
Min
422424
end, DataDirGap, Mounts),
423-
IdealInterval = 2 * SmallestGap / ?FAST_RATE,
425+
IdealInterval = 2 * SmallestGap / fast_rate(),
424426
trunc(erlang:max(MinInterval, erlang:min(MaxInterval, IdealInterval))).
425427

428+
fast_rate() ->
429+
%% 250MB/s i.e. 250kB/ms
430+
application:get_env(rabbit, disk_monitor_fast_rate, 250_000).
431+
426432
-spec mounts() -> mounts().
427433
mounts() ->
428434
case application:get_env(rabbit, disk_free_limits) of

deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ ssl_options.fail_if_no_peer_cert = true",
179179
"disk_free_limit.absolute = 2P",
180180
[{rabbit,[{disk_free_limit, "2P"}]}],
181181
[]},
182+
%% Disk monitor polling
183+
{disk_monitor_tune_polling_parameters,
184+
"disk_monitor.fast_rate = 1000000 # 1 GB/sec
185+
disk_monitor.min_interval = 50
186+
disk_monitor.max_interval = 20000",
187+
[{rabbit,[{disk_monitor_fast_rate, 1_000_000},
188+
{disk_monitor_min_interval, 50},
189+
{disk_monitor_max_interval, 20_000}]}],
190+
[]},
182191

183192
{default_users,
184193
"

0 commit comments

Comments
 (0)