SlideShare a Scribd company logo
Help! I need more servers! What do I do? Scaling a PHP application
A real world example The wonderful world of startups Who am I? Introduction
Scalability Network infrastructure and components Keeping server farms in sync Static content delivery Of databases and replications… Caching and code acceleration Code planning, design and implementation techniques Presentation Overview
Performance v/s high availability No right or wrong technique Having the right tools for the job Scalability
In the network Load Balancers
Software v/s hardware load balancers Load Balancers More expensive More robust Processes traffic at hardware level Tech agnostic: works with any OS Hardware load balancer Most packages cannot handle large or complex networks Large amount of hardware Easy setup Flexible (more configuration options) Cheaper Software load balancer (eg: UltraMonkey) Cons Pros
I’m losing my sessions! Session Persistence
Stick y sessions Session sharing Database Session server Sharedance Session clustering in Zend Platform Session Persistence
Overriding php’s default session handler <?php function session_handler_open($save_path, $session_name) { ... } function session_handler_close() { ... } function session_handler_store($key, $data) { ... } function session_handler_fetch($key) { ... } function session_handler_delete($key) { ... } function session_handler_gc($timeout) { } session_set_save_handler('session_handler_open', 'session_handler_close', 'session_handler_fetch', 'session_handler_store', 'session_handler_delete', 'session_handler_gc'); ?> Session Persistence
Code base Vendor tools PHP script using rsync #!/usr/local/php5/bin/php <?php $servers = array( '10.1.42.11', //web2 '10.1.42.12', //web3 '10.1.42.13', //web4 '10.1.42.14', //web5 '10.1.42.15', //web6 '10.1.42.16', //web7 '10.1.42.17', //web8 ); foreach($servers as $server) { //rsync /www/doc_root $command = &quot;rsync -avz /www/doc_root/ $server:/www/doc_root&quot;; echo &quot;Syncing /www/doc_root on $server...\n&quot;; echo &quot;------------------\n&quot;; echo shell_exec($command) . &quot;\n&quot;; ?> Server farms: Keeping servers in sync
Server configurations Need to restart servers after config changes Apache configs PHP configs Zend platform synchronises php.ini files across servers and restarts them Server farms: Keeping servers in sync
Why separate static content? Memory consumption Blocking Apache processes for large files How to separate static content? Types of static content: js, css, images, videos, audio, html Changing application’s urls for static content Using a low memory footprint server to serve static content (lighttpd, thttpd…) Zend platform’s download server Content delivery network (CDN) Static content separation
Typical prefork MPM Apache config < IfModule mpm_prefork_module> ServerLimit 1024 StartServers  128 MinSpareServers  256 MaxSpareServers  512 MaxClients  1024 MaxRequestsPerChild  2000 </IfModule> Static content separation
Comparing the different content separation ways Static content separation
Concurrency Level:      10,000 Time taken for tests:   5.420 seconds Complete requests:      100,000 Failed requests:        0 Write errors:           0 Keep-Alive requests:    0 Total transferred:      419,968,990 bytes HTML transferred:       388,510,351 bytes Requests per second:    18,449.53 [#/sec] (mean) Time per request:       542.019 [ms] (mean) Time per request:       0.054 [ms] (mean, across all concurrent requests) Transfer rate:          75,666.30 [Kbytes/sec] received Lighttpd benchmark
High performance and high availability for MySQL Master-slave replication Dual master replication DRBD + Heartbeat MySQL Cluster Vertical and horizontal partitioning Shards Application database infrastructure
Application database infrastructure How does all this affect your code? Some technologies implement scalability transparently Replication, to take advantage of it for performance, requires separation of read/write queries One way to do that would be to implement a wrapper with methods: mysql_safe_reader(), mysql_safe_writer() MySQL proxy
Some tools to optimize MySQL’s performance General query log with mysql_sla Mysql slow query log (log_slow_queries) Monyog Application database infrastructure
Application database infrastructure Comparison of MySQL scalability options
Application database infrastructure More details in MySQL manual, chapter 14, high availability and scalability
Code acceleration How code accelerators work Xcache, APC, eaccelerator Zend platform Code accelerator
Code acceleration How code accelerators work Xcache, APC, eaccelerator Zend platform Code accelerator
Database requests caching Usually the primary bottleneck Limit the number of requests to the db Use memcahed for frequently accessed data that does not change often HTML caching At application level, generate HTML pages that do not change often, and serve them as HTML Zend Platform caching Caching
Database requests caching Usually the primary bottleneck Limit the number of requests to the db Use memcahed for frequently accessed data that does not change often Caching
Memcache example $memcache = new Memcache(); $memcache->connect('yourserverhost', 11211) or die(&quot;Could not connect to memcache server&quot;); function getTopFiles() { global $memcache; $query = &quot;SELECT TOP 100 id, filename, rank FROM files ORDER BY rank DESC&quot;; $queryMd5 = md5($query); //Connect to memcache server $results = $memcache->get($queryMd5); if(!$results) { $results = mysql_safe_reader($query); //store for a day. 0: do not compress $memcache->set($queryMd5, $results, 0, 86400); } return $results; } Caching
HTML caching At application level, generate HTML pages that do not change often, and serve them as HTML Zend Platform caching Caching
Caching Zend Platform caching screenshot
Caching Client side caching Expired header Etag
PHP Code design considerations Zend Framework What is Zend Framework? How can it help me in my development?
PHP Code design considerations How is the application split? Modular design advantages Segmentation across multiple servers Shared storage Data centralization
Conclusion Plan, plan then plan some more Ensure compatibility
Thank you! Maurice Kherlakian Email:  [email_address] Skype: mkherlakian

More Related Content

What's hot (20)

PDF
Building Scalable Websites with Perl
Perrin Harkins
 
PPTX
Caching
Nascenia IT
 
PPTX
Php basics
Egerton University
 
PDF
WordPress Performance & Scalability
Joseph Scott
 
PDF
Memcache basics on google app engine
Ido Green
 
ODP
Clug 2011 March web server optimisation
grooverdan
 
PPT
Speeding Up The Snail
Marcus Deglos
 
ODP
Caching and tuning fun for high scalability @ PHPTour
Wim Godden
 
PDF
Using Vagrant for Local WordPress Development
slicejack
 
PPT
Drupal Performance - SerBenfiquista.com Case Study
hernanibf
 
PPTX
Mini-Training: To cache or not to cache
Betclic Everest Group Tech Team
 
ODP
Caching and tuning fun for high scalability
Wim Godden
 
PDF
DevOps Meetup ansible
sriram_rajan
 
PPTX
Ch7(publishing my sql data on the web)
Chhom Karath
 
PDF
Drupal feature proposal: two new stream-wrappers
Marcus Deglos
 
PPT
5-WebServers.ppt
webhostingguy
 
PDF
Facebook的缓存系统
yiditushe
 
TXT
Connection
Radian Sibarani
 
PPTX
Memcached
Shrawan Kumar Nirala
 
PPT
High Performance Wordpress: “Faster, Cheaper, Easier : Pick Three”
Valent Mustamin
 
Building Scalable Websites with Perl
Perrin Harkins
 
Caching
Nascenia IT
 
Php basics
Egerton University
 
WordPress Performance & Scalability
Joseph Scott
 
Memcache basics on google app engine
Ido Green
 
Clug 2011 March web server optimisation
grooverdan
 
Speeding Up The Snail
Marcus Deglos
 
Caching and tuning fun for high scalability @ PHPTour
Wim Godden
 
Using Vagrant for Local WordPress Development
slicejack
 
Drupal Performance - SerBenfiquista.com Case Study
hernanibf
 
Mini-Training: To cache or not to cache
Betclic Everest Group Tech Team
 
Caching and tuning fun for high scalability
Wim Godden
 
DevOps Meetup ansible
sriram_rajan
 
Ch7(publishing my sql data on the web)
Chhom Karath
 
Drupal feature proposal: two new stream-wrappers
Marcus Deglos
 
5-WebServers.ppt
webhostingguy
 
Facebook的缓存系统
yiditushe
 
Connection
Radian Sibarani
 
High Performance Wordpress: “Faster, Cheaper, Easier : Pick Three”
Valent Mustamin
 

Viewers also liked (20)

PPTX
Organ y plani
Daniel Agurto
 
PPTX
Tintas.impresiones
san_van
 
PPT
40 aniversario mulos_rojos_fcq_1970-1971-ligero2
EXMULOS
 
DOC
Cv Daniel Blanco (Español)
Daniel_Blanco_Ruiz
 
PPT
Ind scan
Jaya Prakash
 
PDF
Gerardo Ortiz noticias
Andy Desai
 
PPT
Trabajo equipo n5 final gerencia estrategica de la comunicación (1)
Mélida Sanabria
 
PPTX
Diabetic food guide
Keya Mitra
 
DOC
Definiciones grecia roma
--- ---
 
PPSX
Cerro colorado gomez y bonavia 4 a
pertileivan
 
PDF
upload test 1
Sadayuki Furuhashi
 
PDF
Innovación incremental: Soluciones Reales. Fidel Rodríguez Batalla
EOI Escuela de Organización Industrial
 
PPT
Fotos el Balsal Valle
andrew7246
 
PPTX
DANTE'S INFERNO | Circle 8 Bolgia 9: Sowers of Dischord
jotunheimm
 
PDF
ADT Commercial Security in DFW
Lon Bason
 
PDF
Lt200 drb200 tecnico
miguecas
 
PPTX
alimentos alcalinos contra el cancer fruta para el cancer, DIETA ANTICANCER
jorge andres
 
PDF
Request Lifecycle im Zend Framework
Mayflower GmbH
 
PPTX
Panteón y cosmogonía romana
friflome
 
PPT
Microsoft Innovative Teachers Conference--Q & A Session
Richard Van Eck
 
Organ y plani
Daniel Agurto
 
Tintas.impresiones
san_van
 
40 aniversario mulos_rojos_fcq_1970-1971-ligero2
EXMULOS
 
Cv Daniel Blanco (Español)
Daniel_Blanco_Ruiz
 
Ind scan
Jaya Prakash
 
Gerardo Ortiz noticias
Andy Desai
 
Trabajo equipo n5 final gerencia estrategica de la comunicación (1)
Mélida Sanabria
 
Diabetic food guide
Keya Mitra
 
Definiciones grecia roma
--- ---
 
Cerro colorado gomez y bonavia 4 a
pertileivan
 
upload test 1
Sadayuki Furuhashi
 
Innovación incremental: Soluciones Reales. Fidel Rodríguez Batalla
EOI Escuela de Organización Industrial
 
Fotos el Balsal Valle
andrew7246
 
DANTE'S INFERNO | Circle 8 Bolgia 9: Sowers of Dischord
jotunheimm
 
ADT Commercial Security in DFW
Lon Bason
 
Lt200 drb200 tecnico
miguecas
 
alimentos alcalinos contra el cancer fruta para el cancer, DIETA ANTICANCER
jorge andres
 
Request Lifecycle im Zend Framework
Mayflower GmbH
 
Panteón y cosmogonía romana
friflome
 
Microsoft Innovative Teachers Conference--Q & A Session
Richard Van Eck
 
Ad

Similar to Zend Con 2008 Slides (20)

ODP
Caching and tuning fun for high scalability @ FOSDEM 2012
Wim Godden
 
ODP
Caching and tuning fun for high scalability
Wim Godden
 
ODP
Caching and tuning fun for high scalability
Wim Godden
 
PPTX
Turbocharging php applications with zend server
Eric Ritchie
 
PDF
Enhancing scalability with intelligent caching
Eric Ritchie
 
PDF
Top ten-list
Brian DeShong
 
ODP
Caching and tuning fun for high scalability @ FrOSCon 2011
Wim Godden
 
PPT
Top 10 Scalability Mistakes
John Coggeshall
 
PPT
Apache Con 2008 Top 10 Mistakes
John Coggeshall
 
PDF
Bottom to Top Stack Optimization with LAMP
katzgrau
 
PDF
Bottom to Top Stack Optimization - CICON2011
CodeIgniter Conference
 
ODP
Caching and tuning fun for high scalability @ phpBenelux 2011
Wim Godden
 
PPT
Tips for a Faster Website
Rayed Alrashed
 
ODP
phptek13 - Caching and tuning fun tutorial
Wim Godden
 
PPT
FOWA Scaling The Lamp Stack Workshop
dlieberman
 
PDF
Turbocharging php applications with zend server (workshop)
Eric Ritchie
 
PPT
Top 30 Scalability Mistakes
John Coggeshall
 
PDF
How to scale PHP applications
Enrico Zimuel
 
PDF
Zend Server: A Guided Tour
Shahar Evron
 
PDF
Clug 2012 March web server optimisation
grooverdan
 
Caching and tuning fun for high scalability @ FOSDEM 2012
Wim Godden
 
Caching and tuning fun for high scalability
Wim Godden
 
Caching and tuning fun for high scalability
Wim Godden
 
Turbocharging php applications with zend server
Eric Ritchie
 
Enhancing scalability with intelligent caching
Eric Ritchie
 
Top ten-list
Brian DeShong
 
Caching and tuning fun for high scalability @ FrOSCon 2011
Wim Godden
 
Top 10 Scalability Mistakes
John Coggeshall
 
Apache Con 2008 Top 10 Mistakes
John Coggeshall
 
Bottom to Top Stack Optimization with LAMP
katzgrau
 
Bottom to Top Stack Optimization - CICON2011
CodeIgniter Conference
 
Caching and tuning fun for high scalability @ phpBenelux 2011
Wim Godden
 
Tips for a Faster Website
Rayed Alrashed
 
phptek13 - Caching and tuning fun tutorial
Wim Godden
 
FOWA Scaling The Lamp Stack Workshop
dlieberman
 
Turbocharging php applications with zend server (workshop)
Eric Ritchie
 
Top 30 Scalability Mistakes
John Coggeshall
 
How to scale PHP applications
Enrico Zimuel
 
Zend Server: A Guided Tour
Shahar Evron
 
Clug 2012 March web server optimisation
grooverdan
 
Ad

Recently uploaded (20)

PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 

Zend Con 2008 Slides

  • 1. Help! I need more servers! What do I do? Scaling a PHP application
  • 2. A real world example The wonderful world of startups Who am I? Introduction
  • 3. Scalability Network infrastructure and components Keeping server farms in sync Static content delivery Of databases and replications… Caching and code acceleration Code planning, design and implementation techniques Presentation Overview
  • 4. Performance v/s high availability No right or wrong technique Having the right tools for the job Scalability
  • 5. In the network Load Balancers
  • 6. Software v/s hardware load balancers Load Balancers More expensive More robust Processes traffic at hardware level Tech agnostic: works with any OS Hardware load balancer Most packages cannot handle large or complex networks Large amount of hardware Easy setup Flexible (more configuration options) Cheaper Software load balancer (eg: UltraMonkey) Cons Pros
  • 7. I’m losing my sessions! Session Persistence
  • 8. Stick y sessions Session sharing Database Session server Sharedance Session clustering in Zend Platform Session Persistence
  • 9. Overriding php’s default session handler <?php function session_handler_open($save_path, $session_name) { ... } function session_handler_close() { ... } function session_handler_store($key, $data) { ... } function session_handler_fetch($key) { ... } function session_handler_delete($key) { ... } function session_handler_gc($timeout) { } session_set_save_handler('session_handler_open', 'session_handler_close', 'session_handler_fetch', 'session_handler_store', 'session_handler_delete', 'session_handler_gc'); ?> Session Persistence
  • 10. Code base Vendor tools PHP script using rsync #!/usr/local/php5/bin/php <?php $servers = array( '10.1.42.11', //web2 '10.1.42.12', //web3 '10.1.42.13', //web4 '10.1.42.14', //web5 '10.1.42.15', //web6 '10.1.42.16', //web7 '10.1.42.17', //web8 ); foreach($servers as $server) { //rsync /www/doc_root $command = &quot;rsync -avz /www/doc_root/ $server:/www/doc_root&quot;; echo &quot;Syncing /www/doc_root on $server...\n&quot;; echo &quot;------------------\n&quot;; echo shell_exec($command) . &quot;\n&quot;; ?> Server farms: Keeping servers in sync
  • 11. Server configurations Need to restart servers after config changes Apache configs PHP configs Zend platform synchronises php.ini files across servers and restarts them Server farms: Keeping servers in sync
  • 12. Why separate static content? Memory consumption Blocking Apache processes for large files How to separate static content? Types of static content: js, css, images, videos, audio, html Changing application’s urls for static content Using a low memory footprint server to serve static content (lighttpd, thttpd…) Zend platform’s download server Content delivery network (CDN) Static content separation
  • 13. Typical prefork MPM Apache config < IfModule mpm_prefork_module> ServerLimit 1024 StartServers 128 MinSpareServers 256 MaxSpareServers 512 MaxClients 1024 MaxRequestsPerChild 2000 </IfModule> Static content separation
  • 14. Comparing the different content separation ways Static content separation
  • 15. Concurrency Level:      10,000 Time taken for tests:   5.420 seconds Complete requests:      100,000 Failed requests:        0 Write errors:           0 Keep-Alive requests:    0 Total transferred:      419,968,990 bytes HTML transferred:       388,510,351 bytes Requests per second:    18,449.53 [#/sec] (mean) Time per request:       542.019 [ms] (mean) Time per request:       0.054 [ms] (mean, across all concurrent requests) Transfer rate:          75,666.30 [Kbytes/sec] received Lighttpd benchmark
  • 16. High performance and high availability for MySQL Master-slave replication Dual master replication DRBD + Heartbeat MySQL Cluster Vertical and horizontal partitioning Shards Application database infrastructure
  • 17. Application database infrastructure How does all this affect your code? Some technologies implement scalability transparently Replication, to take advantage of it for performance, requires separation of read/write queries One way to do that would be to implement a wrapper with methods: mysql_safe_reader(), mysql_safe_writer() MySQL proxy
  • 18. Some tools to optimize MySQL’s performance General query log with mysql_sla Mysql slow query log (log_slow_queries) Monyog Application database infrastructure
  • 19. Application database infrastructure Comparison of MySQL scalability options
  • 20. Application database infrastructure More details in MySQL manual, chapter 14, high availability and scalability
  • 21. Code acceleration How code accelerators work Xcache, APC, eaccelerator Zend platform Code accelerator
  • 22. Code acceleration How code accelerators work Xcache, APC, eaccelerator Zend platform Code accelerator
  • 23. Database requests caching Usually the primary bottleneck Limit the number of requests to the db Use memcahed for frequently accessed data that does not change often HTML caching At application level, generate HTML pages that do not change often, and serve them as HTML Zend Platform caching Caching
  • 24. Database requests caching Usually the primary bottleneck Limit the number of requests to the db Use memcahed for frequently accessed data that does not change often Caching
  • 25. Memcache example $memcache = new Memcache(); $memcache->connect('yourserverhost', 11211) or die(&quot;Could not connect to memcache server&quot;); function getTopFiles() { global $memcache; $query = &quot;SELECT TOP 100 id, filename, rank FROM files ORDER BY rank DESC&quot;; $queryMd5 = md5($query); //Connect to memcache server $results = $memcache->get($queryMd5); if(!$results) { $results = mysql_safe_reader($query); //store for a day. 0: do not compress $memcache->set($queryMd5, $results, 0, 86400); } return $results; } Caching
  • 26. HTML caching At application level, generate HTML pages that do not change often, and serve them as HTML Zend Platform caching Caching
  • 27. Caching Zend Platform caching screenshot
  • 28. Caching Client side caching Expired header Etag
  • 29. PHP Code design considerations Zend Framework What is Zend Framework? How can it help me in my development?
  • 30. PHP Code design considerations How is the application split? Modular design advantages Segmentation across multiple servers Shared storage Data centralization
  • 31. Conclusion Plan, plan then plan some more Ensure compatibility
  • 32. Thank you! Maurice Kherlakian Email: [email_address] Skype: mkherlakian