Module: Raindrops::Aggregate::LastDataRecv

Defined in:
lib/raindrops/aggregate/last_data_recv.rb

Overview

  • Kgio::TCPServer#kgio_tryaccept

Constant Summary collapse

@@default_aggregate =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#raindrops_aggregateObject

The integer value of last_data_recv is sent to this object. This is usually a duck type compatible with the Aggregate class, but can be anything that accepts the *<<* method.



19
20
21
# File 'lib/raindrops/aggregate/last_data_recv.rb', line 19

def raindrops_aggregate
  @raindrops_aggregate
end

Class Method Details

.cornify!Object

automatically extends any TCPServer objects used by Unicorn



35
36
37
38
39
# File 'lib/raindrops/aggregate/last_data_recv.rb', line 35

def self.cornify!
  Unicorn::HttpServer::LISTENERS.each do |sock|
    sock.extend(self) if TCPServer === sock
  end
end

.default_aggregateObject

By default, this is a Raindrops::Aggregate::PMQ object It may be anything that responds to *<<*



25
26
27
# File 'lib/raindrops/aggregate/last_data_recv.rb', line 25

def self.default_aggregate
  @@default_aggregate ||= Raindrops::Aggregate::PMQ.new
end

.default_aggregate=(agg) ⇒ Object

Assign any object that responds to *<<*



30
31
32
# File 'lib/raindrops/aggregate/last_data_recv.rb', line 30

def self.default_aggregate=(agg)
  @@default_aggregate = agg
end

.extended(obj) ⇒ Object

each extended object needs to have TCP_DEFER_ACCEPT enabled for accuracy.



43
44
45
46
47
# File 'lib/raindrops/aggregate/last_data_recv.rb', line 43

def self.extended(obj)
  obj.raindrops_aggregate = default_aggregate
  # obj.setsockopt Socket::SOL_TCP, tcp_defer_accept = 9, seconds = 60
  obj.setsockopt Socket::SOL_TCP, 9, 60
end

Instance Method Details

#acceptObject



59
60
61
# File 'lib/raindrops/aggregate/last_data_recv.rb', line 59

def accept
  count! super
end

#accept_nonblockObject



63
64
65
# File 'lib/raindrops/aggregate/last_data_recv.rb', line 63

def accept_nonblock
  count! super
end

#count!(io) ⇒ Object

The last_data_recv member of Raindrops::TCP_Info can be used to infer the time a client spent in the listen queue before it was accepted.

We require TCP_DEFER_ACCEPT on the listen socket for last_data_recv to be accurate



75
76
77
78
79
80
81
# File 'lib/raindrops/aggregate/last_data_recv.rb', line 75

def count!(io)
  if io
    x = Raindrops::TCP_Info.new(io)
    @raindrops_aggregate << x.last_data_recv
  end
  io
end

#kgio_accept(*args) ⇒ Object



55
56
57
# File 'lib/raindrops/aggregate/last_data_recv.rb', line 55

def kgio_accept(*args)
  count! super
end

#kgio_tryaccept(*args) ⇒ Object

:stopdoc:



51
52
53
# File 'lib/raindrops/aggregate/last_data_recv.rb', line 51

def kgio_tryaccept(*args)
  count! super
end