Your SlideShare is downloading. ×
High Performance Php My Sql Scaling Techniques
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

High Performance Php My Sql Scaling Techniques

6,247
views

Published on

This talk will discuss issues and solutions when attempting to scale PHP and MySQL to high volume websites (such as digg.com). It will discuss some of the problems at hand, and go into (at a high …

This talk will discuss issues and solutions when attempting to scale PHP and MySQL to high volume websites (such as digg.com). It will discuss some of the problems at hand, and go into (at a high level) some of the solutions, such as using memcache, DB partitioning, etc. As well as how to handle these solutions within PHP.

Published in: Technology, Business

1 Comment
11 Likes
Statistics
Notes
  • Actually (Eli Here), While yes, it is possible to use apache for static content and saturate an outbound link ... what viewing these slides without my voice doesn't get into are some of the reasons for using thttpd.

    Apache+PHP makes for some heavy processes, depending on what you are doing, and your machine's in question, it's possible to run out of RAM and hit swap very quickly, because of image/etc requests coming in that don't need PHP anyway, yet require more and more RAM for new processes.

    Also, Apache+PHP can only handle so many concurrent requests before locking out future ones. If a bunch of people come to download very large static files, they can lock up all the connections, causing a very slow (or non-existant) website to your other users. Servers such as thttpd which operate in a polling fashion, instead of a process fork manner, can therefore handle many more requests for static content without hitting limits.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
6,247
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
327
Comments
1
Likes
11
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. High Performance PHP & MySQL Scaling Techniques Eli White http://eliw.com/
  • 2. What's all this then? ● Introduction ● Standard Solution ● Quick PHP Solutions ● APC User Variables ● Memcached ● Purpose Driven Database Servers ● Database Partitioning The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 3. Introduction Performance is a problem Scaling your performance is a bigger problem The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 4. Standard Solution How most people setup a basic solution that scales 'so far'. The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 5. Standard Solution Many PHP Servers behind a load balancer: The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 6. Standard Solution Many MySQL slaves, talking to a master The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 7. Standard Solution Randomized or 'planned' PHP to MySQL relations The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 8. Quick PHP Solutions A number of things that will speed up PHP, if that is your bottleneck. The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 9. Use an opcode cache PHP by default recompiles every page, every request. APC (Alternative PHP Cache) http://pecl.php.net/package/APC The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 10. Stop using PHP Specifically move to faster server software, such as thttpd for static HTML pages, images, etc. The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 11. Pregenerate Content If pages do not need to be instantly updated, generate them on a regular basis. The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 12. Cache content Half-way between dynamic and pregenerated. Cache it as you create it. Example: jpcache http://www.jpcache.com/ Or Smarty does this for you. The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 13. Memcached What is it? The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 14. Memcached Performance gains Allows complicated processing to be done once. Cache chunks of data that are used on many different pages. Still be able to dynamically create pages, but using some cached data. The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 15. Memcached Server Farm Setting up a pool of servers ● PHP Provides the basics of distributing load across servers. Taking it to the next level ● Failover protection, Redundancy, etc. The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 16. Memcached disadvantages / issues ● Coding the actual caching decisions ● Out of date / Old data ● Perpetuating slave lag ● Scaling it further / Getting the most out of caching ● Balancing the farm load The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 17. Creating Generic Memcached Solutions ● Create generic/abstract system (classes) to hide connections, load balancing, fail over, and server farm aspects for you. ● You only ever say 'store' or 'retrieve' ● Next Step: Create a system (classes) to even abstract that further. To completely hide how the data is stored, retrieved, and cached. ● You just 'ask for the data', and the classes handle everything. The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 18. APC User Variables What is it? The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 19. APC User Variables Pros & Cons Advantages: ● You already have the ability to do it. ● Local memory access, no network traffic. ● Stores data as native PHP types in local memory. Limitations: ● Data that is stored is local to that web server. ● Has to share memory resources with web server. The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 20. Purpose Driven MySQL Pools Creating separate slave pools, that are close to identical in order to isolate high database load. The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 21. Purpose Driven Pool Example The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 22. Database Partitioning What is it? Simplest Definition: Breaking up your database into a number of smaller ones. (And I'm not talking about built-in versions) The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 23. Pros & Cons of Partitioning Pros Cons ● Greater performance ● Loss of direct SQL support ● Tweakable / Scalable ● Increased PHP load ● Complicated programming The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 24. Main Types of Partitioning Horizontal Vertical Application Level Discussion topic: Partitioning within same database The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 25. Horizontal Partitioning “Moving various rows of your table into different tables” Various methodologies: ● Range Based ● Date Based ● Interlaced ● User Based ● Partial partitioning works well here The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 26. Vertical Partitioning “Moving various columns of your table into different tables” Various methodologies: ● Move rarely used columns into auxiliary table ● Move often empty columns into auxiliary table ● Move columns that are not used in where clauses The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 27. Application Level Partitioning “Moving various tables of your DB onto different servers” Various methodologies: ● Move single tables to specific servers ● Move groups of related tables together to allow joining The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 28. Generic code to handle partitioning Coding to partitions can get complicated. Make a set of functions/classes that understand the partitions so that you don't have to. Your code, again, should only be concerned with: Give me the data! The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008
  • 29. Any Questions? For this presentation & more: http://eliw.com/