0
PHP site optimization Demonstrating a Zend framework websiteperformance improvement and optimization.
Areas of improvementApplication FrameworkDatabaseNetwork LatencyIO ContentionCPU UtilizationNetwork ConnectivityOthers
Performance or Scalability. Both?Hiphop (Facebook implementation of php) is high performing but not scalable
Workload distribution of a page              request10% web server40% php processing50% database response10-15% improvemen...
Database performanceQuery simplificationQuery optimizationSchema tuningReplicationShardingClustering
Network LatencyHow to identify?When both page response and CPU usage are slowReasons?DNS Reverse Lookups, TCP Handshakes, ...
DNS Reverse LookupsUse ipaddress wherever possible
TCP HandshakesUse persistent connections to remote/local- network services wherever possible
Number of HopsTry to put servers on same switch or in the same  LAN.Physical layer and network layer trade offs to be avoi...
IO Contention
CPU Utilization
Network Connectivity
ORM optionsActive Record (made popular by Ruby on Rails)Data MapperCollectionDoctrineData access methods used by Yii, CI, ...
Active Record (AR)It is an object-relational mapping and object-   persistence patternIt binds a business object with a re...
Active Record Issues
Data Patterns in Zend Framework Zend_Controller_Front   Singleton   FrontController Zend_Db_Table   Table Data Gateway Zen...
Profiler with Zend_DB$db = Zend_Db::factory(Pdo_Mysql,      array(host => 127.0.0.1,     username => user1,     password =...
PregStripos is 2 times faster than pregctype_alnum is 5 times faster than pregCasting “if ($var == (int) $var)” is 5 times...
Magic methods__get, __set, __callUsed by Soap, data tables, java objectsUse sparingly and avoid too much recursion
Code AccelerationAPC, Zend OptimizerIncrease performance by 3-4 times
QueueQueueing is offloading long running tasks to queuing systemJob Queue  GearmanMessage Queue  ActiveMQ  AWS Simple Queu...
What not to doCaching should be the last thing to do. (Focus on performance optimization)Avoid LIKE queries. (Try Solr, Ze...
What to doMinimize require_once. Use autoloaderHorizontal architecture is better than vertical  ex. wide inheritance is be...
Benchmarking
Upcoming SlideShare
Loading in...5
×

Php Site Optimization

796

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
796
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
9
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Php Site Optimization"

  1. 1. PHP site optimization Demonstrating a Zend framework websiteperformance improvement and optimization.
  2. 2. Areas of improvementApplication FrameworkDatabaseNetwork LatencyIO ContentionCPU UtilizationNetwork ConnectivityOthers
  3. 3. Performance or Scalability. Both?Hiphop (Facebook implementation of php) is high performing but not scalable
  4. 4. Workload distribution of a page request10% web server40% php processing50% database response10-15% improvement easily achievable using a commonly used alternative stack i.e. Nginx + APC + Htmlcaching + Memcache + CDN
  5. 5. Database performanceQuery simplificationQuery optimizationSchema tuningReplicationShardingClustering
  6. 6. Network LatencyHow to identify?When both page response and CPU usage are slowReasons?DNS Reverse Lookups, TCP Handshakes, High number of hopsTools?Tcpdump, ping, traceroute ..
  7. 7. DNS Reverse LookupsUse ipaddress wherever possible
  8. 8. TCP HandshakesUse persistent connections to remote/local- network services wherever possible
  9. 9. Number of HopsTry to put servers on same switch or in the same LAN.Physical layer and network layer trade offs to be avoided
  10. 10. IO Contention
  11. 11. CPU Utilization
  12. 12. Network Connectivity
  13. 13. ORM optionsActive Record (made popular by Ruby on Rails)Data MapperCollectionDoctrineData access methods used by Yii, CI, Symphony ...
  14. 14. Active Record (AR)It is an object-relational mapping and object- persistence patternIt binds a business object with a relational record (row)AR class maps to a db table (or view)AR instance maps to a db table recordAR instance properties maps to db table record fieldsInstance methods act on a specific record
  15. 15. Active Record Issues
  16. 16. Data Patterns in Zend Framework Zend_Controller_Front Singleton FrontController Zend_Db_Table Table Data Gateway Zend_Log Factory Method Adapter
  17. 17. Profiler with Zend_DB$db = Zend_Db::factory(Pdo_Mysql, array(host => 127.0.0.1, username => user1, password => pwd, dbname, ex_db, profiler => true));After query execution using $db:-$prof = $db->getProfiler();$prof->getTotalElapsedSecs();$prof->getTotalNumQueries();
  18. 18. PregStripos is 2 times faster than pregctype_alnum is 5 times faster than pregCasting “if ($var == (int) $var)” is 5 times faster than preg_match(“/^d*$/”, $var)
  19. 19. Magic methods__get, __set, __callUsed by Soap, data tables, java objectsUse sparingly and avoid too much recursion
  20. 20. Code AccelerationAPC, Zend OptimizerIncrease performance by 3-4 times
  21. 21. QueueQueueing is offloading long running tasks to queuing systemJob Queue GearmanMessage Queue ActiveMQ AWS Simple Queue Service
  22. 22. What not to doCaching should be the last thing to do. (Focus on performance optimization)Avoid LIKE queries. (Try Solr, Zend_Lucene)
  23. 23. What to doMinimize require_once. Use autoloaderHorizontal architecture is better than vertical ex. wide inheritance is better than deep level inheritanceLazy loading / Load on DemandUse diagnostic tools Zend studio profiler, Code Tracing
  24. 24. Benchmarking
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×