Skip to content

Commit

Permalink
Cache value of os:timestamp() in basho_bench_stats:handle_cast()
Browse files Browse the repository at this point in the history
  • Loading branch information
slfritchie committed Oct 20, 2014
1 parent 0faae29 commit 3e330c5
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/basho_bench_stats.erl
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,15 @@ handle_call({op, Op, {error, Reason}, _ElapsedUs}, _From, State) ->
{reply, ok, State#state { errors_since_last_report = true }}.

handle_cast({Op, {ok, Units}, ElapsedUs}, State = #state{last_write_time = LWT, report_interval = RI}) ->
TimeSinceLastReport = timer:now_diff(os:timestamp(), LWT) / 1000, %% To get the diff in seconds
TimeSinceLastWarn = timer:now_diff(os:timestamp(), State#state.last_warn) / 1000,
Now = os:timestamp(),
TimeSinceLastReport = timer:now_diff(Now, LWT) / 1000, %% To get the diff in seconds
TimeSinceLastWarn = timer:now_diff(Now, State#state.last_warn) / 1000,
if
TimeSinceLastReport > (RI * 2) andalso TimeSinceLastWarn > ?WARN_INTERVAL ->
?WARN("basho_bench_stats has not reported in ~.2f milliseconds\n", [TimeSinceLastReport]),
{message_queue_len, QLen} = process_info(self(), message_queue_len),
?WARN("stats process mailbox size = ~w\n", [QLen]),
NewState = State#state{last_warn = os:timestamp()};
NewState = State#state{last_warn = Now};
true ->
NewState = State
end,
Expand Down

0 comments on commit 3e330c5

Please sign in to comment.