Skip to content

Commit

Permalink
Use monotonic clock when timestamping observed values
Browse files Browse the repository at this point in the history
The Monotonic clock is going to be more accurate on the few cases where
the distinction matters, but it's also somehow faster than `Time.now`.

Signed-off-by: Daniel Magliola <danielmagliola@gocardless.com>
  • Loading branch information
Daniel Magliola committed Jun 22, 2020
1 parent dddba2f commit 6bb7144
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/prometheus/client/data_stores/direct_file_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,10 @@ def write_value(key, value)
init_value(key)
end

now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
pos = @positions[key]
@f.seek(pos)
@f.write([value, Time.now.to_f].pack('dd'))
@f.write([value, now].pack('dd'))
@f.flush
end

Expand Down

0 comments on commit 6bb7144

Please sign in to comment.