+ All Categories
Home > Technology > High Performance Php My Sql Scaling Techniques

High Performance Php My Sql Scaling Techniques

Date post: 13-Dec-2014
Category:
Upload: zendcon
View: 6,151 times
Download: 1 times
Share this document with a friend
Description:
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.
29
High Performance PHP & MySQL Scaling Techniques Eli White http://eliw.com/
Transcript
Page 1: High Performance Php My Sql Scaling Techniques

High Performance PHP & MySQL Scaling Techniques

Eli Whitehttp://eliw.com/

Page 2: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

What's all this then?

● Introduction

● Standard Solution

● Quick PHP Solutions

● APC User Variables

● Memcached

● Purpose Driven Database Servers

● Database Partitioning

Page 3: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

Introduction

Performance is a problem

Scaling your performance is a bigger problem

Page 4: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

Standard Solution

How most people setup a basic solution that scales 'so far'.

Page 5: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

Standard Solution

Many PHP Servers behind a load balancer:

Page 6: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

Standard Solution

Many MySQL slaves, talking to a master

Page 7: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

Standard Solution

Randomized or 'planned' PHP to MySQL relations

Page 8: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

Quick PHP Solutions

A number of things that will speed up PHP, if that is your bottleneck.

Page 9: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

Use an opcode cache

PHP by default recompiles every page, every request.

APC (Alternative PHP Cache)http://pecl.php.net/package/APC

Page 10: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

Stop using PHP

Specifically move to faster server software, such as thttpd for static HTML pages, images, etc.

Page 11: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

Pregenerate Content

If pages do not need to be instantly updated, generate them on a regular basis.

Page 12: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

Cache content

Half-way between dynamic and pregenerated.

Cache it as you create it.

Example: jpcachehttp://www.jpcache.com/

Or Smarty does this for you.

Page 13: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

Memcached

What is it?

Page 14: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

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.

Page 15: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

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.

Page 16: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

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

Page 17: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

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.

Page 18: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

APC User Variables

What is it?

Page 19: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

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.

Page 20: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

Purpose Driven MySQL Pools

Creating separate slave pools, that are close to identical in order to isolate high database load.

Page 21: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

Purpose Driven Pool Example

Page 22: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

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)

Page 23: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

Pros & Cons of Partitioning

Pros● Greater performance● Tweakable / Scalable

Cons● Loss of direct SQL support● Increased PHP load● Complicated programming

Page 24: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

Main Types of Partitioning

Horizontal Vertical

Application Level

Discussion topic: Partitioning within same database

Page 25: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

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

Page 26: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

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

Page 27: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

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

Page 28: High Performance Php My Sql Scaling Techniques

The Knight Rider Methodology to Software Development Eli White - ZendCon 08 - 9/17/2008

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!

Page 29: High Performance Php My Sql Scaling Techniques

Any Questions?

For this presentation & more:

http://eliw.com/


Recommended