Transcript
Page 1: Performance scalability brandonlyon

PERFORMANCE & SCALABILITYWhere to Begin

Brandon Lyon

Page 2: Performance scalability brandonlyon

Performance & Scalability

Define the Objective

Page 3: Performance scalability brandonlyon

Performance & Scalability

Define the Objective Minimize HTTP

Requests

Page 4: Performance scalability brandonlyon

Performance & Scalability

Define the Objective Minimize HTTP

Requests Minimize Server

Processing

Page 5: Performance scalability brandonlyon

Performance & Scalability

Define the Objective Minimize HTTP

Requests Minimize Server

Processing Optimize Server

Processing

Page 6: Performance scalability brandonlyon

Performance & Scalability

Define the Objective Minimize HTTP

Requests Minimize Server

Processing Optimize Server

Processing Optimize the

Database

Page 7: Performance scalability brandonlyon

Performance & Scalability

Define the Objective Minimize HTTP

Requests Minimize Server

Processing Optimize Server

Processing Optimize the

Database

Page 8: Performance scalability brandonlyon

Minimizing HTTP Requests

Aggregate & Compress CSS Files

Page 9: Performance scalability brandonlyon

Minimizing HTTP Requests

Aggregate & Compress CSS Files

Aggregate JavaScript Files

Page 10: Performance scalability brandonlyon

Minimizing HTTP Requests

Aggregate & Compress CSS Files

Aggregate JavaScript Files

Image Sprites

Page 11: Performance scalability brandonlyon

Performance & Scalability

Define the Objective Minimize HTTP

Requests Minimize Server

Processing Optimize Server

Processing Optimize the

Database

Page 12: Performance scalability brandonlyon

Minimize Server Processing

Alternative PHP Cache (APC)

Memcached Varnish Cache

Page 13: Performance scalability brandonlyon

Alternative PHP Cache (APC)

Make sure you've allocated enough memory.apc.shm_segments=1

apc.shm_size=32

Check your script files on every request?apc.stat=0

Memory Fragmentation?apc.ttl=0

Page 14: Performance scalability brandonlyon

Memcached

Basic Implementation

# memcached -m 24 -p 11211 -d

$conf = array(

'memcache_servers' => array(

'localhost:11211' => 'default',

),

'memcache_bins' => array(

'cache' => 'default',

),

Page 15: Performance scalability brandonlyon

Memcached

Server Cluster?$conf = array(

'memcache_servers' => array(

host1:port => cluster,

hostN:port => cluster,

),

'memcache_bins' => array(

bin1 => cluster,

binN => cluster,

),

Page 16: Performance scalability brandonlyon

Varnish Cache

Toss your cookies!if (req.url !~ "^/blog\/.*/") {

set req.http.Cookie =

regsuball(req.http.Cookie, "comment\_.*", "");

}

Define Exceptionsif (req.url ~ "install.php|update.php") {

return(pass);

}

Page 17: Performance scalability brandonlyon

Performance & Scalability

Define the Objective Minimize HTTP

Requests Minimize Server

Processing Optimize Server

Processing Optimize the

Database

Page 18: Performance scalability brandonlyon

Optimize Server Processing

Identify the Problem

Page 19: Performance scalability brandonlyon

Optimize Server Processing

Identify the Problem

FIX IT

Page 20: Performance scalability brandonlyon

Optimize Server Processing

Identifying the Problem Areas Network Linux Apache MySQL PHP

Page 21: Performance scalability brandonlyon

Optimize Server Processing

Identifying the Problem Areas Network Linux Apache MySQL PHP

Page 22: Performance scalability brandonlyon

Optimize Server Processing

Performance Profiling Apache Benchmarking (ab) MySQL Slow Query Log & Profiling PHP Xdebug & KCachegrind

Page 23: Performance scalability brandonlyon

Apache Benchmarking (ab)

10 Concurrent Requests

100 Requests

7.35 Requests/Second 50% of Requests served in

under 1352ms

# ab -n 100 -c 10 http://d7.blyon.lan/

Page 24: Performance scalability brandonlyon

Apache Benchmarking (ab)

Compress Cached Pages Aggregate and Compress CSS files Aggregate JavaScript files

Page 25: Performance scalability brandonlyon

Apache Benchmarking (ab)

10 Concurrent Requests

100 Requests

46.32 Requests/Second 50% of Requests served in

under 213ms

# ab -n 100 -c 10 http://d7.blyon.lan/

Page 26: Performance scalability brandonlyon

Apache Benchmarking (ab)

Install APC Install APC Drupal Module

Page 27: Performance scalability brandonlyon

Apache Benchmarking (ab)

10 Concurrent Requests

100 Requests

648.77 Requests/Second 50% of Requests served in

under 12ms

# ab -n 100 -c 10 http://d7.blyon.lan/

Page 28: Performance scalability brandonlyon

Optimize Server Processing

Performance Profiling Apache Benchmarking (ab) MySQL Slow Query Log & Profiling PHP Xdebug & KCachegrind

Page 29: Performance scalability brandonlyon

MySQL Slow Query Log

/etc/mysql/my.cnflog_slow_queries = /var/log/mysql/mysql-slow.log

long_query_time = 1

# tail -f /var/log/mysql/mysql-slow.log# User@Host: root[root] @ localhost []

# Query_time: 0.000427 Lock_time: 0.000037 Rows_sent: 50

Rows_examined: 50

SET timestamp=1294541182;

select * from node;

Page 30: Performance scalability brandonlyon

Optimize Server Processing

Performance Profiling Apache Benchmarking (ab) MySQL Slow Query Log & Profiling PHP Xdebug & KCachegrind

Page 31: Performance scalability brandonlyon

PHP Xdebug & KCachegrind

Xdebug Features Stack Traces & Function Traces in Error

Messages Memory Allocation Infinite Recursion Protection PHP Profiling Code Coverage Analysis Interactive Debugging support

Page 32: Performance scalability brandonlyon

PHP Xdebug & KCachegrind

Xdebug Configuration zend_extension="/usr/local/php/modules/xdebug.so"

xdebug.profiler_enable_trigger = 1

Xdebug Usage Append ”?XDEBUG_PROFILE=1” to URL

View cachegrind compatible profile log

/tmp/cachegrind.out.10362

Page 33: Performance scalability brandonlyon

PHP Xdebug & KCachegrind

Kcachegrind Profile data Visualization tool Accepts ”Callgrind Profile” formatted data Requires KDE Libraries

Page 34: Performance scalability brandonlyon

PHP Xdebug & KCachegrind

Page 35: Performance scalability brandonlyon

Now FIX IT

Page 36: Performance scalability brandonlyon

Performance & Scalability

Define the Objective Minimize HTTP

Requests Minimize Server

Processing Optimize Server

Processing Optimize the

Database

Page 37: Performance scalability brandonlyon

Optimizing the Database

http://day32.com/MySQL/tuning-primer.sh Analyzes current my.cnf Analyzes resource usage Analyzes Caching Analyzes Tables and Queries Generates recommended my.cnf

Page 38: Performance scalability brandonlyon

PERFORMANCE & SCALABILITYWhere to Begin

Brandon Lyon


Top Related