SlideShare una empresa de Scribd logo
1 de 46
Descargar para leer sin conexión
PHP Go VROOOM!
    How to take a site from slow to go
   This talk is for beginners
   This is not “how to profile PHP”
   This is not “how to use HipHop”
   This is not how to profile your network
   Velma would be bored (you might be too)
   I will no doubt rant




Disclaimer
PHP is NOT your problem!*
*95.99% of the time
   Client Side                 IO
   Server Side                 Database
                                Frameworks
                                Hardware




    Let the Lecture Begin!




Why your app is slow…
Client Side
Do you want some Expires with that?
 http://developer.yahoo.com/yslow/
 http://code.google.com/speed/page-
  speed/
 http://tools.pingdom.com/
 http://www.fiddler2.com/fiddler2/




Profile – Don’t Guess!
   Make it external
   One file – minimized and compressed
    (minify)
   Put it at the top
   Use sprites for images
   Avoid expressions
   No @import
   Use conditional tags for IE issues, not css
    hacks
   Specific Selectors
   Give images dimensions


CSS
   Make it external
   One file – minimized and compressed
    (minify)
   Put it at the bottom
   Or defer the loading completely
   Use a well maintained framework
   document.write is a bad bad thing




Javascript
   Use the right format – png, gif or jpg
   Compress that image – lots of
    compression tools available
   Keep them small
   Scale them on the server, not with html
    size/width
   Have a small, cacheable favicon.ico
   Use sprites for layouts



Images
 Keep them small
 Keep them very domain specific




Cookies (om nom nom)
   Compress, compress, compress
   Use a CDN and/or media server
   Reduce DNS Lookups
   No 404‟s, empty img/hrefs
   Avoid redirects
   Parallelize downloads
   Watch external script use! (fb, google,
    social anything)



HTTP Requests
   Use cache control headers!
    ◦   Expires
    ◦   Last-Modified
    ◦   (best)
    ◦   Cache-Control
    ◦   Etag
    ◦   (harder to get right)
   Be kind to proxies as well




Client Side Caching
 http://developer.yahoo.com/performance/
  rules.html
 http://code.google.com/speed/page-
  speed/docs/rules_intro.html
 http://www.w3.org/Protocols/rfc2616/rfc2
  616.html
 Use the Google




Reference
Server Setup
Have you hugged your sysadmin today?
 Apache Bench
 Siege
 Http_Load
 JMeter




Profile, Don’t Guess!
 Security
 Speed
 Some Pain (worth it)
 Compile your own – it‟s faster then the
  distros!
    ◦ Drop your debug data
    ◦ Tune to your architecture
    ◦ At the very least do PHP, Server, Database




Upgrade your Software
“memcache does precisely f**k all for
 opcode caching” – Michael Maclean

This is the #1 best way to speed up your
 PHP site




Install APC (or something)
   Simple servers for static content
   Cache full pages and bypass PHP
   Dynamic images and CSS are a pain, find
    another solution
   CDN solutions are more affordable then
    ever before
   run a reverse proxy-cache




Don’t Use PHP and Use a CDN
Pick the right Tools
 Add more CPUs or more cores
 Add more RAM
 Use RAID or Solid State drives
 Network can definitely be a bottleneck –
  but like PHP it‟s the last thing to fix - hire
  a really smart guy




Hardware
 http://assets.en.oreilly.com/1/event/44/S
  calable%20Internet%20Architectures%20
  Presentation%202.pdf
 http://ilia.ws/files/Moscow2010_Optimizat
  ion_Mistakes.pdf
 http://people.apache.org/~sctemme/Apco
  nEU2006/FR4/FR4_Performance_Up.pdf
 http://omniti.com/surge/2011




Resources
Database
Use indexes people!
 Mysql – has profiler built in
 Postgresql – turn on logging and use
  analyzer on logs
 SQL Server – built in profiler
 MongoDB – built in profiler




Profile – Don’t Guess!
   Do not guess
   Add indexes where needed
   Sometimes it‟s faster to do the work in
    PHP
   Log on the PHP side, count on the PHP
    side… then do it on the server side too
   Always try to do fewer queries




Analyze your Queries
   Query Caching
    ◦ PHP side – cache generated queries
    ◦ Server side – query cache
   Results Caching
    ◦ Memcached is your friend
      Libmemcached = php‟s memcached (faster, non-
       portable)
      php sockets = php‟s memcache (slower,
       completely portable)
    ◦ File caching – sometimes IO is faster then db



