SlideShare une entreprise Scribd logo
1  sur  43
Turbocharging PHP
Applications With Zend
Server.

Eric Ritchie (eric@zend.com)




                               © All rights reserved. Zend Technologies, Inc.
Eric Ritchie bids you welcome!
• Senior Technical Consultant and Trainer
  at Zend Technologies

• Zend Framework and PHP 5.3 ZCE

• Eighteen years of system administration experience

• Twelve years of PHP (3,4 & 5) and five years Zend
  Framework development experience

• Hobbies: Sampling good wines/whiskies
 (gifts welcome)




                     © All rights reserved. Zend Technologies, Inc.
Agenda

• Defining the problem
• The sharpest tool in the shed… Code Tracing
• Laziness is good (at least for web servers):
  Using caching to avoid work
• If we must work, then procrastinate: Use the Job Queue
• Taking the heat off the disk: Ways to reduce disk I/O




                       © All rights reserved. Zend Technologies, Inc.
What we will not cover (probably)

• Database optimization > caching
• Web service optimization
• Varnish and reverse proxying in general
• CDNs (Content Delivery Networks)
• Caching technology comparisons
• Operating system level optimizations
• JavaScript performance in general
• Network Traffic Analysis



                      © All rights reserved. Zend Technologies, Inc.
Defining the problem
Why is it that we always discover that we have performance
problems AFTER we go live?




                      © All rights reserved. Zend Technologies, Inc.
The evolution of an organic website
• A new website is born...




                                  Internet



LAMP Server




                      © All rights reserved. Zend Technologies, Inc.
...too much of a good thing?
• the smoke begins...




                                    Internet



LAMP Server




                        © All rights reserved. Zend Technologies, Inc.
First job: Bottleneck identification

• Many possible tools:
   Zend Server Event Monitoring

   Profiling

   microtime()

   Slow query logs

• One Swiss army knife:
   Zend Server Code Tracing




                         © All rights reserved. Zend Technologies, Inc.
Zend Code Tracing
A black box for your PHP code




                      © All rights reserved. Zend Technologies, Inc.
Zend Code Tracing: Main view




               © All rights reserved. Zend Technologies, Inc.
Zend Code Tracing: Statistics view




                © All rights reserved. Zend Technologies, Inc.
Zend Code Tracing: How to store a trace?

• Best way (in most cases)
  … Use a web browser




  Very quick and easy, but obviously not so good for POST requests

  Also, we may not be allowed!




                         © All rights reserved. Zend Technologies, Inc.
Zend Code Tracing: How to store a trace?
• The official way
   … Use event monitoring




   Works for all requests where an event is generated
   Great for catching random problems
   Custom events allow for „programmatic“ generation of traces


                          © All rights reserved. Zend Technologies, Inc.
Caching
Reducing the work load of our application architecture




                       © All rights reserved. Zend Technologies, Inc.
Zend Page Cache

• Dynamic content is expensive, so don’t regenerate
  Low impact, since no code changes may be required

  Complete request cached, so a hit is like a static request

  Multiple copies of pages can be maintained

  Controlled by flexable and comprehensive rules

• Sadly, nothing comes for free
  Page design can render page caching useless

  Highly dynamic content cannot be reasonably cached

  Problems with stale content



                        © All rights reserved. Zend Technologies, Inc.
Zend Page Caching: Custom content




               © All rights reserved. Zend Technologies, Inc.
Zend Page Cache: Configuration




               © All rights reserved. Zend Technologies, Inc.
Data caching

• Protects the data layer:
   Helps prevent repetitive DB/web service calls

   Far easier than scaling the database

• But...
   Requires code changes

   Custom data is also problematic

   Risk of delivering stale content

   De-caching can bring down the data source




                         © All rights reserved. Zend Technologies, Inc.
One common architecture
• Network data cache
  e.g. Memcache



 Internet                                                               DB Server(s)


                LB


                                                                         Cache
                                                                         Server
                                                    Web Farm


                       © All rights reserved. Zend Technologies, Inc.
Network data cache

• Some advantages
  Only one cache to update/invalidate

  Most effective way of protecting the data source

• Many disadvantages...
  Single point of failure (or uncertainty when in distributed mode)

  Limits scalability

  Performance bottleneck

  Slower




                        © All rights reserved. Zend Technologies, Inc.
A different approach
• Shared memory cache                                    Cache
  e.g. Zend Data Cache


                                                       Cache

 Internet                                                             DB Server(s)




                                                                      X
                LB                                     Cache



                                                                       Cache
                                                                       Server
                                                    Web Farm



                     © All rights reserved. Zend Technologies, Inc.
Zend Data Cache: A shared memory cache

• Many advantages
  Completely scalable (copy/paste architecture)

  No single point of failure

  Does not require TCP/IP

  Very fast

• Some disadvantages...
  Not the path of least resistance

  More work for the data source or the developer

  Your colleagues may laugh at you (but they would be wrong)



                         © All rights reserved. Zend Technologies, Inc.
Zend Data Cache: Usage

• Inserting into the cache
   $res = zend_shm_cache_store($key, $value, $ttl)

   $res = zend_disk_cache_store($key, $value, $ttl)

• Reading from the cache
   $value = zend_shm_cache_fetch($key)

   $value = zend_disk_cache_fetch($key)

• In all cases the key can contain a namespace to allow
  grouping of data, e.g. namespace::key




                        © All rights reserved. Zend Technologies, Inc.
Zend Data Cache: Usage

• Deleting from the cache
  $res = zend_shm_cache_delete($key)

  $res = zend_disk_cache_delete($key)

• Wiping the cache
  $res = zend_shm_cache_clear()

  $res = zend_disk_cache_clear()




                       © All rights reserved. Zend Technologies, Inc.
Shared memory caching

• Taming the disadvantages
  True, we need to work a little, but...
    • We can use Zend Server‘s Job Queue to perform remote
      cache maintenance
    • We can get a list of active servers from the Web API
      provided by Zend Server
    • Really, we don‘t have to code much ourselves




                          © All rights reserved. Zend Technologies, Inc.
Remote de-caching
• With Zend Server‘s Job Queue




• ...and the job itself




                          © All rights reserved. Zend Technologies, Inc.
Shared memory cache on steroids

• Don‘t decache, update
  Regenerate the data and insert into the cache

  At a minimum do this for all components of the index page

  Reduces data source load




                       © All rights reserved. Zend Technologies, Inc.
Zend Job Queue
Why do now what you can do a little later?
Or, genius is being calm on the surface while being calculating in
the background. Your application should do just that.
Or, your server‘s marketing department.




                       © All rights reserved. Zend Technologies, Inc.
Zend Job Queue

• Doesn’t make PHP faster, but makes it look that way
  Break slow tasks out of the user workflow

  Offload the heavy lifting to a background server.

  Delay expensive tasks to off peak hours

  Helps to prevent repetitve work reducing overall load

• Possible to create jobs which depend on other jobs, run
  regularly and have set priorites
• Hooks into Zend Server‘s Event Monitoring component
  Jobs can feedback status information

  Problems appear in the central Zend Server event list


                        © All rights reserved. Zend Technologies, Inc.
Zend Job Queue: Typical example




               © All rights reserved. Zend Technologies, Inc.
Zend Job Queue: Basic use

• Would be hard to make it easier…




• We can also pass information to our job...




                      © All rights reserved. Zend Technologies, Inc.
Zend Job Queue: Basic use

• Possible to name our jobs and set an earliest start time…




• Once sheduled, it is possible to check up on jobs



                      © All rights reserved. Zend Technologies, Inc.
Zend Job Queue: Querying jobs

• Finding out the status of our job using the job id




   Find out if the job is still queued, running, completed or failed

   When finished we get a copy of the script‘s output




                          © All rights reserved. Zend Technologies, Inc.
Zend Job Queue: Querying jobs

• Searching for jobs




   Search for an existing queued job of the same type

   Useful for avoiding repetitive work

   Returns the number of matching jobs along with job details




                         © All rights reserved. Zend Technologies, Inc.
Optimization vs. Complexity




           © All rights reserved. Zend Technologies, Inc.
Optimization vs. Complexity

• With every optimization complexity increaces
   Who else dropped into the caching pitfall?

• First: implement functionality
• System performing well?
• If not, check why
• Get rid of bottlenecks




                         © All rights reserved. Zend Technologies, Inc.
Reducing Disk I/O
The only component of a web server slower than the disk
subsystem is the guy you ask to set it up.




                      © All rights reserved. Zend Technologies, Inc.
Reducing disk I/O

• Use an opcode cache e.g. Zend Optimizer+
  Avoids the need to open PHP files and compile the contents for
   every request.
  Compiled „opcodes“ are instead held in shared memory for later
   reuse.
  Particularly important for framework based projects where tens
   of files may be needed to answer one request.
  Also saves some compiler time, but disk I/O savings are usually far
   more significant.
  Most obvious benefit for scripts with short run times or running on
   loaded servers.


                        © All rights reserved. Zend Technologies, Inc.
Reducing disk I/O

• Store static files elsewhere
• Do not cache to the file system
• Must have local storage? ...Use a ramdisk
• Reduce PHP/Apache logging to minimal levels
   E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR

• Don‘t forget the Zend Server logs!
   Search for log_verbosity_level in the configuration




                         © All rights reserved. Zend Technologies, Inc.
File system concerns

• EXT3 – The default problem
   For a web server ReiserFS can be 20x (or more) faster, really!

   Even XFS is 2.5x faster

   If you must use EXT3/4 then throw memory at the server

• My NFS/Samba server is fast... Honest!
   Even „fast“ NFS servers have terrible performance under load

   Older implementations cannot use buffer cache

   Poor scalability

• Distributed file systems
   Extremely poor scalability

                         © All rights reserved. Zend Technologies, Inc.
PHP uses your network

• PHP communicates with network services like
   Databases (ex: MySQL, Oracle)

   Caching systems (ex: Memcache, Redis ..)

   Job Queue Systems (ex: Zend Job Queue, RabbitMQ )

   Session Clustering Daemon (ex: Zend Session Clustering)

• If one of these services overloads the network then all
  other suffer from slowdown
   Network congestion

   Insufficient bandwidth

   High latency


                         © All rights reserved. Zend Technologies, Inc.
So long...

• …and thanks for all the fish.




                       © All rights reserved. Zend Technologies, Inc.
Turbocharging PHP
Applications With Zend
Server.

Eric Ritchie (eric@zend.com)




                               © All rights reserved. Zend Technologies, Inc.

Contenu connexe

Tendances

Tendances (20)

MySQL Enterprise Backup: Better Very Large Database Backup & Recovery and More!!
MySQL Enterprise Backup: Better Very Large Database Backup & Recovery and More!!MySQL Enterprise Backup: Better Very Large Database Backup & Recovery and More!!
MySQL Enterprise Backup: Better Very Large Database Backup & Recovery and More!!
 
J2EE Performance And Scalability Bp
J2EE Performance And Scalability BpJ2EE Performance And Scalability Bp
J2EE Performance And Scalability Bp
 
Zend Server: A Guided Tour
Zend Server: A Guided TourZend Server: A Guided Tour
Zend Server: A Guided Tour
 
Tiery Eyed
Tiery EyedTiery Eyed
Tiery Eyed
 
Hadoop Operations at LinkedIn
Hadoop Operations at LinkedInHadoop Operations at LinkedIn
Hadoop Operations at LinkedIn
 
Hadoop Operations for Production Systems (Strata NYC)
Hadoop Operations for Production Systems (Strata NYC)Hadoop Operations for Production Systems (Strata NYC)
Hadoop Operations for Production Systems (Strata NYC)
 
Hadoop on Virtual Machines
Hadoop on Virtual MachinesHadoop on Virtual Machines
Hadoop on Virtual Machines
 
Apache hbase for the enterprise (Strata+Hadoop World 2012)
Apache hbase for the enterprise (Strata+Hadoop World 2012)Apache hbase for the enterprise (Strata+Hadoop World 2012)
Apache hbase for the enterprise (Strata+Hadoop World 2012)
 
Streamline Collections by Using Document Imaging Scenarios for Accounts Recei...
Streamline Collections by Using Document Imaging Scenarios for Accounts Recei...Streamline Collections by Using Document Imaging Scenarios for Accounts Recei...
Streamline Collections by Using Document Imaging Scenarios for Accounts Recei...
 
