Zed,

Very cool, finally got around to playing with StatusHandler and StatisticsHandler. One thing that was missing that I wanted was insight into _what_ the RailsHandler was working on, and what was queued up while it sat in single-threaded mode -- ie., the current list of requests.

W/ the attached mongrel.conf, I hacked the RailsHandler to keep a hash of active requests, and spit that out in the StatusHandler.

Any thoughts or feedback on this (attached)?

thanks,
Michael


[EMAIL PROTECTED] wrote:
Feature Requests item #4420, was opened at 2006-05-10 02:10
You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=5148&aid=4420&group_id=1306
Initial Comment:
It would be really nice to have some insight into what a production Mongrel 
process is doing, in particular if it's stuck running a long-running Rails 
process.

I'm thinking something like Apache's server-status, or maybe having it dump to 
the log the list of queued requests in response to a signal.

----------------------------------------------------------------------

Comment By: Zed Shaw (zedshaw)
Date: 2006-05-23 05:57

Message:
Done and in svn. Take a look at examples/simpletest.rb for how it's used. I'll be documenting it, but basically add
stats = Mongrel::StatisticsFilter.new(:sample_rate => 1)
uri "/", :handler => stats
uri "/status", :handler => Mongrel::StatusHandler.new(:stats_filter => stats)

To a config/mongrel.conf and use -S to run it. Adjust sample rate to around 300 
for a lower load.


class Mongrel::Rails::RailsHandler
  @@guard = Mutex.new
  @@active_requests = {}
  def self.active_requests
    @@guard.synchronize do
      @@active_requests.values
    end
  end

  alias_method :do_process, :process
  def process(request, response)
    path_info = request.params[Mongrel::Const::PATH_INFO]
    @@guard.synchronize do
      @@active_requests[Thread.current] = { :path => path_info, :start => 
Time.now }
    end
    do_process(request, response)
    @@guard.synchronize do
      @@active_requests.delete Thread.current
    end
  end
end


class Mongrel::StatusHandler
  alias_method :describe_listener_basic, :describe_listener
  def describe_listener
    results = describe_listener_basic

    if (rails_handler = listener.classifier.handler_map.values.flatten.find { 
|h| h.is_a? Mongrel::Rails::RailsHandler })
      t = Time.now
      i = 0
      active_requests = rails_handler.class.active_requests
      results << "<h2>RailsHandler, #{active_requests.length} Active 
Requests</h2>"
      results << table("requests",
                       if active_requests.any?
                         active_requests.sort { |a,b| a[:start] <=> b[:start] 
}.map do |req| 
                           [i+=1, req[:path], "%0.2f seconds" % (t - 
req[:start])]
                         end
                       else
                         ["no active requests"]
                       end)
    end

    results
  end
end


stats = Mongrel::StatisticsFilter.new(:sample_rate => 1)
uri "/", :handler => stats
uri "/server-status", :handler => Mongrel::StatusHandler.new(:stats_filter => 
stats)
_______________________________________________
Mongrel-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/mongrel-users

Reply via email to