Ruby on Rails question - how can I measure response time from when request first hits app?? (e.g. using 'benchmark')
Background - I'm serving files (text, images) to a browser via my Rails application as the user needs to be authenticated too. The files are on file system, however references are in the database, as I'm using PAPERCLIP. Using AUTHLOGIC for authentication. I'm finding the response times are quite bad, as each request for HTML/image etc have to go through the Rails layers I guess of AUTHLOGIC, PAPERCLIP then stream back.
Q1 - How can I get benchmark times that start right from the first point the HTTP request hits the rails app, through to when it's ready to start streaming back the request (i.e. to avoid network traffic variations)?
I'm using "benchmark" in my controller however I'm pretty sure I'm missing other delays like: authentication via AuthLogic, etc... For example I'开发者_高级运维m roughly doing
def find
self.class.benchmark("BENCHMARK REPORT") do
search_path = params[:path] * "/"
webfile = Webfile.find_by_path( search_path )
if webfile
send_file webfile.file.path , :type => webfile.file_content_type, :disposition => 'inline'
else
render :text => "COULD NOT FIND YOUR FILE WITH PATH = #{params [:path]}"
end
end
end
Q2 - Given I want users to authenticate for HTML & associated files (CSS, images) then page needs, is there any obvious way to get an order of magnitude improvement? I guess I could save in session state the list of children files a HTML page needs & get its file location path, until the subsequent requests come, and that would some a database lookup (at the expense of using session state)?
thanks
There are a lot of ways to do this. One good one is to install the New Relic plugin in your app which does this kind of performance monitoring. You need to pay to use it in production, but it's free to use locally for development benchmarking and profiling.
There are several other companies offering similar products although I haven't personally used them.
Also rails now comes with some scripts to do benchmarking and profiling. Check out the scripts in script/performance
精彩评论