Skip to content

Commit

Permalink
Use Process.clock_gettime.
Browse files Browse the repository at this point in the history
it's faster than Time.now

Signed-off-by: Yuta Iwama <[email protected]>
  • Loading branch information
ganmacs committed Aug 13, 2019
1 parent 6e486aa commit 7811da6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/fluent/clock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def self.now_raw
Process.clock_gettime(CLOCK_ID)
end

def self.real_now(unit = :second)
Process.clock_gettime(Process::CLOCK_REALTIME, unit)
end

def self.dst_clock_from_time(time)
diff_sec = Time.now - time
now_raw - diff_sec
Expand Down
3 changes: 2 additions & 1 deletion lib/fluent/time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ def self.eq?(a, b)
end

def self.now
from_time(Time.now)
now = Fluent::Clock.real_now(:nanosecond)
Fluent::EventTime.new(now / 1_000_000_000, now % 1_000_000_000)
end

def self.parse(*args)
Expand Down

0 comments on commit 7811da6

Please sign in to comment.