Skip to content

Commit

Permalink
Prefer monotonic time to measure durations
Browse files Browse the repository at this point in the history
Monotonic time instead of wall clock time should be used to measure a
duration.

This is mostly a cosmetic change given that consumer timeouts are 30
mins by default.

See also
rabbitmq/khepri#239
#10928

(cherry picked from commit f5d2fd6)
  • Loading branch information
ansd authored and mergify[bot] committed Jun 6, 2024
1 parent 1ea136b commit 9c81f49
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions deps/rabbit/src/rabbit_channel.erl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
delivery_tag,
%% consumer tag
tag,
delivered_at,
delivered_at :: integer(),
%% queue name
queue,
%% message ID used by queue and message store implementations
Expand Down Expand Up @@ -1985,10 +1985,10 @@ record_sent(Type, QueueType, Tag, AckRequired,
false ->
ok
end,
DeliveredAt = os:system_time(millisecond),
rabbit_trace:tap_out(Msg, ConnName, ChannelNum, Username, TraceState),
UAMQ1 = case AckRequired of
true ->
DeliveredAt = erlang:monotonic_time(millisecond),
?QUEUE:in(#pending_ack{delivery_tag = DeliveryTag,
tag = Tag,
delivered_at = DeliveredAt,
Expand Down Expand Up @@ -2778,7 +2778,7 @@ evaluate_consumer_timeout(State = #ch{unacked_message_q = UAMQ}) ->

evaluate_consumer_timeout1(PA = #pending_ack{delivered_at = Time},
State) ->
Now = os:system_time(millisecond),
Now = erlang:monotonic_time(millisecond),
case get_consumer_timeout(PA, State) of
Timeout when is_integer(Timeout)
andalso Time < Now - Timeout ->
Expand Down

0 comments on commit 9c81f49

Please sign in to comment.