Cache Everything
 Use transactions as appropriate
 Normalize your data (or use nosql)
 Minimize connections to the db
 Foreign keys can be slower, use cautiously




Best Practices are “Best” for a
Reason
 http://dev.mysql.com/doc/refman/5.0/en/
  optimization.html
 http://wiki.postgresql.org/wiki/Performan
  ce_Optimization
 http://msdn.microsoft.com/en-
  us/library/ff647793.aspx




Resources
PHP Optimization
echo not print… are you kidding me?
 XhProf
 Xdebug
 DBG (free and pay versions)
 APD – older but serviceable


 Inclued
 Memtrack
 Scream (also in xdebug)




Profile – Don’t Guess
“We should forget about small efficiencies,
say about 97% of the time: premature
  optimization is the root of all evil.”
- Donald Knuth


“Knowing when optimization is premature
  defines the difference between the master
  engineer and the apprentice.”
- Theo Schlossnagle



The Boss knows Best
 In-memory sessions are faster than disk
  or database equivalents. (mm, apc,
  wincache or memcache)
 Cache pages partially, or fully – store in
  memcache, have apache bypass PHP
 Cache any and everything
 Cache in layers – browser, full page,
  partial page, data, query results,
  application settings


Cache
   Gearman it
   Fork it
   Cron it
   Exec it
   Parallelization needs communication
    though!




Farm it out
 Reflection is nice – but it is VERY slow and
  memory heavy
 This kind of job is much better when
  handed off to C (yaml extension, for
  example)
 Writing extra code is worth the
  performance improvement
 Just because you CAN do something in
  PHP just like $lang doesn‟t mean that‟s
  the best solution

Avoid Runtime Introspection
   Avoid lots of stats
   Use an opcode cache (yes, I‟m saying it
    AGAIN)
   Try not to have too many files in a
    directory
   include_path as short as possible
   Use absolute paths




File and I/O
“I'm saying that if your autoloader is a
  significant fraction of the work your app
  does, then you are either Doing It
  Wrong™, or really unlikely, Doing It Very
  Well Indeed™ I know which I favour”
  -Michael Maclean




Balance Speed and Maintainability
Autoload and Includes
 NFS is of the devil – do not use it
 Errors are always created, even if you
  don‟t see them
    ◦ error_reporting(-1);
   @ is terrible! Set and restore error
    handler if you know something will spit,
    it‟s STILL faster




Very Bad Things
   „‟ is a wee bit faster than “”
   echo not print
   Don‟t use magic methods
   ++$i not $i++
   $_SERVER['REQUEST_TIME'] not time()
   static methods are faster
   $function() not call_user_func(„function‟)
   arrays are faster then objects



Micro Optimizations (Here be Evil)
   http://xdebug.org
   https://github.com/jokkedk/webgrind
   https://github.com/facebook/xhprof
   http://pecl.php.net/package/inclued
   https://github.com/eexit/Inclued
   http://pecl.php.net/package/scream
   http://pecl.php.net/package/memtrack




Resources
Frameworks
Sure you wrote the code faster…
Trick them into running faster…
“You are trading „development speed‟ for
  „processing speed‟ … all you do is waste all day
  reading docs to produce a half-assed project”
– Bob Majdak Jr

“ORMs are great for automating the sort of query
  that an idiot could write, and useless for
  anything non-trivial.”
– Greg Chiasson

http://highscalability.com/blog/2011/5/2/stack-
  overflow-makes-slow-pages-100x-faster-by-
  simple-sql-tu.html



ORMS
   Remove require/include calls and use
    autoloader or include_all files
   Avoid lots of configuration in parseable
    files (yaml, ini, etc)
   Turn off Debug features
   Use any sort of database caching available
   Watch your “dispatch loops” – write
    something custom if you need to
   Watch Plugin loading of all types


Frameworks
   Switch to another system (lots of importers)
   Use a cache plugin – or two, or three
   Keep wordpress up to date
   Don‟t use a lot of plugins
   Don‟t use the wp-db-abstraction plugin or
    any other plugin doing crazy things to the
    core
   It‟s just PHP, do all the PHP things too!



