high performance php & mysql scaling techniques
TRANSCRIPT
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
1/30
High Performance PHP& MySQL Scaling Techniques
Elliott White III Elidigg.com
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
2/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
What's all this then?
Introduction
Standard Solution
Quick PHP Solutions
APC User Variables
Memcached
Purpose Driven Database Servers
Database Partitioning
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
3/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
Introduction
Performance is a problem
Scaling your performance is a bigger problem
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
4/30Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
Standard Solution
How most people setup a basic solution that scales 'so far'.
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
5/30Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
Standard Solution
Many PHP Servers behind a load balancer:
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
6/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
Standard Solution
Many MySQL slaves, talking to a master:
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
7/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
Standard Solution
Randomized or 'planned' PHP to MySQL relations
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
8/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
Quick PHP Solutions
A number of things that will speed up PHP,
if that is your bottleneck.
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
9/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
Use an opcode cache
PHP by default recompiles every page, every request.
APC (Alternative PHP Cache)
http://pecl.php.net/package/APC
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
10/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
Stop using PHP
Specifically move to faster server software, suchas thttpd for static HTML pages, images, etc.
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
11/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
Pregenerate Content
If pages do not need to be instantly updated,generate them on a regular basis.
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
12/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
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.
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
13/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
APC User Variables
What is it?
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
14/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
APC User Variables Pros & Cons
Advantages:
Allows complicated processing to be done once.
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.
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
15/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
Memcached
What is it?
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
16/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
Memcached Performance gains
Caching certain chunks of data that might be used
on many different pages.
From that, still being able to dynamically create
the page, but using some cached data.
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
17/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
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.
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
18/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
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
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
19/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
Creating Generic Memcached Solutions
Create generic/abstract system (classes) to hideconnections, load balancing, fail over, and server farmaspects for you.
You only ever say 'store' or 'retrieve'
Next Step: Create a system (classes) to even abstractthat further. To completely hide how the data is stored,
retrieved, and cached. You just 'ask for the data', and the classes handle
everything.
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
20/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
Purpose Driven MySQL Pools
Creating separate slave pools, that are close toidentical in order to isolate high database load.
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
21/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
Purpose Driven Pool Example
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
22/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
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)
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
23/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
Pros & Cons of Partitioning
Pros
Greater performance
Tweakable / Scalable
Cons
Loss of direct SQL support
Increased PHP load
Complicated programming
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
24/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
Main Types of Partitioning
Horizontal Vertical
Application Level
Discussion topic: Partitioning within same database
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
25/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
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
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
26/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
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
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
27/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
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
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
28/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
Generic code to handle partitioning
Coding to partitions can get complicated.
Make a set of functions/classes that understandthe shards so that you don't have to.
Your code, again, should only be concerned with:
Give me the data!
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
29/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
Digg is Hiring!
Digg.com is hiring experienced PHP programmers!
http://digg.com/jobs
-
8/14/2019 High Performance PHP & MySQL Scaling Techniques
30/30
Oct 9, 2007 High Performance PHP & MySQL Scaling Techniques
Any Questions?
For this presentation and more:
http://eliw.com/
Visit http://digg.com/