0

我有这样的课:


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

它是一个服务器,我在另一端使用 ActiveResource 前端。

每个第 3 次请求都非常慢(大约 5 秒,第 1 次和第 2 次都可以,大约 0.01 秒)。Model.all.to_xml 中的问题(它是 ActiveRecord -> SQLite)。

为什么它太慢了?只有当我在 Mongrel::HttpHandler.. 中使用它时才会发生这种情况


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

总是很好用。

4

1 回答 1

0

ActiveRecord::Base.clear_active_connections!解决了这个问题。

于 2010-05-15T23:45:08.123 回答