Wordpress
   Install a Cache          Install a Cache
    plugin                    plugin
   Limit other Plugins      Limit other Plugins
    in use                    in use
   Disable anonymous        Make sure
    sessions                  debugging is off in
   Use a simple theme        production
   All the other PHP        Turn off statistics
    stuff                    All the other PHP
                              stuff


Drupal, Joomla
   http://groups.drupal.org/high-performance
   http://codex.wordpress.org/WordPress_Opti
    mization
   http://www.joomlaperformance.com/
   http://www.brandonsavage.net/micro-
    optimizations-that-dont-matter/
   http://weierophinney.net/matthew/archives/
    245-Autoloading-Benchmarks.html
   http://framework.zend.com/manual/en/perfo
    rmance.html
   http://www.endyourif.com/optimizing-
    cakephp-websites/
   http://trac.symfony-
    project.org/wiki/Optimization
Resources
Write it in C
When PHP actually IS the problem
   http://emsmith.net
   http://joind.in/3422
   auroraeosrose@gmail.com
   IRC – freenode – auroraeosrose
   #php-gtk #coapp




Questions?

Más contenido relacionado

La actualidad más candente

PyGrunn 2017 - Django Performance Unchained - slides
PyGrunn 2017 - Django Performance Unchained - slidesPyGrunn 2017 - Django Performance Unchained - slides
PyGrunn 2017 - Django Performance Unchained - slidesArtur Barseghyan
 
Understanding PHP objects
Understanding PHP objectsUnderstanding PHP objects
Understanding PHP objectsjulien pauli
 
Puppet for Sys Admins
Puppet for Sys AdminsPuppet for Sys Admins
Puppet for Sys AdminsPuppet
 
PHP language presentation
PHP language presentationPHP language presentation
PHP language presentationAnnujj Agrawaal
 
Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)julien pauli
 
Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Alena Holligan
 
Building a Dynamic Website Using Django
Building a Dynamic Website Using DjangoBuilding a Dynamic Website Using Django
Building a Dynamic Website Using DjangoNathan Eror
 
Puppet Camp Berlin 2014: Manageable puppet infrastructure
Puppet Camp Berlin 2014: Manageable puppet infrastructurePuppet Camp Berlin 2014: Manageable puppet infrastructure
Puppet Camp Berlin 2014: Manageable puppet infrastructurePuppet
 
Getting started with Django 1.8
Getting started with Django 1.8Getting started with Django 1.8
Getting started with Django 1.8rajkumar2011
 
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015Fernando Hamasaki de Amorim
 
Auto-loading of Drupal CCK Nodes
Auto-loading of Drupal CCK NodesAuto-loading of Drupal CCK Nodes
Auto-loading of Drupal CCK Nodesnihiliad
 
Web develop in flask
Web develop in flaskWeb develop in flask
Web develop in flaskJim Yeh
 
Professional Help for PowerShell Modules
Professional Help for PowerShell ModulesProfessional Help for PowerShell Modules
Professional Help for PowerShell ModulesJune Blender
 
Mysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionMysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionjulien pauli
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principlesPerl Careers
 

La actualidad más candente (20)

Cross platform php
Cross platform phpCross platform php
Cross platform php
 
Php on Windows
Php on WindowsPhp on Windows
Php on Windows
 
Ant
Ant Ant
Ant
 
PyGrunn 2017 - Django Performance Unchained - slides
PyGrunn 2017 - Django Performance Unchained - slidesPyGrunn 2017 - Django Performance Unchained - slides
PyGrunn 2017 - Django Performance Unchained - slides
 
Understanding PHP objects
Understanding PHP objectsUnderstanding PHP objects
Understanding PHP objects
 
Puppet for Sys Admins
Puppet for Sys AdminsPuppet for Sys Admins
Puppet for Sys Admins
 
PHP language presentation
PHP language presentationPHP language presentation
PHP language presentation
 
Introduce Django
Introduce DjangoIntroduce Django
Introduce Django
 
Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)
 
Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016
 
Building a Dynamic Website Using Django
Building a Dynamic Website Using DjangoBuilding a Dynamic Website Using Django
Building a Dynamic Website Using Django
 
Puppet Camp Berlin 2014: Manageable puppet infrastructure
Puppet Camp Berlin 2014: Manageable puppet infrastructurePuppet Camp Berlin 2014: Manageable puppet infrastructure
Puppet Camp Berlin 2014: Manageable puppet infrastructure
 
