@@ -10,7 +10,7 @@ class LatencyReplica
10
10
11
11
attr_reader :replica_clients
12
12
13
- DUMMY_LATENCY_SEC = 100.0
13
+ DUMMY_LATENCY_NSEC = 100 * 1000 * 1000 * 1000
14
14
MEASURE_ATTEMPT_COUNT = 10
15
15
16
16
def initialize ( replications , options , pool , **kwargs )
@@ -45,16 +45,18 @@ def measure_latencies(clients) # rubocop:disable Metrics/MethodLength, Metrics/A
45
45
threads = chuncked_clients . map do |k , v |
46
46
Thread . new ( k , v ) do |node_key , client |
47
47
Thread . pass
48
- min = DUMMY_LATENCY_SEC + 1.0
48
+
49
+ min = DUMMY_LATENCY_NSEC
49
50
MEASURE_ATTEMPT_COUNT . times do
50
- starting = Process . clock_gettime ( Process ::CLOCK_MONOTONIC )
51
+ starting = Process . clock_gettime ( Process ::CLOCK_MONOTONIC , :nanosecond )
51
52
client . send ( :call_once , 'PING' )
52
- duration = Process . clock_gettime ( Process ::CLOCK_MONOTONIC ) - starting
53
+ duration = Process . clock_gettime ( Process ::CLOCK_MONOTONIC , :nanosecond ) - starting
53
54
min = duration if duration < min
54
55
end
56
+
55
57
latencies [ node_key ] = min
56
58
rescue StandardError
57
- latencies [ node_key ] = DUMMY_LATENCY_SEC
59
+ latencies [ node_key ] = DUMMY_LATENCY_NSEC
58
60
end
59
61
end
60
62
0 commit comments