|
|
|
|
| |
Scaling a PHP MySQL Web Application, Part 2
By Eli White
Tips for scaling your PHP-MySQL Web app based on real-world experiences at Digg, TripAdvisor, and other high-traffic sites. In this portion: pooling and sharding techniques.
Published April 2011
In Part 1 of this article, I explained the basic steps to move your application from a single server to a scalable solution for both PHP and MySQL. While most Web applications will never need to expand beyond the concepts presented in that article, eventually you may find yourself in a situation where the basic steps arent enough.
Here are some more advanced topics on how you might change your setup to support additional throughput, isolate concerns better, and take your scalability to the next level.
MySQL Database Pooling
Database pooling is one fairly simple technique that allows for greater isolation of concerns. . This concept involves having a group of database slaves virtually separated into multiple pools. Each pool has a specific classes of queries sent to it. Using a basic blog as an example case, we might end up with a pool distribution like this: |
|
 |
Now the obvious question at this point is: Why? Given that all the slaves in the above setup are identical, then why would you consider doing this?
The main reason is to isolate areas of high database load. Basically, you decide what queries are OK to perform more slowly. In this example you see that weve set aside just two slaves for batch processes. Typically if you have any batch processes that need to run in the background you arent worried about how fast they run. Whether it takes five seconds, or five minutes, doesnt matter. So its OK for the batch processes to have fewer resources, thereby leaving more for the rest of the application. But perhaps more important, the kinds of queries you may typically do when performing large batch processes (and the reason they are not done in real time in the first place) can be rather large and resource intensive.
By isolating these processes off to their own database slaves, your batch processes firing off wont actually affect the apparent performance of your Web application. (Its amazing how many Websites get slower just after midnight when everyone decides to run cron jobs to background-process data.) Isolate that pain and your Website performs better. Youve now created selective scalability.
The same concept can apply to other aspects of your application as well. If you think about a typical blog, the homepage only shows a list of posts. Any comments to those posts are displayed only on a permalink page. Retrieving those comments for any given post can be a potentially painful process, given there can be any number of them. Its further complicated if the site allows threaded comments because finding and assembling those threads can be intense.
Therein lays the benefit of database pooling. Its usually more important to have your homepage load extremely fast. The permalink pages with comments can be slower. By the time someone is going to load the full post, theyve committed and are willing to wait a little longer. Therefore, if you isolate a set of slaves (four in the example above) to be specific to queries about comments, you can leave the larger pool of primary slaves to be used when generating homepages. Again youve isolated load and created selective scalability. Your comment and permalink pages might become slower under heavy load, but homepage generation will always be fast.
Read More... |
|
| |
| Referer Statistics Categories : PHP, MySQL, HTTP, Databases | | | Building A Persistent Shopping Cart With PHP and MySQL Categories : PHP, MySQL, Databases, Ecommerce | | | Alternating row colors with PHP and mySQL Categories : PHP, Databases, MySQL, HTML and PHP | | | Beginners guide to PHP and MySQL Categories : PHP, Beginner Guides, Databases, MySQL, Installation | | | Custom MySQL-functions Categories : Databases, MySQL, PHP, PHP Functions | | | Watching The Web Categories : PHP, Databases, MySQL, HTTP, MD5 | | | User identification using cookies in PHP and MySQL Categories : PHP, Databases, MySQL, Cookies | | | Creating an IE-Only Database Driven Menu System With PHP, MySQL and DHTML Categories : PHP, MySQL, Databases, DHTML | | | Simple Connection to MySQL with PHP Categories : PHP, MySQL, Databases | | | Miles To Go Before I Sleep... Categories : PHP, Calendar, Databases, MySQL | | | PHP, MySQL and Authentication 101 Categories : PHP, Databases, MySQL, Authentication | | | Descriptions of Common Data Types Categories : MySQL, Databases, PHP, PHP options/info, General | | | Date Arithmetic With MySQL Categories : PHP, Databases, MySQL, Date Time | | | Building A Dynamic MySQL Paging Class With PHP Categories : PHP, Databases, MySQL | | | Time Is Money Part 1 of 2 - Designing and implementing a Web-based application Categories : PHP, Databases, MySQL, Complete Programs | |
| | |
|
|