Quantcast
Channel: AndolaSoft » Rails Development
Viewing all articles
Browse latest Browse all 5

Simple Ways to Keep Rails Database Optimized

$
0
0

Database is the most crucial component to every Rails application. Each visit to the Rails app can cause one or even hundreds of database queries. On top of that considering the number of visitors per day and the number of pages each visitor hits, it can be concluded that database optimization is very crucial to Rails web-app hosting. Here I have mentioned some simple steps to optimize Rails database.

Andolasoft_Ruby on rails

Reducing the number of queries:

One of the easiest ways to optimize Rails database is by reducing the number of queries it uses. If it is possible to remove codes which aren’t necessary or performing tasks in one query instead of two, can improve the web-app’s response time to a great extent. Rails even makes it easier by providing the ‘include’ option in Active Record.

Proper Database Indexes

Having proper database indexes for the tables will assist in improving the performance when searching, grouping and sorting. By default rails adds indexes to the primary keys where as the rest indexes are added manually. Indexes can be added to all foreign keys, type columns that are searchable.

Implementing ActiveRecord

Rails framework is featured to make it easier for the programmer to develop Ruby apps efficiently and with much ease. The Rails database library, ActiveRecord, offers numerous options which can be set to improve certain queries. Optimizing individual queries can be tough and time consuming but it offers better performance than optimizing all queries at a time. Some time Rails generates database queries that are too complex and needs improvement. In such cases ‘SQL explain’ command should be used to see which queries are slow and why. Then the queries can be re-written with raw SQL statements, avoiding the ActiveRecord.

Every Ruby on rails developer should consider database optimization as crucial and take necessary steps to curve any such issues.



Viewing all articles
Browse latest Browse all 5

Trending Articles