Implementing Parallelism in PostgreSQL - PGCon 2014
Implementing Parallelism in PostgreSQL - PGCon 2014Implementing Parallelism in PostgreSQL - PGCon 2014
Implementing Parallelism in PostgreSQL - PGCon 2014
 
Strata + Hadoop World 2012: Apache HBase Features for the Enterprise
Strata + Hadoop World 2012: Apache HBase Features for the EnterpriseStrata + Hadoop World 2012: Apache HBase Features for the Enterprise
Strata + Hadoop World 2012: Apache HBase Features for the Enterprise
 
Mtc learnings from isv & enterprise interaction
Mtc learnings from isv & enterprise  interactionMtc learnings from isv & enterprise  interaction
Mtc learnings from isv & enterprise interaction
 
Mtc learnings from isv & enterprise (dated - Dec -2014)
Mtc learnings from isv & enterprise (dated - Dec -2014)Mtc learnings from isv & enterprise (dated - Dec -2014)
Mtc learnings from isv & enterprise (dated - Dec -2014)
 
Acquia Managed Cloud: Highly Available Architecture for Highly Unpredictable ...
Acquia Managed Cloud: Highly Available Architecture for Highly Unpredictable ...Acquia Managed Cloud: Highly Available Architecture for Highly Unpredictable ...
Acquia Managed Cloud: Highly Available Architecture for Highly Unpredictable ...
 
HDFS Futures: NameNode Federation for Improved Efficiency and Scalability
HDFS Futures: NameNode Federation for Improved Efficiency and ScalabilityHDFS Futures: NameNode Federation for Improved Efficiency and Scalability
HDFS Futures: NameNode Federation for Improved Efficiency and Scalability
 
High Scalability Toronto: Meetup #2
High Scalability Toronto: Meetup #2High Scalability Toronto: Meetup #2
High Scalability Toronto: Meetup #2
 
What Can FPGA Designers Do With Personal Data Centers?
What Can FPGA Designers Do With Personal Data Centers?What Can FPGA Designers Do With Personal Data Centers?
What Can FPGA Designers Do With Personal Data Centers?
 
Thousands of Threads and Blocking I/O
Thousands of Threads and Blocking I/OThousands of Threads and Blocking I/O
Thousands of Threads and Blocking I/O
 
What's New and Upcoming in HDFS - the Hadoop Distributed File System
What's New and Upcoming in HDFS - the Hadoop Distributed File SystemWhat's New and Upcoming in HDFS - the Hadoop Distributed File System
What's New and Upcoming in HDFS - the Hadoop Distributed File System
 
Scaling CQ5
Scaling CQ5Scaling CQ5
Scaling CQ5
 

Similaire à Turbocharging php applications with zend server

Optimizing Magento Performance with Zend Server
Optimizing Magento Performance with Zend ServerOptimizing Magento Performance with Zend Server
Optimizing Magento Performance with Zend Server
varien
 

Similaire à Turbocharging php applications with zend server (20)

PHP Apps on the Move - Migrating from In-House to Cloud
PHP Apps on the Move - Migrating from In-House to Cloud  PHP Apps on the Move - Migrating from In-House to Cloud
PHP Apps on the Move - Migrating from In-House to Cloud
 
Performance tuning PHP on IBMi
Performance tuning PHP on IBMiPerformance tuning PHP on IBMi
Performance tuning PHP on IBMi
 
Scalable High-Availability Session Storage with ZSCM
Scalable High-Availability Session Storage with ZSCMScalable High-Availability Session Storage with ZSCM
Scalable High-Availability Session Storage with ZSCM
 
How to scale PHP applications
How to scale PHP applicationsHow to scale PHP applications
How to scale PHP applications
 
What's new with Zend server
What's new with Zend serverWhat's new with Zend server
What's new with Zend server
 
How to Manage Cloud Infrastructures using Zend Framework
How to Manage Cloud Infrastructures using Zend FrameworkHow to Manage Cloud Infrastructures using Zend Framework
How to Manage Cloud Infrastructures using Zend Framework
 
Zend In The Cloud
Zend In The CloudZend In The Cloud
Zend In The Cloud
 
