Ruby and Rails have basic profiling tools that can help you. Take a look at this Rails manual: Rails Performance Testing Applications .
This page describes how you can write benchmarking test cases to prevent performance regressions and profiling methods that can be as simple as:
rails profiler 'Ruby.code.to.run'
If this does not help you, consider using the New Relic . But I would also look at Rack-Bug (by the way, it has a Rails 3 branch for Rails 3). Rack-Bug is a debugging toolbar that gives you a lot of awesome indicators on where the time was spent on the request and does it right in the browser, along with a normal response, so this is the least painful.
Now what you are doing is wrong:
- you should avoid thick looks, as thick looks are hard to test, hard to debug, and hard to profile.
- you should avoid slow code in your web process, as it will block other clients from accessing your web server, instead move all this logic to the asynchronous job queue
So, move this processing to the job queue. Delayed_job is pretty reliable, properly supported, and works with Rails 3.
Thus, your opinion will register a new task and return. And when the work is done, you set the flag somewhere so that it is done. Then, using a special API call, you can check its completeness from client-side Javascript every few seconds. And after completion, you can show the results, redirect or start the download, or something else, again from Javascript.
And if the above is not an option (maybe this is the page that displays the report, which should be instantaneous), the first bottleneck you should consider are the SQL queries executed, so check out MySQL DESCRIBE (or PostgreSQL EXPLAIN ) . It's easy to see where you need indexes.
source share