views:

45

answers:

1

I have a class like this:


class Router :: Mongrel::HttpHandler

  def process(req, res)
    status, header, body = [200, {"Content-type"=>"text/html"}, Model.all.to_xml]

    res.start(status) do |head, out|
      header.each_pair { |key, value|  head[key] = value }
        out.write body
      end
  end

end

It's an server and I use an ActiveResource front end on the other side.

Every 3rd request is very slow (about 5 seconds, 1st and 2nd is ok, about 0.01 sec). The problem in Model.all.to_xml (it is ActiveRecord -> SQLite).

Why it is too slow? It only happens when I use it in Mongrel::HttpHandler.. This


100.times do
  a = Time.now
  Car.all.to_xml
  puts "#{Time.now - a}"
  sleep(1)
end

is always works good.

A: 

ActiveRecord::Base.clear_active_connections! solved the problem.

stel