High performance WordPress

36
High Performance WordPress with your host: Mikel King Caching, Clustering & Tuning http://j.konex.us/ mk-twttr http://j.konex.us/ mk-plus http://linkd.in/in -mk

description

The Deck from my presentation at WordCamp NYC 2014.

Transcript of High performance WordPress

Page 1: High performance WordPress

High Performance WordPress

with your host: Mikel King

Caching, Clustering & Tuning

http://j.konex.us/mk-twttr http://j.konex.us/mk-plus http://linkd.in/in-mk

Page 2: High performance WordPress

Scaling WordPress

High Performance WordPress by @MikelKing http://jafdip.com

Page 3: High performance WordPress

● PHP Apps like WordPress don’t scale = LIES!

Scaling WordPress

High Performance WordPress by @MikelKing http://jafdip.com

Page 4: High performance WordPress

● PHP Apps like WordPress don’t scale = LIES!● PHP is not JAVA so Big IRON = FAIL

Scaling WordPress

High Performance WordPress by @MikelKing http://jafdip.com

Page 5: High performance WordPress

● PHP Apps like WordPress don’t scale = LIES!● PHP is not JAVA so Big IRON = FAIL● Caching + DB Clustering + Apache Tuning

= Success!

Scaling WordPress

High Performance WordPress by @MikelKing http://jafdip.com

Page 6: High performance WordPress

User level --

Files System --

Memory Resident --

Browser

Caching Plugins

Memcache

Realms of Caching

High Performance WordPress by @MikelKing http://jafdip.com

Page 7: High performance WordPress

● Is easy to turn on and easier to fail.● Requires access to Apache conf

&& ! .htaccess● Requires proper WordPress CSS & JS

registration and enqueuing

Browser Caching

High Performance WordPress by @MikelKing http://jafdip.com

Page 8: High performance WordPress

Apache Conf Example

# 480 weeks

<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">

Header set Cache-Control "max-age=290304000, public"

</FilesMatch>

# 2 DAYS

<FilesMatch "\.(xml|txt)$">

Header set Cache-Control "max-age=172800, public, must-revalidate"

</FilesMatch>

# 2 HOURS

<FilesMatch "\.(html|htm)$">

Header set Cache-Control "max-age=7200, must-revalidate"

</FilesMatch>

High Performance WordPress by @MikelKing http://jafdip.com

Page 9: High performance WordPress

wp_register_script( 'top-menu', $this->js_template_url . 'top_menu.js', null, self::VERSION, self::IN_HEADER ); wp_enqueue_script('top-menu');

Asset Registration

High Performance WordPress by @MikelKing http://jafdip.com

Page 10: High performance WordPress

● Easy to setup● Good for shared hosting● NOT load balancer friendly● Plugins are written in PHP● Does NOT reliably cache DB Objects● Relies on file system access

File System Caching

High Performance WordPress by @MikelKing http://jafdip.com

Page 11: High performance WordPress

The Caching GameHigh Performance WordPress by @MikelKing http://jafdip.com

Page 12: High performance WordPress

W1 ServerHigh Performance WordPress by @MikelKing http://jafdip.com

Page 13: High performance WordPress

W3 ServerHigh Performance WordPress by @MikelKing http://jafdip.com

Page 14: High performance WordPress

W2 ServerHigh Performance WordPress by @MikelKing http://jafdip.com

Page 15: High performance WordPress

M1 ServerHigh Performance WordPress by @MikelKing http://jafdip.com

Page 16: High performance WordPress

M3 ServerHigh Performance WordPress by @MikelKing http://jafdip.com

Page 17: High performance WordPress

M3 ServerHigh Performance WordPress by @MikelKing http://jafdip.com

Page 18: High performance WordPress

M2 ServerHigh Performance WordPress by @MikelKing http://jafdip.com

Page 19: High performance WordPress

W4 ServerHigh Performance WordPress by @MikelKing http://jafdip.com

Page 20: High performance WordPress

Example of DB runaway

High Performance WordPress by @MikelKing http://jafdip.com

Page 21: High performance WordPress

● Stores PHP code as compiled objects● Capable of caching DB queries as objects● May be clustered● Is load balancer friendly

Memory Based Caching

High Performance WordPress by @MikelKing http://jafdip.com

Page 22: High performance WordPress

Example of a memcache cluster

define('WP_CACHE', true);

$memcached_servers = array( 'default' => array( '172.16.1.244:11211', '172.16.1.229:11211', '172.16.1.195:11211', '172.16.1.227:11211', '172.16.1.218:11211’, '172.16.1.205:11211’ ));

High Performance WordPress by @MikelKing http://jafdip.com

Page 23: High performance WordPress

Example of a memcache cluster

memcache-top v0.6 (default port: 11211, color: on, refresh: 3 seconds)

