Skip to content

Commit a278295

Browse files
committed
Make Quorum queue snapshot interval configurable
And increase the default from 4096 to 8192. This should help reducing the number of snapshots taken by high throughput near-empty queues.
1 parent 1bdefd7 commit a278295

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

deps/rabbit/src/rabbit_quorum_queue.erl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
-define(TICK_TIMEOUT, 5000). %% the ra server tick time
108108
-define(DELETE_TIMEOUT, 5000).
109109
-define(ADD_MEMBER_TIMEOUT, 5000).
110+
-define(SNAPSHOT_INTERVAL, 8192). %% the ra default is 4096
110111

111112
%%----------- rabbit_queue_type ---------------------------------------------
112113

@@ -189,7 +190,9 @@ start_cluster(Q) ->
189190
{created, NewQ} ->
190191
TickTimeout = application:get_env(rabbit, quorum_tick_interval,
191192
?TICK_TIMEOUT),
192-
RaConfs = [make_ra_conf(NewQ, ServerId, TickTimeout)
193+
SnapshotInterval = application:get_env(rabbit, quorum_snapshot_interval,
194+
?SNAPSHOT_INTERVAL),
195+
RaConfs = [make_ra_conf(NewQ, ServerId, TickTimeout, SnapshotInterval)
193196
|| ServerId <- members(NewQ)],
194197
case ra:start_cluster(?RA_SYSTEM, RaConfs) of
195198
{ok, _, _} ->
@@ -1058,7 +1061,9 @@ add_member(Q, Node, Timeout) when ?amqqueue_is_quorum(Q) ->
10581061
Members = members(Q),
10591062
TickTimeout = application:get_env(rabbit, quorum_tick_interval,
10601063
?TICK_TIMEOUT),
1061-
Conf = make_ra_conf(Q, ServerId, TickTimeout),
1064+
SnapshotInterval = application:get_env(rabbit, quorum_snapshot_interval,
1065+
?SNAPSHOT_INTERVAL),
1066+
Conf = make_ra_conf(Q, ServerId, TickTimeout, SnapshotInterval),
10621067
case ra:start_server(?RA_SYSTEM, Conf) of
10631068
ok ->
10641069
case ra:add_member(Members, ServerId, Timeout) of
@@ -1621,7 +1626,7 @@ members(Q) when ?amqqueue_is_quorum(Q) ->
16211626
format_ra_event(ServerId, Evt, QRef) ->
16221627
{'$gen_cast', {queue_event, QRef, {ServerId, Evt}}}.
16231628

1624-
make_ra_conf(Q, ServerId, TickTimeout) ->
1629+
make_ra_conf(Q, ServerId, TickTimeout, SnapshotInterval) ->
16251630
QName = amqqueue:get_name(Q),
16261631
RaMachine = ra_machine(Q),
16271632
[{ClusterName, _} | _] = Members = members(Q),
@@ -1634,7 +1639,8 @@ make_ra_conf(Q, ServerId, TickTimeout) ->
16341639
friendly_name => FName,
16351640
metrics_key => QName,
16361641
initial_members => Members,
1637-
log_init_args => #{uid => UId},
1642+
log_init_args => #{uid => UId,
1643+
snapshot_interval => SnapshotInterval},
16381644
tick_timeout => TickTimeout,
16391645
machine => RaMachine,
16401646
ra_event_formatter => Formatter}.

0 commit comments

Comments
 (0)