Getting started with Django 1.8
Getting started with Django 1.8Getting started with Django 1.8
Getting started with Django 1.8
 
Puppet @ Seat
Puppet @ SeatPuppet @ Seat
Puppet @ Seat
 
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
 
Auto-loading of Drupal CCK Nodes
Auto-loading of Drupal CCK NodesAuto-loading of Drupal CCK Nodes
Auto-loading of Drupal CCK Nodes
 
Web develop in flask
Web develop in flaskWeb develop in flask
Web develop in flask
 
Professional Help for PowerShell Modules
Professional Help for PowerShell ModulesProfessional Help for PowerShell Modules
Professional Help for PowerShell Modules
 
Mysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionMysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extension
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principles
 

Similar a Php go vrooom!

Drupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp NorthDrupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp NorthPhilip Norton
 
Improving Drupal Performances
Improving Drupal PerformancesImproving Drupal Performances
Improving Drupal PerformancesVladimir Ilic
 
scale_perf_best_practices
scale_perf_best_practicesscale_perf_best_practices
scale_perf_best_practiceswebuploader
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindSam Keen
 
Speeding up your Drupal site
Speeding up your Drupal siteSpeeding up your Drupal site
Speeding up your Drupal siteRonan Berder
 
Apache Con 2008 Top 10 Mistakes
Apache Con 2008 Top 10 MistakesApache Con 2008 Top 10 Mistakes
Apache Con 2008 Top 10 MistakesJohn Coggeshall
 
Top 10 Scalability Mistakes
Top 10 Scalability MistakesTop 10 Scalability Mistakes
Top 10 Scalability MistakesJohn Coggeshall
 
Joomla! Performance on Steroids
Joomla! Performance on SteroidsJoomla! Performance on Steroids
Joomla! Performance on SteroidsSiteGround.com
 
Orlando DNN Usergroup Pres 12/06/11
Orlando DNN Usergroup Pres 12/06/11Orlando DNN Usergroup Pres 12/06/11
Orlando DNN Usergroup Pres 12/06/11Jess Coburn
 
Make Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speedMake Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speedAndy Kucharski
 
Site Speed = Success – Optimising WordPress from the Server Up - Presented by...
Site Speed = Success – Optimising WordPress from the Server Up - Presented by...Site Speed = Success – Optimising WordPress from the Server Up - Presented by...
Site Speed = Success – Optimising WordPress from the Server Up - Presented by...WordCamp Harare
 
WordCamp Harare 2016 - Site Speed = Success
WordCamp Harare 2016 - Site Speed = SuccessWordCamp Harare 2016 - Site Speed = Success
WordCamp Harare 2016 - Site Speed = SuccessAnthony Somerset
 
Magento Performance Optimization 101
Magento Performance Optimization 101Magento Performance Optimization 101
Magento Performance Optimization 101Angus Li
 
Performance and optimization CakeFest 2014
Performance and optimization CakeFest 2014Performance and optimization CakeFest 2014
Performance and optimization CakeFest 2014markstory
 
Drupal performance and scalability
Drupal performance and scalabilityDrupal performance and scalability
Drupal performance and scalabilityTwinbit
 
2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida real2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida realPHP Conference Argentina
 
Top 30 Scalability Mistakes
Top 30 Scalability MistakesTop 30 Scalability Mistakes
Top 30 Scalability MistakesJohn Coggeshall
 
WE18_Performance_Up.ppt
WE18_Performance_Up.pptWE18_Performance_Up.ppt
WE18_Performance_Up.pptwebhostingguy
 

Similar a Php go vrooom! (20)

Drupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp NorthDrupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp North
 
Scaling PHP apps
Scaling PHP appsScaling PHP apps
Scaling PHP apps
 
Improving Drupal Performances
Improving Drupal PerformancesImproving Drupal Performances
Improving Drupal Performances
 
scale_perf_best_practices
scale_perf_best_practicesscale_perf_best_practices
scale_perf_best_practices
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / Webgrind
 
Speeding up your Drupal site
Speeding up your Drupal siteSpeeding up your Drupal site
Speeding up your Drupal site
 
Apache Con 2008 Top 10 Mistakes
Apache Con 2008 Top 10 MistakesApache Con 2008 Top 10 Mistakes
Apache Con 2008 Top 10 Mistakes
 
