Yii Framework Forum: Working with MySQL Read Replicas - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Working with MySQL Read Replicas Rate Topic: -----

#1 User is offline   NicoPli 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 23-January 11

Posted 04 August 2012 - 05:51 AM

Hi, I am using Yii on Amazon Web Services. We are continuously improving the Code to make the site faster, as we are working with big data. However, we are at a point where this all does not make any sense anymore and we need to start using RDS Read Replicas.
Basically our users perform just find functions on the database and just a few write functions (logging, settings, no big data). What I was thinking about is to extend the CActiveRecords Class and use the beforeFind method to connect to the Read Replica, when ever a write functions is called, use beforeSave to connect to the original database.

My question now is, if you guys think this could work or maybe if you have a better idea (Cronjobs, both read and write, will be constantly connected to the original). And I need to know how to setup extra database connections (from config file) in Yii which are active to the same time. I don't want to open and close the connections all the time, but to have both open, or open it to the first time it is used, and just tell Yii which one it should use to make the next query.

Thanks!
0

#2 User is offline   MetaYii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 393
  • Joined: 07-October 08
  • Location:The Matrix

Posted 18 August 2013 - 12:55 AM

View PostNicoPli, on 04 August 2012 - 05:51 AM, said:

Hi, I am using Yii on Amazon Web Services. We are continuously improving the Code to make the site faster, as we are working with big data. However, we are at a point where this all does not make any sense anymore and we need to start using RDS Read Replicas.
Basically our users perform just find functions on the database and just a few write functions (logging, settings, no big data). What I was thinking about is to extend the CActiveRecords Class and use the beforeFind method to connect to the Read Replica, when ever a write functions is called, use beforeSave to connect to the original database.

My question now is, if you guys think this could work or maybe if you have a better idea (Cronjobs, both read and write, will be constantly connected to the original). And I need to know how to setup extra database connections (from config file) in Yii which are active to the same time. I don't want to open and close the connections all the time, but to have both open, or open it to the first time it is used, and just tell Yii which one it should use to make the next query.

Thanks!


Hi, I know this is rather old post, but I'm in the very same situation. Replicas are no problem, since RDS takes care of them automagically, just create one or the master and that's all. But the Yii part is the interesting one. Was it possible?
Ah! on-off, simplement!
0

#3 User is offline   nineinchnick 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 622
  • Joined: 12-September 11
  • Location:Bialystok, Poland

Posted 18 August 2013 - 02:28 AM

Overload the getDbConnection method in your model and put there logic which would choose the connection. See the source code for reference how it reads the default connection.
Remember you can't do eager loading between models that are using different db connections.
Don't be a dick.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users