2009年4月29日 星期三

Advanced Rails , Database Chapter memo(4)

Magic Multi-Connections
這樣也有辦法讀寫分離!!
Magic Multi-Connections gem allows you to connect to different databases concurrently
from the same application. This is very useful when using one master and several
read-only slaves serving the same models.

For a single-master situation, you could define another database connection in
database.yml for the read slave:
This database is backed by a module, which mirrors the ActiveRecord classes using
this database connection:



Caching
用memcache 啦, 這邊推薦的是用 acts_as_cached plugin



Load Balancing and High Availability

Load balancing
Spreading request load over several systems so as to reduce the load placed on a
single system.

High availability
Resiliency to the failure of one or several constituent components; the ability to
continue providing services without interruption despite component failure.


MySQL
Replication

Master-slave replication works well for load balancing in applications
where reads outnumber writes, since all writes must be applied to the master.

However, master-slave replication as described does not provide high availability;
there is a single master that is a single point of failure.

The MySQL documentation suggests setting up a dynamicDNS entry pointing to the current master; however, this will introduce another potential failure point.


MySQL cluster
The primary high-availability solution for MySQL is the MySQL Cluster technology,
available since version 4.1. Cluster is primarily an in-memory database, though as of
version 5, disk storage is supported. The Cluster product is based on the NDB storage
engine, backed by data nodes.

For high availability, at least three physical servers must be used: two data nodes and
a management node. The management node is needed to arbitrate between the two
data nodes if they become disconnected and out of synchronization with each other.
A replication factor of 2 is used, so the two data nodes must each have enough memory
to hold the working set, unless disk storage is used.



LDAP
LDAP, the Lightweight Directory Access Protocol, is a database system optimized for
user directory information. It is most often used in large organizations, integrated
with the enterprise authentication and email systems. However, it is a database in its
own right. We do not have space to cover LDAPin detail, but there are many
resources available for working with LDAP in Rails.

ActiveLDAP
The ActiveLDAPlibrary (http://ruby-activeldap.rubyforge.org/) is an almost drop-in
replacement for ActiveRecord that uses LDAPinstead of an RDBMS as a backend.

沒有留言: