View
5.495
Download
3
Category
Preview:
DESCRIPTION
This is a talk I gave at Northeast PHP 2013 in Boston, MA. Links: jkle.in/nephp
Citation preview
Scaling PHP to 40 Million Uniques
Northeast PHP 2013Jonathan Klein@jonathanklein
Saturday, August 17, 13
Scaling PHP to 40 Million Uniques
Northeast PHP 2013Jonathan Klein@jonathanklein
Saturday, August 17, 13
Scaling PHP to 60 Million Uniques
Northeast PHP 2013Jonathan Klein@jonathanklein
Saturday, August 17, 13
Who Am I?
Saturday, August 17, 13
Who Am I?
• Performance Engineer at Etsy
Saturday, August 17, 13
Who Am I?
• Performance Engineer at Etsy• Boston Web Perf Meetup Organizer
Saturday, August 17, 13
Who Am I?
• Performance Engineer at Etsy• Boston Web Perf Meetup Organizer• Previously at Wayfair
Saturday, August 17, 13
Who Am I?
• Performance Engineer at Etsy• Boston Web Perf Meetup Organizer• Previously at Wayfair• Led team that converted to PHP
Saturday, August 17, 13
Slides, Links:jkle.in/nephp
Saturday, August 17, 13
codeascraft.com
Saturday, August 17, 13
Some Etsy Stats
Saturday, August 17, 13
Some Etsy Stats• 1.5 billion page views/month
Saturday, August 17, 13
Some Etsy Stats• 1.5 billion page views/month• Almost $1B in sales last year
Saturday, August 17, 13
Some Etsy Stats• 1.5 billion page views/month• Almost $1B in sales last year• Over 1M lines of PHP
Saturday, August 17, 13
Some Etsy Stats• 1.5 billion page views/month• Almost $1B in sales last year• Over 1M lines of PHP• 60M+ unique visitors/month
Saturday, August 17, 13
2012 Traffic
Saturday, August 17, 13
August
2012 Traffic
Saturday, August 17, 13
August
2012 Traffic
50% Higher
Saturday, August 17, 13
Holidays:~90M Uniques
Saturday, August 17, 13
Saturday, August 17, 13
Saturday, August 17, 13
A few others...
Saturday, August 17, 13
A few others...
• Search (Solr)
Saturday, August 17, 13
A few others...
• Search (Solr)• Gearman
Saturday, August 17, 13
A few others...
• Search (Solr)• Gearman• Redis
Saturday, August 17, 13
A few others...
• Search (Solr)• Gearman• Redis• Postgres (legacy)
Saturday, August 17, 13
Saturday, August 17, 13
Hardware (Supermicro)
Saturday, August 17, 13
Hardware (Supermicro)2x 8-core Intel E5-2960 CPUs
Saturday, August 17, 13
Hardware (Supermicro)2x 8-core Intel E5-2960 CPUs
24GB of RAM
Saturday, August 17, 13
Hardware (Supermicro)2x 8-core Intel E5-2960 CPUs
24GB of RAM
160GB SSD
Saturday, August 17, 13
Apache
Saturday, August 17, 13
Apache
• Apache 2.2
Saturday, August 17, 13
Apache
• Apache 2.2• Prefork MPM
Saturday, August 17, 13
Apache
• Apache 2.2• Prefork MPM• mod_php5
Saturday, August 17, 13
Apache
• Apache 2.2• Prefork MPM• mod_php5
StartServers 30MinSpareServers 30MaxSpareServers 60ServerLimit 60MaxClients 60MaxRequestsPerChild 0
Saturday, August 17, 13
PHP
Saturday, August 17, 13
PHP
• PHP 5.4
Saturday, August 17, 13
PHP
• PHP 5.4• Zend OPCache (3GB Memory Segment)
Saturday, August 17, 13
PHP
• PHP 5.4• Zend OPCache (3GB Memory Segment)• memory_limit: 128M
Saturday, August 17, 13
PHP
• PHP 5.4• Zend OPCache (3GB Memory Segment)• memory_limit: 128M• max_execution_time: 30
Saturday, August 17, 13
Optimizing PHP
http://www.slideshare.net/jnklein/northeast-php-high-performance-php
Saturday, August 17, 13
Optimizing PHP
• See last year’s talk
http://www.slideshare.net/jnklein/northeast-php-high-performance-php
Saturday, August 17, 13
Optimizing PHP
• See last year’s talk• Use an Opcode Cache
http://www.slideshare.net/jnklein/northeast-php-high-performance-php
Saturday, August 17, 13
Optimizing PHP
• See last year’s talk• Use an Opcode Cache
• xhprof
http://www.slideshare.net/jnklein/northeast-php-high-performance-php
Saturday, August 17, 13
Optimizing PHP
• See last year’s talk• Use an Opcode Cache
• xhprof
• StatsD/Graphite
http://www.slideshare.net/jnklein/northeast-php-high-performance-php
Saturday, August 17, 13
Optimizing PHP
• See last year’s talk• Use an Opcode Cache
• xhprof
• StatsD/Graphite
• Find hotspots
http://www.slideshare.net/jnklein/northeast-php-high-performance-php
Saturday, August 17, 13
Optimizing PHP
• See last year’s talk• Use an Opcode Cache
• xhprof
• StatsD/Graphite
• Find hotspots
• Upgrade it
http://www.slideshare.net/jnklein/northeast-php-high-performance-php
Saturday, August 17, 13
Static Arrays
Saturday, August 17, 13
Translationsclass language_de {
static $translations = array( "<hash>" => array("content" => 'Accessoires', "file" => "TAXONOMY"), "<hash>" => array("content" => 'Keramik', "file" => "CATEGORY"), "<hash>" => array("content" => 'Dekorieren', "file" => "CATEGORY"), "<hash>" => array("content" => 'Getaggt %s', "file" => "Foo.php"), "<hash>" => array("content" => 'Badezusatz', "file" => "CATEGORY"), "<hash>" => array("content" => 'Datum:{% $date %}', "file" => "bar.tpl")
... snip ...
);}
Saturday, August 17, 13
Saturday, August 17, 13
Saturday, August 17, 13
Atomic Deploys
Saturday, August 17, 13
Deploying PHP
http://codeascraft.com/2013/07/01/atomic-deploys-at-etsy/
Saturday, August 17, 13
Deploying PHP
• mod_realdoc - Apache module
http://codeascraft.com/2013/07/01/atomic-deploys-at-etsy/
Saturday, August 17, 13
Deploying PHP
• mod_realdoc - Apache module• incpath - PHP Extension
http://codeascraft.com/2013/07/01/atomic-deploys-at-etsy/
Saturday, August 17, 13
Deploying PHP
• mod_realdoc - Apache module• incpath - PHP Extension• A/B symlink swap
http://codeascraft.com/2013/07/01/atomic-deploys-at-etsy/
Saturday, August 17, 13
Deploying PHP
• mod_realdoc - Apache module• incpath - PHP Extension• A/B symlink swap• Avoid recompilation to opcodes
http://codeascraft.com/2013/07/01/atomic-deploys-at-etsy/
Saturday, August 17, 13
Upgrading PHP
Saturday, August 17, 13
PHP 5.4 vs. 5.3 - CPU
PHP 5.3
PHP 5.4
Saturday, August 17, 13
PHP 5.4 vs. 5.3 - Memory
PHP 5.3
PHP 5.4
Saturday, August 17, 13
Saturday, August 17, 13
Understand Framework
Overhead
Saturday, August 17, 13
http://systemsarchitect.net/performance-benchmark-of-popular-php-frameworks/
Saturday, August 17, 13
Saturday, August 17, 13
Saturday, August 17, 13
Saturday, August 17, 13
Frameworks are Harder to Scale
Saturday, August 17, 13
Saturday, August 17, 13
Memcached
Saturday, August 17, 13
Memcached
• Roughly same hardware as webs
Saturday, August 17, 13
Memcached
• Roughly same hardware as webs• More memory (48GB)
Saturday, August 17, 13
Memcached
• Roughly same hardware as webs• More memory (48GB)• Shard keys across servers
Saturday, August 17, 13
Memcached
• Roughly same hardware as webs• More memory (48GB)• Shard keys across servers• mctop - https://github.com/etsy/mctop
Saturday, August 17, 13
Saturday, August 17, 13
MySQL
Saturday, August 17, 13
MySQL
• MySQL 5.5 (http://jkle.in/nephp)
Saturday, August 17, 13
MySQL
• MySQL 5.5 (http://jkle.in/nephp)• ~20 master/master pairs
Saturday, August 17, 13
MySQL
• MySQL 5.5 (http://jkle.in/nephp)• ~20 master/master pairs• innodb
Saturday, August 17, 13
MySQL
• MySQL 5.5 (http://jkle.in/nephp)• ~20 master/master pairs• innodb• thread_cache=800
Saturday, August 17, 13
MySQL
• MySQL 5.5 (http://jkle.in/nephp)• ~20 master/master pairs• innodb• thread_cache=800• max_connections=2500
Saturday, August 17, 13
MySQL
• MySQL 5.5 (http://jkle.in/nephp)• ~20 master/master pairs• innodb• thread_cache=800• max_connections=2500• [Almost] no joins
Saturday, August 17, 13
Theoretically we can serve ~9000 req/sec
Saturday, August 17, 13
Saturday, August 17, 13
Static Content
Saturday, August 17, 13
Saturday, August 17, 13
~500 Million Images
Saturday, August 17, 13
Offloading Requests
Saturday, August 17, 13
Offloading Requests
• Multiple CDNs
Saturday, August 17, 13
Offloading Requests
• Multiple CDNs• Img hit rate > 90%
Saturday, August 17, 13
Offloading Requests
• Multiple CDNs• Img hit rate > 90%• CSS/JS hit rate ~100%
Saturday, August 17, 13
Offloading Requests
• Multiple CDNs• Img hit rate > 90%• CSS/JS hit rate ~100%• Edge serves ~7000 reqs/sec
Saturday, August 17, 13
What about misses?
Saturday, August 17, 13
Saturday, August 17, 13
Change Management
Saturday, August 17, 13
Feature Flags
Saturday, August 17, 13
Saturday, August 17, 13
// Owner: Username$server_config['foo']['bar'] = array( 'users' => array('jsmith', 'jdoe'),);
// Owner: Username$server_config['baz'] = [ 'enabled' => [ 'variant1' => 0, 'variant2' => 0, 'variant3' => 50 ],];
// Owner: Username$server_config['qux'] = array( 'enabled' => 100, 'data' => array( 'somedata' ));
Saturday, August 17, 13
if (Feature::isEnabled('foo.bar')) { // Code}
Saturday, August 17, 13
Ramp-up:1%, 5%, 25%, 100%
Saturday, August 17, 13
Deployinator
Saturday, August 17, 13
Saturday, August 17, 13
Schemanator
Saturday, August 17, 13
Saturday, August 17, 13
Recent Improvements
Saturday, August 17, 13
Saturday, August 17, 13
Sandy Bridge
Saturday, August 17, 13
Baseline Performance (median)
Saturday, August 17, 13
Small code change
Baseline Performance (median)
Saturday, August 17, 13
Small code change
PHP 5.4
Baseline Performance (median)
Saturday, August 17, 13
Small code change
PHP 5.4
Disabled Hyperthreading
Baseline Performance (median)
Saturday, August 17, 13
Challenges
Saturday, August 17, 13
Saturday, August 17, 13
Options
Saturday, August 17, 13
Options
• Scale Horizontally (more shards)
Saturday, August 17, 13
Options
• Scale Horizontally (more shards)• Scale Vertically (SSD, bigger drives)
Saturday, August 17, 13
Options
• Scale Horizontally (more shards)• Scale Vertically (SSD, bigger drives)• Change architecture
Saturday, August 17, 13
Saturday, August 17, 13
Architecture Changes
Saturday, August 17, 13
Architecture Changes
• Ongoing conversation
Saturday, August 17, 13
Architecture Changes
• Ongoing conversation• Separate logical/physical shards
Saturday, August 17, 13
Architecture Changes
• Ongoing conversation• Separate logical/physical shards• Complex
Saturday, August 17, 13
Architecture Changes
• Ongoing conversation• Separate logical/physical shards• Complex• Server failure
Saturday, August 17, 13
Architecture Changes
• Ongoing conversation• Separate logical/physical shards• Complex• Server failure
• Migrating data
Saturday, August 17, 13
Architecture Changes
• Ongoing conversation• Separate logical/physical shards• Complex• Server failure
• Migrating data
• Consistency
Saturday, August 17, 13
Monitoring
Saturday, August 17, 13
Graphite
Saturday, August 17, 13
Stacked Search Timers
Saturday, August 17, 13
Ganglia
Saturday, August 17, 13
Saturday, August 17, 13
Nagios
Saturday, August 17, 13
Saturday, August 17, 13
Saturday, August 17, 13
Takeaways
Saturday, August 17, 13
K.I.S.S.
Saturday, August 17, 13
Use Proven Technologies
Saturday, August 17, 13
Saturday, August 17, 13
Understand Your Stack
Saturday, August 17, 13
Measure Everything
Saturday, August 17, 13
Work at Etsy ;-)
Saturday, August 17, 13
Connecthttp://www.meetup.com/Web-Performance-Boston/
www.etsy.com/careers
jonathan@etsy.com
@jonathanklein
Saturday, August 17, 13
Recommended