• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Optimizing LAMPhp Applications

Optimizing LAMPhp Applications



Slides from my talk at RootConf 2012, Bangalore (http://rootconf.in/bangalore2012). The talk covers some general tips and practices to be followed when building web applications for scale on the ...

Slides from my talk at RootConf 2012, Bangalore (http://rootconf.in/bangalore2012). The talk covers some general tips and practices to be followed when building web applications for scale on the LAMPhp stack.



Total Views
Views on SlideShare
Embed Views



2 Embeds 26

http://www.linkedin.com 24
https://www.linkedin.com 2



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    Optimizing LAMPhp Applications Optimizing LAMPhp Applications Presentation Transcript

    • Optimizing LAMPhp Applications RootConf, 26th May 2012 Piyush Goel Capillary Technologies piyush.goel@capillary.co.in
    • Optimization “Premature Optimization is root of all Evil” - Donald Knuth Direction and Goal Oriented Takes Effort and Time No Silver Bullets, only guidelines and practices 26/05/2012 RootConf
    • Web Applications are like Onions !! 26/05/2012 RootConf
    • Web Applications are like Onions !! Layered Architecture Rocks !! 26/05/2012 RootConf
    • 26/05/2012 RootConf
    • Apache Apache 1.3 Pre-forked Model 1 process per request Robust: One crashed process dosen’t affect the others Not as fast as some other possible designs - Really ?? Apache 2.0 Multi-Processing Modules mpm_prefork mpm_worker 26/05/2012 RootConf
    • Tuning Apache• MaxClients• StartServers • Avoid thundering effect• MaxRequestsPerChild • Profiling first• AllowOverride• HostnameLookups• TCP Buffering• Compression : mod_deflate/mod_gzip • May cause spike in CPU 26/05/2012 RootConf
    • Tuning Apache Contd • KeepAlive • N objects per page • t1 seconds for TCP connection • t2 seconds per object • K seconds timeout • Non-KeepAlive : N * (t1 + t2) • KeepAlive : N * (t2) + t1 + K • For KeepAlive to perform better K < t1 * ( N -1 ) Ref: http://www.slideshare.net/techdude/building-scalable-php-applications 26/05/2012 RootConf
    • Tuning Apache Contd… Offload Static Files Apache + PHP not really good at static files Use Nginx or Lighttpd ( or anything else ) 26/05/2012 RootConf
    • 26/05/2012 RootConf
    • PHP Opcode Caching eAccelerator APC Zend_Cache Minimize Includes 1 include: 1 stat and realpath system call Relative paths : too many stat system calls Minimal include_path Reduce logging : prevents disk writes error_reporting = E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR 26/05/2012 RootConf
    • PHP Optimization contd… Output Buffering ob_start / ob_flush Compression ZLIB module ob_gzhandler 26/05/2012 RootConf
    • 26/05/2012 RootConf
    • MySQL under the hood 26/05/2012 RootConf
    • MySQL Tuning Hardware Config: Typical workloads are Memory/IO Bound Size of working data set Storage Engine: MyISAM vs InnoDB InnoDB works well in most cases, unless you need full text search Cache static data: Memcached Swap Space: Actually made us 26/05/2012 RootConf
    • MySQL Tuning Contd… key_buffer_size innodb_buffer_pool_size innodb_log_file_size innodb_log_buffer_size innodb_flush_log_at_trx_commit thread_cache query_cache_size Refer: 1) http://dev.mysql.com 2) http://www.mysqlperformanceblog.com/2006/09/29/what-to- tune-in-mysql-server-after-installation/ 26/05/2012 RootConf
    • MySQL Tuning contd… Slow Query Logs: 1) Most important 2) Regular Monitoring 3) log_queries_not_using_indexes Analyze Tables periodically Optimize Table Abrupt query behaviors Avoid big deletes Use soft deletes Explain & Percona’s query visualizer 26/05/2012 RootConf
    • Tools and Practices26/05/2012 RootConf
    • Tools and Practices Profiling: Profile regularly XDebug / Advanced PHP Debugger ( APD ) KCachegrind / Webgrind Instrument Code with Timers Load Testing / Benchmarking Apache Bench ( ab ) httperf JMeter ( personal favorite ) Strong Monitoring and Alerting Store exhaustively, Alert Judiciously Ganglia, Cacti Nagios etc 26/05/2012 RootConf
    • Tools & Practices 1) vmstat : Extremely useful for finding bottlenecks 2) iostat : Disk activity, useful for db systems 3) pmap : Process memory dump 4) strace: Analyzing system calls 5) sar : System activity reporter, good for postanalysis 6) netstat : Complete network dump 7) htop : Prefer over top 8) cut / tr : Analyzing Apache Access Logs 26/05/2012 RootConf
    • What It shouldn’t be !! SysAdmins vs Developers 26/05/2012 RootConf
    • Personal Rant/Advice Understand what’s happening under the hood 26/05/2012 RootConf
    • THANKS !Capillary is looking for awesome DevAdmins! piyush.goel@capillary.co.in career-tech@capillary.co.in26/05/2012 RootConf