Class: Mongo::Server::RoundTripTimeAverager Private

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo/server/round_trip_time_averager.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.

Since:

  • 2.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRoundTripTimeAverager

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 RoundTripTimeAverager.

Since:

  • 2.0.0



25
26
27
28
# File 'lib/mongo/server/round_trip_time_averager.rb', line 25

def initialize
  @last_round_trip_time = nil
  @average_round_trip_time = nil
end

Instance Attribute Details

#average_round_trip_timeObject (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.

Since:

  • 2.0.0



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

def average_round_trip_time
  @average_round_trip_time
end

#last_round_trip_timeObject (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.

Since:

  • 2.0.0



30
31
32
# File 'lib/mongo/server/round_trip_time_averager.rb', line 30

def last_round_trip_time
  @last_round_trip_time
end

Instance Method Details

#measureObject

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.

Since:

  • 2.0.0



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/mongo/server/round_trip_time_averager.rb', line 33

def measure
  start = Time.now
  begin
    rv = yield
  rescue Exception => exc
  end
  last_round_trip_time = Time.now - start

  # If ismaster 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

  [rv, exc, last_round_trip_time, average_round_trip_time]
end