Application Deployment on IBM i
Application Deployment on IBM iApplication Deployment on IBM i
Application Deployment on IBM i
 
Standard CMS on standard PHP Stack - Drupal and Zend Server
Standard CMS on standard PHP Stack - Drupal and Zend ServerStandard CMS on standard PHP Stack - Drupal and Zend Server
Standard CMS on standard PHP Stack - Drupal and Zend Server
 
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
 
The Perils and Triumphs of using Cassandra at a .NET/Microsoft Shop
The Perils and Triumphs of using Cassandra at a .NET/Microsoft ShopThe Perils and Triumphs of using Cassandra at a .NET/Microsoft Shop
The Perils and Triumphs of using Cassandra at a .NET/Microsoft Shop
 
Costruire un sito e-commerce in alta affidabilità con Magento e Zend Server C...
Costruire un sito e-commerce in alta affidabilità con Magento e Zend Server C...Costruire un sito e-commerce in alta affidabilità con Magento e Zend Server C...
Costruire un sito e-commerce in alta affidabilità con Magento e Zend Server C...
 
Accelerating Application Performance with Amazon ElastiCache (DAT207) | AWS r...
Accelerating Application Performance with Amazon ElastiCache (DAT207) | AWS r...Accelerating Application Performance with Amazon ElastiCache (DAT207) | AWS r...
Accelerating Application Performance with Amazon ElastiCache (DAT207) | AWS r...
 
Cloudy in Indonesia: Java and Cloud
Cloudy in Indonesia: Java and CloudCloudy in Indonesia: Java and Cloud
Cloudy in Indonesia: Java and Cloud
 
Running Oracle EBS in the cloud (DOAG TECH17 edition)
Running Oracle EBS in the cloud (DOAG TECH17 edition)Running Oracle EBS in the cloud (DOAG TECH17 edition)
Running Oracle EBS in the cloud (DOAG TECH17 edition)
 
Zend Products and PHP for IBMi
Zend Products and PHP for IBMi  Zend Products and PHP for IBMi
Zend Products and PHP for IBMi
 
AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2020
AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2020AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2020
AWS Lambda: Best Practices and Common Mistakes - Chicago Cloud Conference 2020
 
Improving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetImproving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve Internet
 
Improving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetImproving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve Internet
 
Optimizing Magento Performance with Zend Server
Optimizing Magento Performance with Zend ServerOptimizing Magento Performance with Zend Server
Optimizing Magento Performance with Zend Server
 

