This module is used to extend TCPServer and Kgio::TCPServer objects and aggregate last_data_recv times for all accepted clients. It is designed to be used with Raindrops::LastDataRecv Rack application but can be easily changed to work with other stats collection devices.
Methods wrapped include:
TCPServer#accept
TCPServer#accept_nonblock
Kgio::TCPServer#kgio_accept
Kgio::TCPServer#kgio_tryaccept
automatically extends any TCPServer objects used by Unicorn
# File lib/raindrops/aggregate/last_data_recv.rb, line 39 39: def self.cornify! 40: Unicorn::HttpServer::LISTENERS.each do |sock| 41: sock.extend(self) if TCPServer === sock 42: end 43: end
By default, this is a Raindrops::Aggregate::PMQ object It may be anything that responds to *<<*
# File lib/raindrops/aggregate/last_data_recv.rb, line 29 29: def self.default_aggregate 30: @@default_aggregate ||= Raindrops::Aggregate::PMQ.new 31: end
Assign any object that responds to *<<*
# File lib/raindrops/aggregate/last_data_recv.rb, line 34 34: def self.default_aggregate=(agg) 35: @@default_aggregate = agg 36: end
each extended object needs to have TCP_DEFER_ACCEPT enabled for accuracy.
# File lib/raindrops/aggregate/last_data_recv.rb, line 47 47: def self.extended(obj) 48: obj.raindrops_aggregate = default_aggregate 49: # obj.setsockopt Socket::SOL_TCP, tcp_defer_accept = 9, seconds = 60 50: obj.setsockopt Socket::SOL_TCP, 9, 60 51: end
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
# File lib/raindrops/aggregate/last_data_recv.rb, line 79 79: def count!(io) 80: if io 81: x = TCP_Info.new(io) 82: @raindrops_aggregate << x.last_data_recv 83: end 84: io 85: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.