Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use monotonic time instead of system time for timers in the IoReactor #271

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ rvm:
- 2.5
- 2.6
- 2.7
- jruby-9.0.5.0
- jruby-9.2.21.0
jdk:
- openjdk8
env:
Expand Down
6 changes: 4 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ PATH
remote: .
specs:
cassandra-driver (3.2.5)
ione (~> 1.2)
ione (~> 1.2.5)
monotime (~> 0.7)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -40,12 +41,13 @@ GEM
ffi (1.9.25)
ffi (1.9.25-java)
gherkin (3.2.0)
ione (1.2.4)
ione (1.2.5)
json (1.8.6)
json (1.8.6-java)
lz4-ruby (0.3.3)
lz4-ruby (0.3.3-java)
minitest (4.7.5)
monotime (0.7.1)
multi_json (1.11.2)
multi_test (0.1.2)
os (0.9.6)
Expand Down
3 changes: 2 additions & 1 deletion cassandra-driver.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ Gem::Specification.new do |s|
s.files << 'ext/cassandra_murmur3/cassandra_murmur3.c'
end

s.add_runtime_dependency 'ione', '~> 1.2'
s.add_runtime_dependency 'ione', '~> 1.2.5'
s.add_runtime_dependency 'monotime', '~> 0.7'

s.add_development_dependency 'bundler', '~> 1.6'
s.add_development_dependency 'rake', '~> 13.0'
Expand Down
3 changes: 2 additions & 1 deletion lib/cassandra/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def self.let(name, &block)
define_method(:"#{name}=") { |object| @instances[name] = object }
end

let(:io_reactor) { Ione::Io::IoReactor.new }
let(:monotonic_clock) { Cassandra::Util::MonoClock::new }
let(:io_reactor) { Ione::Io::IoReactor.new(clock: monotonic_clock) }
let(:cluster_registry) { Cluster::Registry.new(logger) }
let(:cluster_schema) { Cluster::Schema.new }
let(:cluster_metadata) do
Expand Down
10 changes: 10 additions & 0 deletions lib/cassandra/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
module Cassandra
# @private
module Util
class MonoClock
def initialize
@start = Monotime::Instant.now
end

def now
@start.elapsed.to_secs
end
end

module_function

def encode_hash(hash, io = StringIO.new)
Expand Down