Database loadbalancing outside rails application? - ruby-on-rails

I want to make a master/slave setup on my postgresql servers. My problem is how I can get queries from my rails app balanced to the databases? I can't use a gem like Octopus, because it collides with my use of the Apartment gem (both modifies ActiveRecord) inspired by this rails cast. Does anyone know of a way to load balance outside the rails app?

You may consider using pgPool that allows distribution of SELECT request across a pool of servers.

PgBouncer efficiently supports both connection pooling and simple load balancing.

Related

How to use multiple databases for Rails server?

I have a Rails application which is using PostgreSQL database and a huge user base is expected. Is there a way to use multiple databases, may be one database for Read operations and other for Write operations.
Any suggestions/solution?
You can achieve it via database clustering. Master database and slave database. Try using amazon RDS or Heroku services.
Use database sharding. Try using Master and slave databases.
Octopus is a really useful gem for that. https://github.com/thiagopradi/octopus

How to setup new Redshift database with Heroku/Rails 4 app

I have been using Heroku-postgres as my database for my rails 4 app deployed to Heroku.
I connect to the DB locally using pgAdmin3, and haven't had any issues.
Now, I want to switch my database to a amazon-redshift instance which has been spun up for me. All I have is a username, password, and the database host name. Where do I store this information within my Rails 4 app so that my app will use this DB instead of the current postgres DB?
I provided a similar answer here, but I would recommend using this adapter to connect:
https://github.com/fiksu/activerecord-redshift-adapter
This certainly works well for any ActiveRecord query you need to do, I'm using insert statements to update redshift tables rather than ActiveRecord create. Working on a full redshift adapter, hopefully to be released in the next few weeks.
Here's the answer I've given in the past with code examples about halfway down:
How can I build a front end for querying a Redshift database (hopefully with Rails)
Heroku will need to support Redshift as a database option for you, otherwise you'll need to spin up your own stack.
It might be worthwhile checking out AWS EBS service to do this.

Is it possible to share a common Neo4j db by two Rails apps, each using Neography?

While using the Neography gem to implement a Neo4j database on a Rails app, it so appears that the database is local to that particular Rails app's embedded Neo4j server. I wish to share a common Neo4j DB between two Rails apps, just the way you could do with a MySQL database through entries into database.yml. Is this impossible while using Neography? If so, what could be my possible alternatives which don't involve JRuby(i.e. using neo4j.rb).
Neography is a wrapper to query a neo4j server through the REST protocol. In that case, you should be able to query from anywhere you want, once you have started the server, even with a simple curl command.
You want especially to uncomment this line in conf/neo4j-server.properties if your apps are on 2 different servers :
org.neo4j.server.webserver.address=0.0.0.0
Make sure however to protect your database, you can read here how to : http://docs.neo4j.org/chunked/stable/security-server.html

Scaling a Rails application on EC2. Is this the right way?

So I have a Rails application. It currently runs separate as front-end and back-end + database.
I need to scale it to have several back-end servers.
The backend server has Resque background workers running (spawned by user front-end requests). It also relies heavily on callbacks.
I am planning the following setup:
|front-end| --- |load-balancer (haproxy or AWS ELB)| --- Server 1 ---- Postgresql Database (+++ other DBs added via replication later if needed)
\___ Server 2 ---/
++ (other servers added in the same fashion later )
I have concerns about how to deal with putting Database on a separate machine in this case.
1) I intend to create a new empty Rails app with schema identical to initial back-end. Have it running and accepting updates / posts via HTTP and keep connected via remote SSH (to trigger :after_commit callbacks in back-end). Is it a bettergood idea?
2) I am using Postgresql and intend to switch to an enterprise DB once the need arises. Currently the need is to scale the part of back-end that does processing not the database.
3) Does this approach seem scalable?
I'm not sure I really understand your question. Generally in production applications the database layer is separate from the application layer. I can't quite tell if this pertains to you, but it's definitely an interesting watch. http://vimeo.com/33263672 . It talks about using a redis layer between the rails and db layers to facilitate queuing, and creating a zero downtime environment. It seems like it would be a better solution than using a second rails stack? I think it should look something like this;
|ELB| Web Servers |ELB| Application Servers |RRDNS| Redis Servers | PostGreSQL Servers |
If I am understanding your meaning. If not, that video link is still worth a watch :)

What databases should I use with Ruby on Rails, based on current Hosting services?

I've been looking for hosting services and I still don't know what kind of database is the most commom. It seems to be MySql and PostgreSql.
So, I'm not sure about how much traffic and data my website will have (it's just a project), but I would like to be prepared. I've worked in some projects with Oracle (PL/SQL) and I know something from MySql.
Thank you !
ps. 4 years later, I've been coding RoR mostly with PostgreSQL. SQLite by default when I need simple apps, but PostgreSQL otherwise.
One of the tenets of Rails is you shouldn't really care what database you're using: that's all abstracted for you.
So I would say go with the hosting provider that seems the overall best, and trust them to pick a good database.
In this case, as house9, I would recommend Heroku as an excellent overall service. Start with a small, free plan, scale up as needed. They use PostgreSQL by default, which has been entirely adequate in my experience.
I recommend Heroku for hosting
they require Postgres or if you want to go 'NoSql' - you can use MongoDB via the MongoHQ Heroku plug-in
http://heroku.com/
they offer a 'free' plan for small sites
Engine Yard is a trusted Rails host. They support MySQL, Postgres and MongoDB. Here is their list of supported technologies:
http://www.engineyard.com/technology/stack
On May 10th, they are hosting a demo on their cloud services.
MySQL is by far the most common free web database now a days, and is very common in Ruby on Rails Projects. Almost all linux hosting providers will give you mysql databases. Unless you have a specific reason to go elsewhere, it is a great place to start.
I have personally implemented a couple of RoR projects that used MySQL as the backend with no complaints.
I don't think there is any argument that MySQL is the most used. If you re looking for an enterprise class database, I say give DB2 a try. Just like MySQL, DB2 Express-C is free and optional support is available. DB2 is the only database that has support from the vendor. See http://antoniocangiano.com/2010/04/22/rails-db2-and-the-enterprise/.

Resources