module Raindrops::Aggregate::LastDataRecv - raindrops - real-time stats for preforking Rack servers

# module Raindrops::Aggregate::LastDataRecv

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

### Attributes

raindrops_aggregate[RW]

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.

### Public Class Methods

cornify!() click to toggle source

automatically extends any TCPServer objects used by Unicorn

    # File lib/raindrops/aggregate/last_data_recv.rb, line 38
    def self.cornify!
      Unicorn::HttpServer::LISTENERS.each do |sock|
        sock.extend(self) if TCPServer === sock
      end
    end

default_aggregate() click to toggle source

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 28
    def self.default_aggregate
      @@default_aggregate ||= Raindrops::Aggregate::PMQ.new
    end

default_aggregate=(agg) click to toggle source

Assign any object that responds to *<<*

    # File lib/raindrops/aggregate/last_data_recv.rb, line 33
    def self.default_aggregate=(agg)
      @@default_aggregate = agg
    end

extended(obj) click to toggle source

each extended object needs to have TCP_DEFER_ACCEPT enabled for accuracy.

    # File lib/raindrops/aggregate/last_data_recv.rb, line 46
    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

### Public Instance Methods

count!(io) click to toggle source

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 78
    def count!(io)
      if io
        x = TCP_Info.new(io)
        @raindrops_aggregate << x.last_data_recv
      end
      io
    end