Top 10 Scalability Mistakes
Top 10 Scalability MistakesTop 10 Scalability Mistakes
Top 10 Scalability Mistakes
 
Joomla! Performance on Steroids
Joomla! Performance on SteroidsJoomla! Performance on Steroids
Joomla! Performance on Steroids
 
Orlando DNN Usergroup Pres 12/06/11
Orlando DNN Usergroup Pres 12/06/11Orlando DNN Usergroup Pres 12/06/11
Orlando DNN Usergroup Pres 12/06/11
 
Make Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speedMake Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speed
 
Site Speed = Success – Optimising WordPress from the Server Up - Presented by...
Site Speed = Success – Optimising WordPress from the Server Up - Presented by...Site Speed = Success – Optimising WordPress from the Server Up - Presented by...
Site Speed = Success – Optimising WordPress from the Server Up - Presented by...
 
WordCamp Harare 2016 - Site Speed = Success
WordCamp Harare 2016 - Site Speed = SuccessWordCamp Harare 2016 - Site Speed = Success
WordCamp Harare 2016 - Site Speed = Success
 
Magento Performance Optimization 101
Magento Performance Optimization 101Magento Performance Optimization 101
Magento Performance Optimization 101
 
Performance and optimization CakeFest 2014
Performance and optimization CakeFest 2014Performance and optimization CakeFest 2014
Performance and optimization CakeFest 2014
 
Drupal performance and scalability
Drupal performance and scalabilityDrupal performance and scalability
Drupal performance and scalability
 
2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida real2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida real
 
Drupal development
Drupal development Drupal development
Drupal development
 
Top 30 Scalability Mistakes
Top 30 Scalability MistakesTop 30 Scalability Mistakes
Top 30 Scalability Mistakes
 
WE18_Performance_Up.ppt
WE18_Performance_Up.pptWE18_Performance_Up.ppt
WE18_Performance_Up.ppt
 

Más de Elizabeth Smith

Más de Elizabeth Smith (20)

Welcome to the internet
Welcome to the internetWelcome to the internet
Welcome to the internet
 
Database theory and modeling
Database theory and modelingDatabase theory and modeling
Database theory and modeling
 
Taming the resource tiger
Taming the resource tigerTaming the resource tiger
Taming the resource tiger
 
Modern sql
Modern sqlModern sql
Modern sql
 
Php extensions
Php extensionsPhp extensions
Php extensions
 
Taming the resource tiger
Taming the resource tigerTaming the resource tiger
Taming the resource tiger
 
Php internal architecture
Php internal architecturePhp internal architecture
Php internal architecture
 
Taming the tiger - pnwphp
Taming the tiger - pnwphpTaming the tiger - pnwphp
Taming the tiger - pnwphp
 
Php extensions
Php extensionsPhp extensions
Php extensions
 
Php extensions
Php extensionsPhp extensions
Php extensions
 
Php’s guts
Php’s gutsPhp’s guts
Php’s guts
 
Lexing and parsing
Lexing and parsingLexing and parsing
Lexing and parsing
 
Hacking with hhvm
Hacking with hhvmHacking with hhvm
Hacking with hhvm
 
Security is not a feature
Security is not a featureSecurity is not a feature
Security is not a feature
 
Using unicode with php
Using unicode with phpUsing unicode with php
Using unicode with php
 
Mentoring developers-php benelux-2014
Mentoring developers-php benelux-2014Mentoring developers-php benelux-2014
Mentoring developers-php benelux-2014
 
Using unicode with php
Using unicode with phpUsing unicode with php
Using unicode with php
 
Socket programming with php
Socket programming with phpSocket programming with php
Socket programming with php
 
Mentoring developers
Mentoring developersMentoring developers
Mentoring developers
 
Do the mentor thing
Do the mentor thingDo the mentor thing
Do the mentor thing
 

Último

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Último (20)

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

