Friday, February 5, 2010

How To Run My Rails Application Without Database?

A day before haven't tried or had thought about how to disable DB connection when the rails application loads, but unfortunately one of my colleague asked me "Hey, How To Run My Rails Application Without Database?". So i worked on this to get myself aware of this scenario.

Before you understand, ask yourself "Why do you want to disable a DB for rails application?" Obviously the answer will be, Some sites doesn't need DB actually, So i will let you guys see what i did for this scenario, Actually we have two ways to do.

First and Simple Way of Disabling DB:
on 21st line of /config/environment.rb uncomment.
config.frameworks -= [ :active_record, :active_resource, :action_mailer ]


Second way of Disabling DB:
First Step:
#config/environment.rb
require File.join(File.dirname(__FILE__), 'boot')


Second Step:
class MyInitializer < Rails::Initializer
def initialize_database
if configuration.frameworks.include?(:active_record)
ActiveRecord::Base.configurations = configuration.database_configuration
## uncomment the next line to automatically establish the connection
# ActiveRecord::Base.establish_connection
end
end
end

Third Step:
#now, instead of `Rails::Initializer.run ...` do this
MyInitializer.run do |config|
# ...
end

That is it. Now you can run your rails application without DB Connection.
Hope this helps you, pls do a comment

Thanks,
Bala, Anubavam Technologies.

Tuesday, December 22, 2009

Ruby Component and Mysql Sharding.

Ruby Component and Mysql Sharding.

Scaling the Enterprise Application Using the Ruby component,Mongrel Handlers and Mysql Sharding.


Some of the enterprise application shouldn't scale with rails engine,which is occupies more RAM space and we need to run more rails instance to handle the more request.

For this case we have option to use ruby components,Mongrel handlers not a rails mongrel server and Mysql Sharding.

When we compare the memory space of the rails mongrel servers and mongrel handlers.The mongrel handlers occupies less RAM space relatively 40% less then the rails mongrel servers.


This mongrel handlers will accept the request from the outside world and we can redirect to our ruby component to do our business logic and save it in the database.

When we come to the Mysql Sharding,which means we are saving the records in the different database and mysql physical servers.So it will give you more efficient way of saving records with the less configuration physical servers and help you for cost of the servers.

Using this method of saving datas in the database will give you tremendous amount of capacity.

While generating the reports or analytics for the saved data we should have the seperate ruby component which read the shard database and generate the reports as per our requirement.


In this way we can achive more capable of handling request through the mongrel handlers and using ruby component which is pure core level of code which give you more performance compare to handling the request through the Rails Engine which basically do dipatch to controller and action and then return the results.

And the Mysql sharding also will help you to handle the large number of datas and generating the reports.


Comparing the Rails Mongrel Servers and Mongrel Handlers.

-Rails Mongrel Servers Instance occupy RAM Space of - 150 mB

-Mongrel Handlers occupy RAM Space of - 90 mB

Comparing Accepting Request through Rails Mongrel Servers and Mongrel Handlers.

-Rails Mongrel Servers Instance will handle the single request at a time.

-Mongrel Handlers will handle more then 10-15 request at a time.

Comparing Normal Mysql and Mysql Sharding.

-Noraml Myql can handle only limited records and it will get hang when the record get larger and larger.

-In Sharding of Mysql will have the capability to handle more datas.Because it saves the datas in different databse and different physical servers.

Comparing Ruby Component and Rails Engine.

- When we are calling the pure Ruby component and Ruby DBI which is direct coding gives you performance to do the business logic for large entrerprise application.

-When we are using the rails engine it basically do the ground work like dipatching to controller and interact to the model and finally fetch the results.which have lot of work to do and it will affect the performance.

Basic Understanding of the above discussion:

1.When we are looking for the web application like displaying the pages and fetch the values based on the user interaction we have to go for the Rails.

2.When we are looking for background process like handling the process asychronously and managing the massive amount of datas in mysql we can go for the ruby component,mongrel handlers and shard mysql.