Wednesday, December 3, 2008

How to Improve Performace in Rails Application

1.Do not use dynamic finders like find_by_name.. find_by_columnname..
This will internally call a method named 'method_missing' in activerecord then it will construct a query and execute it.

2.Do not use rails helpers like link_to

3.Avoid associations

4.Avoid too many before_filters

5.While writing query for eg. Model.find(:all)
try to use select in this so that u limit only the required rows from the database

6.Move your javascript and css to the bottom of ur page..
<%=javascript_include_tag "prototype"%>

7.If u r using n-1 relation then it can be optimized thru piggy back technique http://railsexpress.de/blog/articles/2005/11/06/the-case-for-piggy-backed-attributes

8.Also do indexing in your database.

What is Indexing and why Indexing?
In a database, you have a few different kinds of objects. You’ve got tables, which are just big containers in which you put your data. The data is not sorted, so if you want to find something in a table, you need to look through everything until you find what you want.

You also have indexes. An index is a sorted list of rows in a table. It contains a small subset of the table’s data, just enough to sort the data and point to the real data rows in the real table. So, when you want to find something in a table, you look at a suitable index, not the table. The index will point to the rows of the table that match what you are looking for.


9.Monitor ur rails app performance using tools like RPM,Production Log Analyzer (http://rails-analyzer.rubyforge.org/pl_analyze/),clientperf(http://austinentrepreneur.wordpress.com/2008/06/21/announcing-clientperf-simple-client-side-rails-performance/)

10.Also check for any memory leak in ur application since ruby is prone to it.

3 comments:

maddy said...

just now , i saw ur web site........very nice description for performace in rails application.

Unknown said...

Ayyo yo iva oru dubaakur don belive his words..

King Bell said...

Inimel train lam fast a poguma sir