WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search


Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - השוואת מחירים בסופר
ZeroLag.com
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this Article to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES SUBMIT AN ARTICLE PRINT
Title : Scaling a PHP MySQL Web Application, Part 2
Categories : PHP, Databases, MySQL
Eli White - ORACLE.com
Eli White - ORACLE.com
Date : 2011-05-01
Grade : 3 of 5 (graded 5 times)
Viewed : 5160
Search : More Articles by Eli White - ORACLE.com
Action : Grade This Article
Tools : My Favotite Articles


Submit your own code examples 
 


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 aren’t 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