@@ -10,7 +10,7 @@ class LatencyReplica
1010
1111 attr_reader :replica_clients
1212
13- DUMMY_LATENCY_SEC = 100.0
13+ DUMMY_LATENCY_NSEC = 100 * 1000 * 1000 * 1000
1414 MEASURE_ATTEMPT_COUNT = 10
1515
1616 def initialize ( replications , options , pool , **kwargs )
@@ -45,16 +45,18 @@ def measure_latencies(clients) # rubocop:disable Metrics/MethodLength, Metrics/A
4545 threads = chuncked_clients . map do |k , v |
4646 Thread . new ( k , v ) do |node_key , client |
4747 Thread . pass
48- min = DUMMY_LATENCY_SEC + 1.0
48+
49+ min = DUMMY_LATENCY_NSEC
4950 MEASURE_ATTEMPT_COUNT . times do
50- starting = Process . clock_gettime ( Process ::CLOCK_MONOTONIC )
51+ starting = Process . clock_gettime ( Process ::CLOCK_MONOTONIC , :nanosecond )
5152 client . send ( :call_once , 'PING' )
52- duration = Process . clock_gettime ( Process ::CLOCK_MONOTONIC ) - starting
53+ duration = Process . clock_gettime ( Process ::CLOCK_MONOTONIC , :nanosecond ) - starting
5354 min = duration if duration < min
5455 end
56+
5557 latencies [ node_key ] = min
5658 rescue StandardError
57- latencies [ node_key ] = DUMMY_LATENCY_SEC
59+ latencies [ node_key ] = DUMMY_LATENCY_NSEC
5860 end
5961 end
6062
0 commit comments