Php go vrooom!

  • 1. PHP Go VROOOM! How to take a site from slow to go
  • 2. This talk is for beginners  This is not “how to profile PHP”  This is not “how to use HipHop”  This is not how to profile your network  Velma would be bored (you might be too)  I will no doubt rant Disclaimer
  • 3. PHP is NOT your problem!* *95.99% of the time
  • 4. Client Side  IO  Server Side  Database  Frameworks  Hardware Let the Lecture Begin! Why your app is slow…
  • 5. Client Side Do you want some Expires with that?
  • 6.  http://developer.yahoo.com/yslow/  http://code.google.com/speed/page- speed/  http://tools.pingdom.com/  http://www.fiddler2.com/fiddler2/ Profile – Don’t Guess!
  • 7. Make it external  One file – minimized and compressed (minify)  Put it at the top  Use sprites for images  Avoid expressions  No @import  Use conditional tags for IE issues, not css hacks  Specific Selectors  Give images dimensions CSS
  • 8. Make it external  One file – minimized and compressed (minify)  Put it at the bottom  Or defer the loading completely  Use a well maintained framework  document.write is a bad bad thing Javascript
  • 9. Use the right format – png, gif or jpg  Compress that image – lots of compression tools available  Keep them small  Scale them on the server, not with html size/width  Have a small, cacheable favicon.ico  Use sprites for layouts Images
  • 10.  Keep them small  Keep them very domain specific Cookies (om nom nom)
  • 11. Compress, compress, compress  Use a CDN and/or media server  Reduce DNS Lookups  No 404‟s, empty img/hrefs  Avoid redirects  Parallelize downloads  Watch external script use! (fb, google, social anything) HTTP Requests
  • 12. Use cache control headers! ◦ Expires ◦ Last-Modified ◦ (best) ◦ Cache-Control ◦ Etag ◦ (harder to get right)  Be kind to proxies as well Client Side Caching
  • 13.  http://developer.yahoo.com/performance/ rules.html  http://code.google.com/speed/page- speed/docs/rules_intro.html  http://www.w3.org/Protocols/rfc2616/rfc2 616.html  Use the Google Reference
  • 14. Server Setup Have you hugged your sysadmin today?
  • 15.  Apache Bench  Siege  Http_Load  JMeter Profile, Don’t Guess!
  • 16.  Security  Speed  Some Pain (worth it)  Compile your own – it‟s faster then the distros! ◦ Drop your debug data ◦ Tune to your architecture ◦ At the very least do PHP, Server, Database Upgrade your Software
  • 17. “memcache does precisely f**k all for opcode caching” – Michael Maclean This is the #1 best way to speed up your PHP site Install APC (or something)
  • 18. Simple servers for static content  Cache full pages and bypass PHP  Dynamic images and CSS are a pain, find another solution  CDN solutions are more affordable then ever before  run a reverse proxy-cache Don’t Use PHP and Use a CDN
  • 19. Pick the right Tools
  • 20.  Add more CPUs or more cores  Add more RAM  Use RAID or Solid State drives  Network can definitely be a bottleneck – but like PHP it‟s the last thing to fix - hire a really smart guy Hardware
  • 21.  http://assets.en.oreilly.com/1/event/44/S calable%20Internet%20Architectures%20 Presentation%202.pdf  http://ilia.ws/files/Moscow2010_Optimizat ion_Mistakes.pdf  http://people.apache.org/~sctemme/Apco nEU2006/FR4/FR4_Performance_Up.pdf  http://omniti.com/surge/2011 Resources
  • 23.  Mysql – has profiler built in  Postgresql – turn on logging and use analyzer on logs  SQL Server – built in profiler  MongoDB – built in profiler Profile – Don’t Guess!
  • 24. Do not guess  Add indexes where needed  Sometimes it‟s faster to do the work in PHP  Log on the PHP side, count on the PHP side… then do it on the server side too  Always try to do fewer queries Analyze your Queries
  • 25. Query Caching ◦ PHP side – cache generated queries ◦ Server side – query cache  Results Caching ◦ Memcached is your friend  Libmemcached = php‟s memcached (faster, non- portable)  php sockets = php‟s memcache (slower, completely portable) ◦ File caching – sometimes IO is faster then db Cache Everything
  • 26.  Use transactions as appropriate  Normalize your data (or use nosql)  Minimize connections to the db  Foreign keys can be slower, use cautiously Best Practices are “Best” for a Reason
  • 27.  http://dev.mysql.com/doc/refman/5.0/en/ optimization.html  http://wiki.postgresql.org/wiki/Performan ce_Optimization  http://msdn.microsoft.com/en- us/library/ff647793.aspx Resources
  • 28. PHP Optimization echo not print… are you kidding me?
  • 29.  XhProf  Xdebug  DBG (free and pay versions)  APD – older but serviceable  Inclued  Memtrack  Scream (also in xdebug) Profile – Don’t Guess
  • 30. “We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.” - Donald Knuth “Knowing when optimization is premature defines the difference between the master engineer and the apprentice.” - Theo Schlossnagle The Boss knows Best
  • 31.  In-memory sessions are faster than disk or database equivalents. (mm, apc, wincache or memcache)  Cache pages partially, or fully – store in memcache, have apache bypass PHP  Cache any and everything  Cache in layers – browser, full page, partial page, data, query results, application settings Cache
  • 32. Gearman it  Fork it  Cron it  Exec it  Parallelization needs communication though! Farm it out
  • 33.  Reflection is nice – but it is VERY slow and memory heavy  This kind of job is much better when handed off to C (yaml extension, for example)  Writing extra code is worth the performance improvement  Just because you CAN do something in PHP just like $lang doesn‟t mean that‟s the best solution Avoid Runtime Introspection
  • 34. Avoid lots of stats  Use an opcode cache (yes, I‟m saying it AGAIN)  Try not to have too many files in a directory  include_path as short as possible  Use absolute paths File and I/O
  • 35. “I'm saying that if your autoloader is a significant fraction of the work your app does, then you are either Doing It Wrong™, or really unlikely, Doing It Very Well Indeed™ I know which I favour” -Michael Maclean Balance Speed and Maintainability Autoload and Includes
  • 36.  NFS is of the devil – do not use it  Errors are always created, even if you don‟t see them ◦ error_reporting(-1);  @ is terrible! Set and restore error handler if you know something will spit, it‟s STILL faster Very Bad Things
  • 37. „‟ is a wee bit faster than “”  echo not print  Don‟t use magic methods  ++$i not $i++  $_SERVER['REQUEST_TIME'] not time()  static methods are faster  $function() not call_user_func(„function‟)  arrays are faster then objects Micro Optimizations (Here be Evil)
  • 38. http://xdebug.org  https://github.com/jokkedk/webgrind  https://github.com/facebook/xhprof  http://pecl.php.net/package/inclued  https://github.com/eexit/Inclued  http://pecl.php.net/package/scream  http://pecl.php.net/package/memtrack Resources
  • 39. Frameworks Sure you wrote the code faster… Trick them into running faster…
  • 40. “You are trading „development speed‟ for „processing speed‟ … all you do is waste all day reading docs to produce a half-assed project” – Bob Majdak Jr “ORMs are great for automating the sort of query that an idiot could write, and useless for anything non-trivial.” – Greg Chiasson http://highscalability.com/blog/2011/5/2/stack- overflow-makes-slow-pages-100x-faster-by- simple-sql-tu.html ORMS
  • 41. Remove require/include calls and use autoloader or include_all files  Avoid lots of configuration in parseable files (yaml, ini, etc)  Turn off Debug features  Use any sort of database caching available  Watch your “dispatch loops” – write something custom if you need to  Watch Plugin loading of all types Frameworks
  • 42. Switch to another system (lots of importers)  Use a cache plugin – or two, or three  Keep wordpress up to date  Don‟t use a lot of plugins  Don‟t use the wp-db-abstraction plugin or any other plugin doing crazy things to the core  It‟s just PHP, do all the PHP things too! Wordpress
  • 43. Install a Cache  Install a Cache plugin plugin  Limit other Plugins  Limit other Plugins in use in use  Disable anonymous  Make sure sessions debugging is off in  Use a simple theme production  All the other PHP  Turn off statistics stuff  All the other PHP stuff Drupal, Joomla
  • 44. http://groups.drupal.org/high-performance  http://codex.wordpress.org/WordPress_Opti mization  http://www.joomlaperformance.com/  http://www.brandonsavage.net/micro- optimizations-that-dont-matter/  http://weierophinney.net/matthew/archives/ 245-Autoloading-Benchmarks.html  http://framework.zend.com/manual/en/perfo rmance.html  http://www.endyourif.com/optimizing- cakephp-websites/  http://trac.symfony- project.org/wiki/Optimization Resources
  • 45. Write it in C When PHP actually IS the problem
  • 46. http://emsmith.net  http://joind.in/3422  auroraeosrose@gmail.com  IRC – freenode – auroraeosrose  #php-gtk #coapp Questions?