05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

MySQL replication<br />

Sometimes the database server is the bottleneck—many simultaneous queries can bog<br />

down a database server, resulting in sluggish performance. Replication is the solution.<br />

Take everything that happens to one database and quickly bring one or more<br />

other databases in sync, so you end up with multiple identical databases. This lets you<br />

spread your queries across many database servers instead of loading down only one.<br />

The most effective model is to use one-way replication, where you have a single master<br />

database that gets replicated to a number of slave databases. All database writes<br />

go to the master server, and database reads are load-balanced across multiple slave<br />

databases. This technique is aimed at architectures that do a lot more reads than<br />

writes. Most web applications fit this scenario nicely.<br />

Figure 13-4 shows the relationship between the master and slave databases during<br />

replication.<br />

Figure 13-4. Database replication<br />

Many databases support replication, including MySQL, PostgreSQL, and Oracle.<br />

Putting it all together<br />

For a really high-powered architecture, pull all these concepts together into something<br />

like the configuration shown in Figure 13-5.<br />

Figure 13-5. Putting it all together<br />

Master<br />

Slave Slave Slave<br />

Apache 1<br />

MySQL slave<br />

Squid cache<br />

redirector<br />

Apache 2<br />

MySQL slave<br />

Master MySQL<br />

server<br />

Apache 3<br />

MySQL slave<br />

Using five separate machines—one for the reverse proxy and redirector, three web<br />

servers, and one master database server—this architecture can handle a huge number<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.<br />

Performance Tuning | 315

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!