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.2k
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
350
Demystifying SPDY and HTTP/2
jklein
1
560
Demystifying SPDY and HTTP/2
jklein
2
1k
Cognitive Biases in Engineering Organizations
jklein
4
1.9k
Composer: From Beginner to Expert
jklein
1
830
Upgrading the Web: Boston Web Performance Meetup
jklein
1
260
Upgrading the Web: Driving Support For New Standards
jklein
1
760
Northeastern Lunch and Learn
jklein
0
200
Profiling PHP With XHProf
jklein
1
980
Other Decks in Technology
See All in Technology
社内イベント管理システムを1週間でAKSからACAに移行した話し
shingo_kawahara
0
190
生成AIのガバナンスの全体像と現実解
fnifni
1
190
20241220_S3 tablesの使い方を検証してみた
handy
4
610
Qiita埋め込み用スライド
naoki_0531
0
5.1k
NW-JAWS #14 re:Invent 2024(予選落ち含)で 発表された推しアップデートについて
nagisa53
0
270
AI時代のデータセンターネットワーク
lycorptech_jp
PRO
1
290
UI State設計とテスト方針
rmakiyama
2
620
KubeCon NA 2024 Recap: How to Move from Ingress to Gateway API with Minimal Hassle
ysakotch
0
210
Fanstaの1年を大解剖! 一人SREはどこまでできるのか!?
syossan27
2
170
LINE Developersプロダクト(LIFF/LINE Login)におけるフロントエンド開発
lycorptech_jp
PRO
0
120
スタートアップで取り組んでいるAzureとMicrosoft 365のセキュリティ対策/How to Improve Azure and Microsoft 365 Security at Startup
yuj1osm
0
230
【re:Invent 2024 アプデ】 Prompt Routing の紹介
champ
0
150
Featured
See All Featured
Building Better People: How to give real-time feedback that sticks.
wjessup
365
19k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
BBQ
matthewcrist
85
9.4k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
66k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
Music & Morning Musume
bryan
46
6.2k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
A better future with KSS
kneath
238
17k
The Language of Interfaces
destraynor
154
24k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
The Cost Of JavaScript in 2023
addyosmani
45
7k
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