3

I am using Amazon's RDS. I have a single database, and we are getting fairly heavy traffic. I already scaled our EC2 instances without any issues, it's been working great, but I want to loosen the database load by creating:

1 - Write database
2 - Read databases

Obviously, I will have to have multiple connections going on in my script, and reading from one and writing to one is easy enough, but what is the logic for load balancing multiple read databases?

Is there something in Amazon I can setup to do this? Like the load balancing for EC2? Or is this something I have to setup within my scripts automatically?

Technically, I may NOT need 2 read db instances at this time, but surely this is a common thing, right? I would assume this would need to be done, and I was curious about the architecture.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
rckehoe
  • 1,198
  • 15
  • 16
  • Have you tried using caching for any of this to make things run better? CodeIgniter's built in caching is kind of 'meh', but Phil Sturgeon did write another caching piece that sounded much better (it would allow you to cache certain pieces of a page rather than the whole page). I'll be curious to see what others have to say on this. – Christian D. Jan 27 '14 at 17:54
  • Possible duplicate of [Has anyone figured out how to scale Amazon RDS read replicas?](http://stackoverflow.com/q/11835271/759866) – BenMorel Feb 02 '14 at 22:56

2 Answers2

3

Unfortunately there is no easy way of doing this. Due to the automagically managed nature of RDS, you are at the mercy of amazon and the services they provide. You have a few options though.

1. You stick with RDS and set up a round robin DNS.

This is achieved easiest through route53. You do this by creating multiple CNAME records for each of your read replicas' endpoints. eg db.mydomain.com -> somename.23ui23asdad4r.region.rds.amazonaws.com Make sure to turn on weighted routing policy and set the weight and "set ID" to the same. rinse and repeat for each read replica.

http://note.io/1agsSMB

Caveat 1: this is not a true load balancer. This is simply rolling a die and pointing each request to one of your RDS

Caveat 2: There is no way to health check your RDS instances and there is no way to auto-scale the instances either. Unless you do some crazy things with cloud watch trigger scripts to manually add and remove RDS read replicas and update route53.

2. Use a die roll in your application itself.

A really cheap and nasty approach you could try is to create a config for each of your read replicas in CodeIgniter and when you connect to the database you randomly choose one.

Caveats: Same as above but even worse as you will need to update your codeigniter config each time you add or remove a read replica.

3. Spend hours and hours porting your RDS to ec2 instances.

You move your database to EC2 instances. This is perhaps the most difficult solution as you will need to manage ALL of your database tweaking and tuning yourself. On the plus side you will be able to put them in an autoscaling group and behind an internal load balancer in your VPC

Community
  • 1
  • 1
Keegan Lillo
  • 532
  • 3
  • 6
0

RDS cluster provides you two endpoints read and write. If you send the read traffic on read endpoint, AWS will manage load balancing for all read replicas. You can also apply a scaling policy for read replicas.

These options are available for AWS Aurora clusters.

סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68