13.5. Summary

Eventually you'll get to the point where you need to squeeze more speed out of Rails. Before you do that, it's very important that you have good diagnostic data. Railsbench is a tool for automatically hitting your application and measuring timings. It provides useful data for finding where slow controller actions are located. Railsbench also allows you to compare two runs made under different server settings.

The Rails log contains a lot of useful information about the timing of pages, especially the timing of individual SQL statements. The query_trace plugin augments that information with a stack trace showing the code location of each SQL query.

The ruby-prof gem is a profiler that runs specific calls to your Rails application and breaks down the time spent by method. It's a firehose of information, but the various reporting options allow you to find the bottlenecks of interest.

When making performance changes, never compromise the maintainability of the program unless absolutely necessary. Using benchmarks to narrow down the problem can help tremendously. Sessions are potential speed bottlenecks for high-load sites, and cookie- or SQL-based storage can speed up their behavior. ActiveRecord is often the root cause of the initial performance problems. The SQL generated by ActiveRecord can be tuned in many ways to improve database response time.

Caching is a common way to improve the performance of a web application. Rails provides support for caching at the entire page level, at the level of an individual controller action, and at the arbitrary fragment level. Fragments can be stored in a file, or by an external system such as DRb or memcache.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.89.82