22
PHP and Web Server Performace Đoàn Văn Tuyển [email protected]

Php & web server performace

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Php & web server performace

PHP and Web Server Performace

Đoàn Văn Tuyể[email protected]

Page 2: Php & web server performace

Who am I

CTO of ADFLEX.VN

Adflex is a Mobile Ads Network. It has:● 5M device for 3 month● 800K active device / day● 10M PHP Request / day● Avg server time 2-20ms● With only 2 server

Page 3: Php & web server performace

Contents

Overview Opcode cache Web Performance Best Practices

− CDN Nginx & Apache Cache Background Process Persitent connection Tools

Page 4: Php & web server performace

1. Overview

Page 5: Php & web server performace

2. Opcode cache

● APC● eAccelerator● ionCube PHP

Accelerator● XCache● Zend Accelerator

Page 6: Php & web server performace

3. Web Performance Best Practices

Google & Yahoo suggest “Web Performance Best Practices”

● Google => http://bit.ly/LinH3j● Yahoo > http://yhoo.it/1eSxRm8

Tools for Browser Google Pagespeed Yahoo slow

Page 7: Php & web server performace

3. Web Performance Best Practices

Use brower’s cache User external CSS & javascript Combine CSS & JS file Use a cookieless domain for static content Avoid 404 error Use Gzip Put CSS on top, javascript on bottom

Page 8: Php & web server performace

3. Web Performance Best Practices

Specify image size Reduce the size of image to fit with display are Minify HTML, CSS, Javascript Optimize Image CDN … bla...bla...

Page 9: Php & web server performace

3. Web Performance Best Practices

PageSpeed Module: All in One => http://bit.ly/1fHuYaQ

Page 10: Php & web server performace

3. Web Performance Best Practices

CDN

Only ~ 1.000đ / 1GB

Page 11: Php & web server performace

● Nginx for static file● Apache or FPM for PHP script

4. Nginx & Apache

Page 12: Php & web server performace

Apache MPM

How many CCU your system can handler?See http://fuscata.com/kb/set-maxclients-apache-prefork for detail.

<IfModule mpm_prefork_module> StartServers 5 MinSpareServers 5 MaxSpareServers 20 MaxClients 250 MaxRequestsPerChild 500</IfModule>

Page 13: Php & web server performace

5. Caching

What● Page cache

● Block cache

● Data cache

How● Write to file (and with APC)

● Memory: Memcache/Redis/APC

● Database

● Static/Global variable

Page 14: Php & web server performace

6. Background Process

● Resque● Gearman● RabbitMQ● Beanstalkd● ZeroMQ● ActiveMQ

or● Build it yourself

Page 15: Php & web server performace

7. Persitent connection

● Similar Connection Pool

● Default for MongoDB Driver

Page 16: Php & web server performace

8. Tools

New relic Profiling: xhprof Firebug, Pagespeed, Yahoo slow Misc

Page 17: Php & web server performace

New relic

For monitor

● Response time: min, max, avg

● Appdex score

● RAM, CPU, Process...

● Error/Alert

See: http://newrelic.com

Page 18: Php & web server performace

xhprof

Tool for profiling for

● Time for each function

● MemorySee: http://php.net/manual/en/book.xhprof.php

Page 19: Php & web server performace

Firebug, Pagespeed, Yahoo slow

Firebug●https://getfirebug.com

Pagespeed●https://developers.google.com/speed/pagespeed/insights_extensions

Yahoo Slow●http://developer.yahoo.com/yslow/

Page 20: Php & web server performace

Misc

JS● Perfomace variable

PHP● debug_print_backtrace()● microtime(true)● register_shutdown_function()● memory_usage()

Page 21: Php & web server performace

Q&A

Page 22: Php & web server performace

Reference

● http://java.dzone.com/articles/php-performance-crash-course

● http://on.fb.me/1hAc7vL

● https://developers.google.com/speed/docs/best-practices/rules_intro

● http://developer.yahoo.com/performance/rules.html

● http://www.slideshare.net/lonelywolf/web-optimization

● http://code.google.com/p/modpagespeed/

● https://github.com/pagespeed/ngx_pagespeed

● http://developer.yahoo.com/yslow/

● https://developers.google.com/speed/pagespeed/insights_extensions

● https://addons.mozilla.org/en-US/firefox/addon/firebug

● http://php.net/manual/en/book.apc.php

● http://php.net/manual/en/book.xhprof.php

● http://www.mdproductions.ca/guides/50-best-practices-to-optimize-php-code-performance

● http://www.chazzuka.com/63-best-practice-to-optimize-php-code-performances-58/

● http://fuscata.com/kb/set-maxclients-apache-prefork