123456789_123456789_123456789_123456789_123456789_

Class: Mongo::Server::RoundTripTimeAverager Private

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: lib/mongo/server/round_trip_time_averager.rb

Overview

Since:

  • 2.0.0

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#average_round_trip_time (readonly)

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/server/round_trip_time_averager.rb', line 34

attr_reader :average_round_trip_time

#last_round_trip_time (readonly)

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/server/round_trip_time_averager.rb', line 33

attr_reader :last_round_trip_time

Instance Method Details

#measure

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/server/round_trip_time_averager.rb', line 36

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_round_trip_time = 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_round_trip_time
    update_average_round_trip_time
  end

  if exc
    raise exc
  else
    rv
  end
end

#update_average_round_trip_time (private)

This method is separate for testing purposes.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/server/round_trip_time_averager.rb', line 67

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