Class: Mongo::Server::RoundTripTimeCalculator Private
- Inherits:
-
Object
- Object
- Mongo::Server::RoundTripTimeCalculator
- Defined in:
- lib/mongo/server/round_trip_time_calculator.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Attribute Summary collapse
- #average_round_trip_time ⇒ Object readonly private
- #last_round_trip_time ⇒ Object readonly private
- #minimum_round_trip_time ⇒ Object readonly private
Instance Method Summary collapse
-
#initialize ⇒ RoundTripTimeCalculator
constructor
private
A new instance of RoundTripTimeCalculator.
- #measure ⇒ Object private
- #update_average_round_trip_time ⇒ Object private
- #update_minimum_round_trip_time ⇒ Object private
Constructor Details
#initialize ⇒ RoundTripTimeCalculator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of RoundTripTimeCalculator.
34 35 36 37 38 39 40 |
# File 'lib/mongo/server/round_trip_time_calculator.rb', line 34 def initialize @last_round_trip_time = nil @average_round_trip_time = nil @minimum_round_trip_time = 0 @lock = Mutex.new @rtts = [] end |
Instance Attribute Details
#average_round_trip_time ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
43 44 45 |
# File 'lib/mongo/server/round_trip_time_calculator.rb', line 43 def average_round_trip_time @average_round_trip_time end |
#last_round_trip_time ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
42 43 44 |
# File 'lib/mongo/server/round_trip_time_calculator.rb', line 42 def last_round_trip_time @last_round_trip_time end |
#minimum_round_trip_time ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
44 45 46 |
# File 'lib/mongo/server/round_trip_time_calculator.rb', line 44 def minimum_round_trip_time @minimum_round_trip_time end |
Instance Method Details
#measure ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/mongo/server/round_trip_time_calculator.rb', line 46 def measure start = Utils.monotonic_time begin rv = yield rescue Error::SocketError, Error::SocketTimeoutError # If we encountered a network error, the round-trip is not # complete and thus RTT for it does not make sense. raise rescue Error, Error::AuthError => exc # For other errors, RTT is valid. end last_rtt = Utils.monotonic_time - start # If hello fails, we need to return the last round trip time # because it is used in the heartbeat failed SDAM event, # but we must not update the round trip time recorded in the server. unless exc @last_round_trip_time = last_rtt @lock.synchronize do update_average_round_trip_time update_minimum_round_trip_time end end if exc raise exc else rv end end |
#update_average_round_trip_time ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
77 78 79 80 81 82 83 |
# File 'lib/mongo/server/round_trip_time_calculator.rb', line 77 def update_average_round_trip_time @average_round_trip_time = if average_round_trip_time RTT_WEIGHT_FACTOR * last_round_trip_time + (1 - RTT_WEIGHT_FACTOR) * average_round_trip_time else last_round_trip_time end end |
#update_minimum_round_trip_time ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
85 86 87 88 89 90 91 |
# File 'lib/mongo/server/round_trip_time_calculator.rb', line 85 def update_minimum_round_trip_time @rtts.push(last_round_trip_time) unless last_round_trip_time.nil? @minimum_round_trip_time = 0 and return if @rtts.size < MIN_SAMPLES @rtts.shift if @rtts.size > RTT_SAMPLES_FOR_MINIMUM @minimum_round_trip_time = @rtts.compact.min end |