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
330
Demystifying SPDY and HTTP/2
jklein
1
550
Demystifying SPDY and HTTP/2
jklein
2
980
Cognitive Biases in Engineering Organizations
jklein
4
1.9k
Composer: From Beginner to Expert
jklein
1
810
Upgrading the Web: Boston Web Performance Meetup
jklein
1
250
Upgrading the Web: Driving Support For New Standards
jklein
1
740
Northeastern Lunch and Learn
jklein
0
200
Profiling PHP With XHProf
jklein
1
970
Other Decks in Technology
See All in Technology
Shift-from-React-to-Vue
calm1205
3
1.2k
Emacs x Nostr
hakkadaikon
1
150
Apple/Google/Amazonの決済システムの違いを踏まえた定期購読課金システムの構築 / abema-billing-system
cyberagentdevelopers
PRO
1
210
「最高のチューニング」をしないために / hack@delta 24.10
fujiwara3
21
3.4k
Nix入門パラダイム編
asa1984
2
200
CI/CDやテスト自動化の開発プロジェクトへの適用
megascus
3
740
新R25、乃木坂46 Mobileなどのファンビジネスを支えるマルチテナンシーなプラットフォームの全体像 / cam-multi-cloud
cyberagentdevelopers
PRO
1
130
「 SharePoint 難しい」ってよく聞くけど、そんなに言うなら8歳の息子に試してもらった
taichinakamura
1
580
omakaseしないための.rubocop.yml のつくりかた / How to Build Your .rubocop.yml to Avoid Omakase #kaigionrails
linkers_tech
3
710
MAMを軸とした動画ハンドリングにおけるAI活用前提の整備と次世代ビジョン / abema-ai-mam
cyberagentdevelopers
PRO
1
110
プロダクト成長に対応するプラットフォーム戦略:Authleteによる共通認証基盤の移行事例 / Building an authentication platform using Authlete and AWS
kakehashi
1
150
GitHub Universe: Evaluating RAG apps in GitHub Actions
pamelafox
0
170
Featured
See All Featured
GraphQLとの向き合い方2022年版
quramy
43
13k
Done Done
chrislema
181
16k
Fontdeck: Realign not Redesign
paulrobertlloyd
81
5.2k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.6k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
37
1.8k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
355
29k
Why Our Code Smells
bkeepers
PRO
334
57k
Building Adaptive Systems
keathley
38
2.2k
Code Reviewing Like a Champion
maltzj
519
39k
Building Your Own Lightsaber
phodgson
102
6k
A Modern Web Designer's Workflow
chriscoyier
692
190k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
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