Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Scaling PHP to 40 Million Uniques
Search
Jonathan Klein
August 17, 2013
Technology
3
1.1k
Scaling PHP to 40 Million Uniques
This is a talk I gave at Northeast PHP 2013 in Boston, MA.
Links: jkle.in/nephp
Jonathan Klein
August 17, 2013
Tweet
Share
More Decks by Jonathan Klein
See All by Jonathan Klein
Cognitive Biases in Engineering Organizations - Craft Conf
jklein
15
340
Demystifying SPDY and HTTP/2
jklein
1
550
Demystifying SPDY and HTTP/2
jklein
2
990
Cognitive Biases in Engineering Organizations
jklein
4
1.9k
Composer: From Beginner to Expert
jklein
1
820
Upgrading the Web: Boston Web Performance Meetup
jklein
1
250
Upgrading the Web: Driving Support For New Standards
jklein
1
750
Northeastern Lunch and Learn
jklein
0
200
Profiling PHP With XHProf
jklein
1
970
Other Decks in Technology
See All in Technology
オープンソースAIとは何か? --「オープンソースAIの定義 v1.0」詳細解説
shujisado
10
1.1k
初心者向けAWS Securityの勉強会mini Security-JAWSを9ヶ月ぐらい実施してきての近況
cmusudakeisuke
0
130
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
160
リンクアンドモチベーション ソフトウェアエンジニア向け紹介資料 / Introduction to Link and Motivation for Software Engineers
lmi
4
300k
Python(PYNQ)がテーマのAMD主催のFPGAコンテストに参加してきた
iotengineer22
0
500
20241120_JAWS_東京_ランチタイムLT#17_AWS認定全冠の先へ
tsumita
2
300
Terraform Stacks入門 #HashiTalks
msato
0
360
IBC 2024 動画技術関連レポート / IBC 2024 Report
cyberagentdevelopers
PRO
1
110
Adopting Jetpack Compose in Your Existing Project - GDG DevFest Bangkok 2024
akexorcist
0
110
Security-JAWS【第35回】勉強会クラウドにおけるマルウェアやコンテンツ改ざんへの対策
4su_para
0
180
100 名超が参加した日経グループ横断の競技型 AWS 学習イベント「Nikkei Group AWS GameDay」の紹介/mediajaws202411
nikkei_engineer_recruiting
1
170
SREが投資するAIOps ~ペアーズにおけるLLM for Developerへの取り組み~
takumiogawa
1
430
Featured
See All Featured
The Language of Interfaces
destraynor
154
24k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
What's in a price? How to price your products and services
michaelherold
243
12k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
100
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Transcript
Scaling PHP to 40 Million Uniques Northeast PHP 2013 Jonathan
Klein @jonathanklein Tuesday, September 24, 13
Scaling PHP to 40 Million Uniques Northeast PHP 2013 Jonathan
Klein @jonathanklein Tuesday, September 24, 13
Scaling PHP to 60 Million Uniques Northeast PHP 2013 Jonathan
Klein @jonathanklein Tuesday, September 24, 13
Who Am I? Tuesday, September 24, 13
Who Am I? • Performance Engineer at Etsy Tuesday, September
24, 13
Who Am I? • Performance Engineer at Etsy • Boston
Web Perf Meetup Organizer Tuesday, September 24, 13
Who Am I? • Performance Engineer at Etsy • Boston
Web Perf Meetup Organizer • Previously at Wayfair Tuesday, September 24, 13
Who Am I? • Performance Engineer at Etsy • Boston
Web Perf Meetup Organizer • Previously at Wayfair • Led team that converted to PHP Tuesday, September 24, 13
Slides, Links: jkle.in/nephp Tuesday, September 24, 13
codeascraft.com Tuesday, September 24, 13
Some Etsy Stats Tuesday, September 24, 13
Some Etsy Stats • 1.5 billion page views/month Tuesday, September
24, 13
Some Etsy Stats • 1.5 billion page views/month • Almost
$1B in sales last year Tuesday, September 24, 13
Some Etsy Stats • 1.5 billion page views/month • Almost
$1B in sales last year • Over 1M lines of PHP Tuesday, September 24, 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 Tuesday, September 24, 13
2012 Traffic Tuesday, September 24, 13
August 2012 Traffic Tuesday, September 24, 13
August 2012 Traffic 50% Higher Tuesday, September 24, 13
Holidays: ~90M Uniques Tuesday, September 24, 13
Tuesday, September 24, 13
Tuesday, September 24, 13
A few others... Tuesday, September 24, 13
A few others... • Search (Solr) Tuesday, September 24, 13
A few others... • Search (Solr) • Gearman Tuesday, September
24, 13
A few others... • Search (Solr) • Gearman • Redis
Tuesday, September 24, 13
A few others... • Search (Solr) • Gearman • Redis
• Postgres (legacy) Tuesday, September 24, 13
Tuesday, September 24, 13
Hardware (Supermicro) Tuesday, September 24, 13
Hardware (Supermicro) 2x 8-core Intel E5-2960 CPUs Tuesday, September 24,
13
Hardware (Supermicro) 2x 8-core Intel E5-2960 CPUs 24GB of RAM
Tuesday, September 24, 13
Hardware (Supermicro) 2x 8-core Intel E5-2960 CPUs 24GB of RAM
160GB SSD Tuesday, September 24, 13
Apache Tuesday, September 24, 13
Apache • Apache 2.2 Tuesday, September 24, 13
Apache • Apache 2.2 • Prefork MPM Tuesday, September 24,
13
Apache • Apache 2.2 • Prefork MPM • mod_php5 Tuesday,
September 24, 13
Apache • Apache 2.2 • Prefork MPM • mod_php5 StartServers
30 MinSpareServers 30 MaxSpareServers 60 ServerLimit 60 MaxClients 60 MaxRequestsPerChild 0 Tuesday, September 24, 13
PHP Tuesday, September 24, 13
PHP • PHP 5.4 Tuesday, September 24, 13
PHP • PHP 5.4 • Zend OPCache (3GB Memory Segment)
Tuesday, September 24, 13
PHP • PHP 5.4 • Zend OPCache (3GB Memory Segment)
• memory_limit: 128M Tuesday, September 24, 13
PHP • PHP 5.4 • Zend OPCache (3GB Memory Segment)
• memory_limit: 128M • max_execution_time: 30 Tuesday, September 24, 13
Optimizing PHP http://www.slideshare.net/jnklein/northeast-php-high-performance-php Tuesday, September 24, 13
Optimizing PHP • See last year’s talk http://www.slideshare.net/jnklein/northeast-php-high-performance-php Tuesday, September
24, 13
Optimizing PHP • See last year’s talk • Use an
Opcode Cache http://www.slideshare.net/jnklein/northeast-php-high-performance-php Tuesday, September 24, 13
Optimizing PHP • See last year’s talk • Use an
Opcode Cache • xhprof http://www.slideshare.net/jnklein/northeast-php-high-performance-php Tuesday, September 24, 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 Tuesday, September 24, 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 Tuesday, September 24, 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 Tuesday, September 24, 13
Static Arrays Tuesday, September 24, 13
Translations class 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 ... ); } Tuesday, September 24, 13
Tuesday, September 24, 13
Tuesday, September 24, 13
Atomic Deploys Tuesday, September 24, 13
Deploying PHP http://codeascraft.com/2013/07/01/atomic-deploys-at-etsy/ Tuesday, September 24, 13
Deploying PHP • mod_realdoc - Apache module http://codeascraft.com/2013/07/01/atomic-deploys-at-etsy/ Tuesday, September
24, 13
Deploying PHP • mod_realdoc - Apache module • incpath -
PHP Extension http://codeascraft.com/2013/07/01/atomic-deploys-at-etsy/ Tuesday, September 24, 13
Deploying PHP • mod_realdoc - Apache module • incpath -
PHP Extension • A/B symlink swap http://codeascraft.com/2013/07/01/atomic-deploys-at-etsy/ Tuesday, September 24, 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/ Tuesday, September 24, 13
Upgrading PHP Tuesday, September 24, 13
PHP 5.4 vs. 5.3 - CPU PHP 5.3 PHP 5.4
Tuesday, September 24, 13
PHP 5.4 vs. 5.3 - Memory PHP 5.3 PHP 5.4
Tuesday, September 24, 13
Tuesday, September 24, 13
Understand Framework Overhead Tuesday, September 24, 13
http://systemsarchitect.net/performance-benchmark-of-popular-php-frameworks/ Tuesday, September 24, 13
Tuesday, September 24, 13
Tuesday, September 24, 13
Tuesday, September 24, 13
Frameworks are Harder to Scale Tuesday, September 24, 13
Tuesday, September 24, 13
Memcached Tuesday, September 24, 13
Memcached • Roughly same hardware as webs Tuesday, September 24,
13
Memcached • Roughly same hardware as webs • More memory
(48GB) Tuesday, September 24, 13
Memcached • Roughly same hardware as webs • More memory
(48GB) • Shard keys across servers Tuesday, September 24, 13
Memcached • Roughly same hardware as webs • More memory
(48GB) • Shard keys across servers • mctop - https://github.com/etsy/mctop Tuesday, September 24, 13
Tuesday, September 24, 13
MySQL Tuesday, September 24, 13
MySQL • MySQL 5.5 (http://jkle.in/nephp) Tuesday, September 24, 13
MySQL • MySQL 5.5 (http://jkle.in/nephp) • ~20 master/master pairs Tuesday,
September 24, 13
MySQL • MySQL 5.5 (http://jkle.in/nephp) • ~20 master/master pairs •
innodb Tuesday, September 24, 13
MySQL • MySQL 5.5 (http://jkle.in/nephp) • ~20 master/master pairs •
innodb • thread_cache=800 Tuesday, September 24, 13
MySQL • MySQL 5.5 (http://jkle.in/nephp) • ~20 master/master pairs •
innodb • thread_cache=800 • max_connections=2500 Tuesday, September 24, 13
MySQL • MySQL 5.5 (http://jkle.in/nephp) • ~20 master/master pairs •
innodb • thread_cache=800 • max_connections=2500 • [Almost] no joins Tuesday, September 24, 13
Theoretically we can serve ~9000 req/sec Tuesday, September 24, 13
Tuesday, September 24, 13
Static Content Tuesday, September 24, 13
Tuesday, September 24, 13
~500 Million Images Tuesday, September 24, 13
Offloading Requests Tuesday, September 24, 13
Offloading Requests • Multiple CDNs Tuesday, September 24, 13
Offloading Requests • Multiple CDNs • Img hit rate >
90% Tuesday, September 24, 13
Offloading Requests • Multiple CDNs • Img hit rate >
90% • CSS/JS hit rate ~100% Tuesday, September 24, 13
Offloading Requests • Multiple CDNs • Img hit rate >
90% • CSS/JS hit rate ~100% • Edge serves ~7000 reqs/sec Tuesday, September 24, 13
What about misses? Tuesday, September 24, 13
Tuesday, September 24, 13
Change Management Tuesday, September 24, 13
Feature Flags Tuesday, September 24, 13
Tuesday, September 24, 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' ) ); Tuesday, September 24, 13
if (Feature::isEnabled('foo.bar')) { // Code } Tuesday, September 24, 13
Ramp-up: 1%, 5%, 25%, 100% Tuesday, September 24, 13
Deployinator Tuesday, September 24, 13
Tuesday, September 24, 13
Schemanator Tuesday, September 24, 13
Tuesday, September 24, 13
Recent Improvements Tuesday, September 24, 13
Tuesday, September 24, 13
Sandy Bridge Tuesday, September 24, 13
Baseline Performance (median) Tuesday, September 24, 13
Small code change Baseline Performance (median) Tuesday, September 24, 13
Small code change PHP 5.4 Baseline Performance (median) Tuesday, September
24, 13
Small code change PHP 5.4 Disabled Hyperthreading Baseline Performance (median)
Tuesday, September 24, 13
Challenges Tuesday, September 24, 13
Tuesday, September 24, 13
Options Tuesday, September 24, 13
Options • Scale Horizontally (more shards) Tuesday, September 24, 13
Options • Scale Horizontally (more shards) • Scale Vertically (SSD,
bigger drives) Tuesday, September 24, 13
Options • Scale Horizontally (more shards) • Scale Vertically (SSD,
bigger drives) • Change architecture Tuesday, September 24, 13
Tuesday, September 24, 13
Architecture Changes Tuesday, September 24, 13
Architecture Changes • Ongoing conversation Tuesday, September 24, 13
Architecture Changes • Ongoing conversation • Separate logical/physical shards Tuesday,
September 24, 13
Architecture Changes • Ongoing conversation • Separate logical/physical shards •
Complex Tuesday, September 24, 13
Architecture Changes • Ongoing conversation • Separate logical/physical shards •
Complex • Server failure Tuesday, September 24, 13
Architecture Changes • Ongoing conversation • Separate logical/physical shards •
Complex • Server failure • Migrating data Tuesday, September 24, 13
Architecture Changes • Ongoing conversation • Separate logical/physical shards •
Complex • Server failure • Migrating data • Consistency Tuesday, September 24, 13
Monitoring Tuesday, September 24, 13
Graphite Tuesday, September 24, 13
Stacked Search Timers Tuesday, September 24, 13
Ganglia Tuesday, September 24, 13
Tuesday, September 24, 13
Nagios Tuesday, September 24, 13
Tuesday, September 24, 13
Tuesday, September 24, 13
Takeaways Tuesday, September 24, 13
K.I.S.S. Tuesday, September 24, 13
Use Proven Technologies Tuesday, September 24, 13
Tuesday, September 24, 13
Understand Your Stack Tuesday, September 24, 13
Measure Everything Tuesday, September 24, 13
Work at Etsy ;-) Tuesday, September 24, 13
Connect http://www.meetup.com/Web-Performance-Boston/ www.etsy.com/careers
[email protected]
@jonathanklein Tuesday, September 24, 13