A Simple Way To Increase The Performance Of Your Rails App


Developing a application and optimizing its performance should go hand in hand but mostly the due to achieve the deadlines and complete the features in a project the scope of optimization reduces and the optimization is kept for the end (which is not a good practice) and other factor such as lack of experience and substandard coding also lead to decrease in the performance.

There are many way to increase the performance and code your application, it is a vast topic and subjective to the application your are development will be discussing small changes that can be done, which will change performance and improve it.

The main areas to concentrate to improve you app performance while developing :

  1. Database optimization and Query optimization
  2. JavaScript, CSS optimization

Lets concentrate on database optimization and here are few quick tips (again these are basic tweaks which we feel should be applied & are subjective to applications and developers)

  • Maintaining proper indexing for required tables in the db (don’t over do indexing ,it may also lead to lowering performance. You can decide this on case to case basis)
  • Maintaining proper relation and association between models also is major factor effecting the app performance and proper utilization of association will increase the performance.
  • Fetch only when it is required and only what is required and reuse the fetched data from the db as much as possible.
  • Optimize the query by limiting the data fetched and fetch data in batches for large amount of data.
  • Database caching can be used to reduce the response time and number of queries . We can achieve it by implementing memcached and dalli gem.
  • Do not write queries in loop, Its the biggest Don’t do while coding. .If its already done find a way to rewrite that part of code and avoid the calling query in a loop situation.

These are the few point can be looked in to for optimizing the rails application. We would also recommend Bullet gem in development which is very useful to reduce N+1 queries in application .

The project is available on GitHub: http://github.com/flyerhzm/bullet
If you have any other pointers to add to this, feel free to comment. We shall take them while writing our next set of articles.

Source: RailsCarma

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s