INSTANCE USAGE HIT % CONN TIME EVICT/s READ/s WRITE/s 172.16.1.244:11211 0.9% 94.5% 146 3.5ms 0.0 30.2K 308.0K 172.16.1.229:11211 33.1% 98.2% 148 1.9ms 0.0 33.1K 253.3K 172.16.1.195:11211 39.0% 97.2% 148 2.2ms 0.0 22.4K 217.8K 172.16.1.227:11211 32.2% 98.7% 148 2.1ms 0.0 128.5K 975.1K 172.16.1.218:11211 0.0% 0.0% 10 2.1ms 0.0 2 276 172.16.1.205:11211 36.3% 90.8% 148 2.1ms 0.0 25.2K 223.8K

AVERAGE: 23.6% 79.9% 124 2.3ms 0.0 39.9K 329.7K

TOTAL: 0.7GB/ 3.0GB 748 14.0ms 0.0 239.4K 1.9M

High Performance WordPress by @MikelKing http://jafdip.com

Page 24: High performance WordPress

Example of a DB on memcache

High Performance WordPress by @MikelKing http://jafdip.com

Page 25: High performance WordPress

Memcache is a separate service to manage

Corruption can spread like a virus

Clearing the cache requires shutting down the entire cluster

Caveats (It’s NOT all sunshine and rainbows)

High Performance WordPress by @MikelKing http://jafdip.com

Page 26: High performance WordPress

● Convert ALL tables to InnoDB● Convert ALL collation to UTF-8● Set innodb_buffer_pool_size = 70-80% of

total DB server available RAM● Set thread_cache_size = 4096● Increase the mysql ulimits

Clustering with HyperDB

High Performance WordPress by @MikelKing http://jafdip.com

Page 27: High performance WordPress

Full text search is supported in the InnoDB engine as of MySql 5.6, prior to this only the MyISAM engine had this feature.

InnoDB became the default storage engine in MySql 5.5 and that prior to this version you must compile it in as an optional item.

Caveats

High Performance WordPress by @MikelKing http://jafdip.com

Page 28: High performance WordPress

Debian/Ubunutu Ulimits

Excerpt: /etc/security/limits.conf

mysql soft nofile 10240mysql hard nofile 40960mysql soft nproc 10240mysql hard nproc 40960

High Performance WordPress by @MikelKing http://jafdip.com

Page 29: High performance WordPress

FreeBSD Ulimits

Excerpt: /etc/login.conf

daemon:\ :memorylocked=64M:\ :memoryuse=unlimited:\ :tc=default:

High Performance WordPress by @MikelKing http://jafdip.com

Page 30: High performance WordPress

Windows Ulimits

High Performance WordPress by @MikelKing http://jafdip.com

Page 31: High performance WordPress

Master$wpdb->add_database(array( 'host’ => '172.16.1.7:3336', 'user’ => 'db_admin', 'password’ => 'My$c3r3t', 'name’ => 'prod_db', 'write’ => 1, 'read’ => 1, 'dataset’ => 'global', 'timeout’ => 0.2, 'lag_threshold’ => 2,));

Slave$wpdb->add_database(array( 'host' => '172.16.1.9:3336’, 'user' => 'db_admin', 'password' => 'My$c3r3t', 'name' => 'prod_db', 'write' => 0, 'read’ => 1, 'dataset’ => 'global', 'timeout’ => 0.2, 'lag_threshold’ => 2,));

HyperDB Conf (db-config.php)

High Performance WordPress by @MikelKing http://jafdip.com

Page 32: High performance WordPress

● Eliminate file reads.● Reduce the number of server limit● Increase the allocated RAM● Install mod_deflate● Install mod_gzip2

Tuning Apache

High Performance WordPress by @MikelKing http://jafdip.com

Page 33: High performance WordPress

House Keeping

Use the PHP native filter_var & filter_input in lieu of regex and built-in WordPress methods

Drop WP & plugin based Search in favor of a search service

• Solr (requires a separate Java based server)• Sphinx (is a separate service• Elastisearch (requires a separate Hadoop server)• GSS ( a.k.a. Google Site Search)

Enterprise Environments

High Performance WordPress by @MikelKing http://jafdip.com

Page 34: High performance WordPress

General House Keeping

● Cleanout the functions.php● Turn off unnecessary auto loaded items in wp_options● Optimize your database with a plug-in like WP Optimize● Leverage the power of a CDN to eliminate your serving

environment’s latency issues.

These items apply sites of any size even if you are on shared hosting

High Performance WordPress by @MikelKing http://jafdip.com

Page 35: High performance WordPress

This has been

High Performance WordPress

with your host: Mikel King

Caching, Clustering & Tuning

http://j.konex.us/mk-twttr http://j.konex.us/mk-plus http://linkd.in/in-mk

Page 36: High performance WordPress

akhirnya

High Performance WordPress by @MikelKing http://jafdip.com