Dernier

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Turbocharging php applications with zend server

  • 1. Turbocharging PHP Applications With Zend Server. Eric Ritchie (eric@zend.com) © All rights reserved. Zend Technologies, Inc.
  • 2. Eric Ritchie bids you welcome! • Senior Technical Consultant and Trainer at Zend Technologies • Zend Framework and PHP 5.3 ZCE • Eighteen years of system administration experience • Twelve years of PHP (3,4 & 5) and five years Zend Framework development experience • Hobbies: Sampling good wines/whiskies (gifts welcome) © All rights reserved. Zend Technologies, Inc.
  • 3. Agenda • Defining the problem • The sharpest tool in the shed… Code Tracing • Laziness is good (at least for web servers): Using caching to avoid work • If we must work, then procrastinate: Use the Job Queue • Taking the heat off the disk: Ways to reduce disk I/O © All rights reserved. Zend Technologies, Inc.
  • 4. What we will not cover (probably) • Database optimization > caching • Web service optimization • Varnish and reverse proxying in general • CDNs (Content Delivery Networks) • Caching technology comparisons • Operating system level optimizations • JavaScript performance in general • Network Traffic Analysis © All rights reserved. Zend Technologies, Inc.
  • 5. Defining the problem Why is it that we always discover that we have performance problems AFTER we go live? © All rights reserved. Zend Technologies, Inc.
  • 6. The evolution of an organic website • A new website is born... Internet LAMP Server © All rights reserved. Zend Technologies, Inc.
  • 7. ...too much of a good thing? • the smoke begins... Internet LAMP Server © All rights reserved. Zend Technologies, Inc.
  • 8. First job: Bottleneck identification • Many possible tools:  Zend Server Event Monitoring  Profiling  microtime()  Slow query logs • One Swiss army knife:  Zend Server Code Tracing © All rights reserved. Zend Technologies, Inc.
  • 9. Zend Code Tracing A black box for your PHP code © All rights reserved. Zend Technologies, Inc.
  • 10. Zend Code Tracing: Main view © All rights reserved. Zend Technologies, Inc.
  • 11. Zend Code Tracing: Statistics view © All rights reserved. Zend Technologies, Inc.
  • 12. Zend Code Tracing: How to store a trace? • Best way (in most cases)  … Use a web browser  Very quick and easy, but obviously not so good for POST requests  Also, we may not be allowed! © All rights reserved. Zend Technologies, Inc.
  • 13. Zend Code Tracing: How to store a trace? • The official way  … Use event monitoring  Works for all requests where an event is generated  Great for catching random problems  Custom events allow for „programmatic“ generation of traces © All rights reserved. Zend Technologies, Inc.
  • 14. Caching Reducing the work load of our application architecture © All rights reserved. Zend Technologies, Inc.
  • 15. Zend Page Cache • Dynamic content is expensive, so don’t regenerate  Low impact, since no code changes may be required  Complete request cached, so a hit is like a static request  Multiple copies of pages can be maintained  Controlled by flexable and comprehensive rules • Sadly, nothing comes for free  Page design can render page caching useless  Highly dynamic content cannot be reasonably cached  Problems with stale content © All rights reserved. Zend Technologies, Inc.
  • 16. Zend Page Caching: Custom content © All rights reserved. Zend Technologies, Inc.
  • 17. Zend Page Cache: Configuration © All rights reserved. Zend Technologies, Inc.
  • 18. Data caching • Protects the data layer:  Helps prevent repetitive DB/web service calls  Far easier than scaling the database • But...  Requires code changes  Custom data is also problematic  Risk of delivering stale content  De-caching can bring down the data source © All rights reserved. Zend Technologies, Inc.
  • 19. One common architecture • Network data cache e.g. Memcache Internet DB Server(s) LB Cache Server Web Farm © All rights reserved. Zend Technologies, Inc.
  • 20. Network data cache • Some advantages  Only one cache to update/invalidate  Most effective way of protecting the data source • Many disadvantages...  Single point of failure (or uncertainty when in distributed mode)  Limits scalability  Performance bottleneck  Slower © All rights reserved. Zend Technologies, Inc.
  • 21. A different approach • Shared memory cache Cache e.g. Zend Data Cache Cache Internet DB Server(s) X LB Cache Cache Server Web Farm © All rights reserved. Zend Technologies, Inc.
  • 22. Zend Data Cache: A shared memory cache • Many advantages  Completely scalable (copy/paste architecture)  No single point of failure  Does not require TCP/IP  Very fast • Some disadvantages...  Not the path of least resistance  More work for the data source or the developer  Your colleagues may laugh at you (but they would be wrong) © All rights reserved. Zend Technologies, Inc.
  • 23. Zend Data Cache: Usage • Inserting into the cache  $res = zend_shm_cache_store($key, $value, $ttl)  $res = zend_disk_cache_store($key, $value, $ttl) • Reading from the cache  $value = zend_shm_cache_fetch($key)  $value = zend_disk_cache_fetch($key) • In all cases the key can contain a namespace to allow grouping of data, e.g. namespace::key © All rights reserved. Zend Technologies, Inc.
  • 24. Zend Data Cache: Usage • Deleting from the cache  $res = zend_shm_cache_delete($key)  $res = zend_disk_cache_delete($key) • Wiping the cache  $res = zend_shm_cache_clear()  $res = zend_disk_cache_clear() © All rights reserved. Zend Technologies, Inc.
  • 25. Shared memory caching • Taming the disadvantages  True, we need to work a little, but... • We can use Zend Server‘s Job Queue to perform remote cache maintenance • We can get a list of active servers from the Web API provided by Zend Server • Really, we don‘t have to code much ourselves © All rights reserved. Zend Technologies, Inc.
  • 26. Remote de-caching • With Zend Server‘s Job Queue • ...and the job itself © All rights reserved. Zend Technologies, Inc.
  • 27. Shared memory cache on steroids • Don‘t decache, update  Regenerate the data and insert into the cache  At a minimum do this for all components of the index page  Reduces data source load © All rights reserved. Zend Technologies, Inc.
  • 28. Zend Job Queue Why do now what you can do a little later? Or, genius is being calm on the surface while being calculating in the background. Your application should do just that. Or, your server‘s marketing department. © All rights reserved. Zend Technologies, Inc.
  • 29. Zend Job Queue • Doesn’t make PHP faster, but makes it look that way  Break slow tasks out of the user workflow  Offload the heavy lifting to a background server.  Delay expensive tasks to off peak hours  Helps to prevent repetitve work reducing overall load • Possible to create jobs which depend on other jobs, run regularly and have set priorites • Hooks into Zend Server‘s Event Monitoring component  Jobs can feedback status information  Problems appear in the central Zend Server event list © All rights reserved. Zend Technologies, Inc.
  • 30. Zend Job Queue: Typical example © All rights reserved. Zend Technologies, Inc.
  • 31. Zend Job Queue: Basic use • Would be hard to make it easier… • We can also pass information to our job... © All rights reserved. Zend Technologies, Inc.
  • 32. Zend Job Queue: Basic use • Possible to name our jobs and set an earliest start time… • Once sheduled, it is possible to check up on jobs © All rights reserved. Zend Technologies, Inc.
  • 33. Zend Job Queue: Querying jobs • Finding out the status of our job using the job id  Find out if the job is still queued, running, completed or failed  When finished we get a copy of the script‘s output © All rights reserved. Zend Technologies, Inc.
  • 34. Zend Job Queue: Querying jobs • Searching for jobs  Search for an existing queued job of the same type  Useful for avoiding repetitive work  Returns the number of matching jobs along with job details © All rights reserved. Zend Technologies, Inc.
  • 35. Optimization vs. Complexity © All rights reserved. Zend Technologies, Inc.
  • 36. Optimization vs. Complexity • With every optimization complexity increaces  Who else dropped into the caching pitfall? • First: implement functionality • System performing well? • If not, check why • Get rid of bottlenecks © All rights reserved. Zend Technologies, Inc.
  • 37. Reducing Disk I/O The only component of a web server slower than the disk subsystem is the guy you ask to set it up. © All rights reserved. Zend Technologies, Inc.
  • 38. Reducing disk I/O • Use an opcode cache e.g. Zend Optimizer+  Avoids the need to open PHP files and compile the contents for every request.  Compiled „opcodes“ are instead held in shared memory for later reuse.  Particularly important for framework based projects where tens of files may be needed to answer one request.  Also saves some compiler time, but disk I/O savings are usually far more significant.  Most obvious benefit for scripts with short run times or running on loaded servers. © All rights reserved. Zend Technologies, Inc.
  • 39. Reducing disk I/O • Store static files elsewhere • Do not cache to the file system • Must have local storage? ...Use a ramdisk • Reduce PHP/Apache logging to minimal levels  E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR • Don‘t forget the Zend Server logs!  Search for log_verbosity_level in the configuration © All rights reserved. Zend Technologies, Inc.
  • 40. File system concerns • EXT3 – The default problem  For a web server ReiserFS can be 20x (or more) faster, really!  Even XFS is 2.5x faster  If you must use EXT3/4 then throw memory at the server • My NFS/Samba server is fast... Honest!  Even „fast“ NFS servers have terrible performance under load  Older implementations cannot use buffer cache  Poor scalability • Distributed file systems  Extremely poor scalability © All rights reserved. Zend Technologies, Inc.
  • 41. PHP uses your network • PHP communicates with network services like  Databases (ex: MySQL, Oracle)  Caching systems (ex: Memcache, Redis ..)  Job Queue Systems (ex: Zend Job Queue, RabbitMQ )  Session Clustering Daemon (ex: Zend Session Clustering) • If one of these services overloads the network then all other suffer from slowdown  Network congestion  Insufficient bandwidth  High latency © All rights reserved. Zend Technologies, Inc.
  • 42. So long... • …and thanks for all the fish. © All rights reserved. Zend Technologies, Inc.
  • 43. Turbocharging PHP Applications With Zend Server. Eric Ritchie (eric@zend.com) © All rights reserved. Zend Technologies, Inc.