Skip to content

Commit 7404ba5

Browse files
ansdacogoluegnes
authored andcommitted
Remove useless ensure_stats_timer calls
Calling ensure_stats_timer after init_stats_timer and reset_stats_timer is enough. The idea is to call stop_stats_timer before hibernation and ensure_stats_timer on wakeup. However, since we never call stop_stats_timer in rabbit_stream_reader, we don't need to call ensure_stats_timer on every network activity. (cherry picked from commit b145684)
1 parent 3391a6d commit 7404ba5

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

deps/rabbitmq_stream/src/rabbit_stream_reader.erl

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -535,11 +535,10 @@ open(info,
535535
name = ConnectionName,
536536
credits = Credits,
537537
heartbeater = Heartbeater
538-
} = Connection0,
538+
} = Connection,
539539
connection_state = #stream_connection_state{blocked = Blocked} = State,
540540
config = #configuration{credits_required_for_unblocking = CreditsRequiredForUnblocking}
541541
} = StatemData) ->
542-
Connection = ensure_stats_timer(Connection0),
543542
rabbit_log_connection:debug("Connection ~p received resource alarm. Alarm "
544543
"on? ~p",
545544
[ConnectionName, IsThereAlarm]),
@@ -581,12 +580,11 @@ open(info,
581580
connection = #stream_connection{socket = S,
582581
credits = Credits,
583582
heartbeater = Heartbeater
584-
} = Connection0,
583+
} = Connection,
585584
connection_state = #stream_connection_state{blocked = Blocked} = State,
586585
config = Configuration
587586
} = StatemData)
588587
when OK =:= tcp; OK =:= ssl ->
589-
Connection = ensure_stats_timer(Connection0),
590588
{Connection1, State1} = handle_inbound_data_post_auth(Transport,
591589
Connection,
592590
State,
@@ -662,10 +660,9 @@ open(info,
662660
transport = Transport,
663661
connection = #stream_connection{socket = S,
664662
monitors = Monitors
665-
} = Connection0,
663+
} = Connection,
666664
connection_state = State
667665
} = StatemData) ->
668-
Connection = ensure_stats_timer(Connection0),
669666
{Connection1, State1} =
670667
case Monitors of
671668
#{MonitorRef := Stream} ->
@@ -764,13 +761,12 @@ open(cast,
764761
credits = Credits,
765762
heartbeater = Heartbeater,
766763
publishers = Publishers
767-
} = Connection0,
764+
} = Connection,
768765
connection_state = #stream_connection_state{
769766
blocked = Blocked
770767
} = State,
771768
config = Configuration
772769
} = StatemData) ->
773-
Connection = ensure_stats_timer(Connection0),
774770
ByPublisher =
775771
lists:foldr(fun({PublisherId, PublishingId}, Acc) ->
776772
case maps:get(PublisherId, Acc, undefined) of
@@ -820,13 +816,12 @@ open(cast,
820816
heartbeater = Heartbeater,
821817
publishers = Publishers,
822818
publisher_to_ids = PublisherRefToIds
823-
} = Connection0,
819+
} = Connection,
824820
connection_state = #stream_connection_state{
825821
blocked = Blocked
826822
} = State,
827823
config = Configuration
828824
} = StatemData) ->
829-
Connection = ensure_stats_timer(Connection0),
830825
%% FIXME handle case when publisher ID is not found (e.g. deleted before confirms arrive)
831826
PublisherId =
832827
maps:get({Stream, PublisherReference}, PublisherRefToIds,
@@ -867,11 +862,10 @@ open(cast,
867862
connection = #stream_connection{
868863
stream_subscriptions = StreamSubscriptions,
869864
send_file_oct = SendFileOct
870-
} = Connection0,
865+
} = Connection,
871866
connection_state = #stream_connection_state{consumers = Consumers} = State
872867
} = StatemData)
873868
when Offset > -1 ->
874-
Connection = ensure_stats_timer(Connection0),
875869
{Connection1, State1} =
876870
case maps:get(StreamName, StreamSubscriptions, undefined) of
877871
undefined ->
@@ -930,9 +924,8 @@ open(cast,
930924
connection = Connection1,
931925
connection_state = State1}};
932926
open(cast, {force_event_refresh, Ref}, #statem_data{
933-
connection = Connection0,
927+
connection = Connection,
934928
connection_state = State} = StatemData) ->
935-
Connection = ensure_stats_timer(Connection0),
936929
Infos =
937930
augment_infos_with_user_provided_connection_name(infos(?CREATION_EVENT_KEYS,
938931
Connection,
@@ -942,7 +935,8 @@ open(cast, {force_event_refresh, Ref}, #statem_data{
942935
Connection1 =
943936
rabbit_event:init_stats_timer(Connection,
944937
#stream_connection.stats_timer),
945-
{keep_state, StatemData#statem_data{connection = Connection1}}.
938+
Connection2 = ensure_stats_timer(Connection1),
939+
{keep_state, StatemData#statem_data{connection = Connection2}}.
946940

947941
close_sent(info, {tcp, S, Data}, #statem_data{
948942
transport = Transport,

0 commit comments

Comments
 (0)