私はこのようなクラスを持っています:
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
常にうまく機能します。