37
www.mimos.my © 2009 MIMOS Berhad. All Rights Reserved. Turbocharge Your PHP with Nginx Errazudin Ishak

turbocharge your php with nginx - errazudin - phpnw2010

Embed Size (px)

DESCRIPTION

turbocharge your php with nginx by @errazudin #phpnw2010

Citation preview

Page 1: turbocharge your php with nginx - errazudin - phpnw2010

www.mimos.my © 2009 MIMOS Berhad. All Rights Reserved.

Turbocharge Your PHP with Nginx

Errazudin Ishak

Page 2: turbocharge your php with nginx - errazudin - phpnw2010

• me

• “engine X”

• nginx.conf

• ..with PHP

• Benchmark

• Samples

Agenda

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Page 3: turbocharge your php with nginx - errazudin - phpnw2010

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

"Apache is like Microsoft Word, it has a million options but you only need six. Nginx does those six things, and it does five of them 50 times faster than Apache." - Chris Lea, ChrisLea.com

http://www.abacuspub.com/fsd/catalog/s574.htm

Page 4: turbocharge your php with nginx - errazudin - phpnw2010

• Senior engineer @ Mimos Malaysia

• Focuses on web application development, deployment, performance and stability.

• 2009 : foss.my , MyGOSSCON

• 2010 : Entp. PHP Techtalk, BarcampKL, PHP Meetup, MOSC2010

Me

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Page 5: turbocharge your php with nginx - errazudin - phpnw2010

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Page 6: turbocharge your php with nginx - errazudin - phpnw2010

• Free

• X platform

• open-source

• (high-performance)

• lightweight

• HTTP server

• reverse proxy

• IMAP/POP3 proxy server

nginx

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Page 7: turbocharge your php with nginx - errazudin - phpnw2010

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

“I'm the author of nginx (pronounced "engine x")-Igor Sysoev(nginx creator)

http://noisetu.be/mirrors/jet_beetle/

Page 8: turbocharge your php with nginx - errazudin - phpnw2010

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Load BalanceStatic Content, Index filesReverse Proxy (with cache)Streaming

http://image.importtuner.com/f/miscellaneous/new-tomei-turbo-kits-for-sr/29774779/tomei-bolt-on-turbo-kit-for-sr.jpg

Page 9: turbocharge your php with nginx - errazudin - phpnw2010

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Loads of RequestLess memory footprintUse less CPUC10K Certified

http://www.litchfieldimports.co.uk/forum/gtr-engine-bay.jpg

Page 10: turbocharge your php with nginx - errazudin - phpnw2010

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Apache----------ProcessesThreadsHigh MemoryCPU OverheadPHP included as module (mod_php)

http://www.gtrblog.com/wp-content/uploads/2008/11/gtr-gt2-nurburgring-001.jpg

--------Async modelSingle ThreadLow MemoryLess CPUPHP as separate proc. over FastCGI

Page 11: turbocharge your php with nginx - errazudin - phpnw2010

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Numbers

http://www.scoobyworld.co.uk/catalog/images/BFamber-1.jpg

Page 12: turbocharge your php with nginx - errazudin - phpnw2010

Market Share for Top Servers Across All Domains

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Source :

Netcraft

213,458,815

Page 13: turbocharge your php with nginx - errazudin - phpnw2010

Market Share for Top Servers Across the Million Busiest Sites

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Source :

Netcraft

Page 14: turbocharge your php with nginx - errazudin - phpnw2010

Market Share for Top Servers Across All Domains

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Source :

Netcraft

227,225,642

Page 15: turbocharge your php with nginx - errazudin - phpnw2010

Market Share for Top Servers Across the Million Busiest Sites

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Source :

Netcraft

Page 16: turbocharge your php with nginx - errazudin - phpnw2010

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

http://www.autoguide.com/auto-news/wp-content/uploads/2010/09/The_Stig_Top_Gear_Eight.jpg

Who?

Page 17: turbocharge your php with nginx - errazudin - phpnw2010

Me uses nginx

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Page 18: turbocharge your php with nginx - errazudin - phpnw2010

Me uses nginx

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Page 19: turbocharge your php with nginx - errazudin - phpnw2010

We also..

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Page 20: turbocharge your php with nginx - errazudin - phpnw2010

We all love nginx…

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Page 21: turbocharge your php with nginx - errazudin - phpnw2010

Modules

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Mail, 3rd

Party

Optional

HTTP

Standard HTTP

Core

Page 22: turbocharge your php with nginx - errazudin - phpnw2010

Modules

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Main, Events

HTTP Core, HTTP Upstream, HTTP Access, HTTP Auth Basic, HTTP Auto Index, Browser, Charset, Empty gif, FastCGI, Geo, Gzip, HTTP Headers, Index, HTTP Referer, HTTP Limit Zone, HTTP Limit Requests, Log, Map,

Memchached, HTTP Proxy, Rewrite, SSI, User ID

HTTP Addition, Emb. Perl, FLV, Gzip Precompression, Random Index, GeoIP, Real IP, SSL, Stub Status, Substitution, WebDAV, Google Perftools,

XSLT, Secure Link, Image Filter

Mail Core, Mail Auth, Mail Proxy, Mail SSL

Page 23: turbocharge your php with nginx - errazudin - phpnw2010

• FastCGI

• PHP-FPM (FastCGI Process Manager)

• Bundled with PHP 5.3.3

Nginx with PHP

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Page 24: turbocharge your php with nginx - errazudin - phpnw2010

• persistent processes, ability to handle multiple requests.

• web server and gateway application communicate with sockets such as TCP

• web server forwards the client request to the gateway and receives the response within a single connection

• can be implemented on any platform with any programming language.

Nginx with PHP : FastCGI

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Page 25: turbocharge your php with nginx - errazudin - phpnw2010

server {

server_name mysite.com;

listen 80;

root /usr/share/mysite/www;

index index.html;

location / {

fastcgi_pass 127.0.0.1:9000;

fastcgi_param SCRIPT_FILENAME

$document_root$fastcgi_script_name;

fastcgi_param PATH_INFO $fastcgi_script_name;

include fastcgi_params;

}

}

Nginx with PHP : FastCGI

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Page 26: turbocharge your php with nginx - errazudin - phpnw2010

• FastCGI Process Manager

• Daemonizes PHP > background proc

• provides a command-line script for managing PHP proc

• configuration of FastCGI pools

• enhances some of the FastCGI internals

• increases error reporting

• script termination

PHP-FPM

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Page 27: turbocharge your php with nginx - errazudin - phpnw2010

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Benchmark

http://www.myshutterspace.com/profile/AthonySaucedo

Page 28: turbocharge your php with nginx - errazudin - phpnw2010

• AMD Turion 64

• 1MB L2 Cache, 1.8 GHz

• 1GB RAM

• OS- Karmic Koala

• (my old 4 y.o. Acer)

Benchmark : Specs

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Page 29: turbocharge your php with nginx - errazudin - phpnw2010

• -n 5000

• -c 500

Benchmark : apacheBench

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Page 30: turbocharge your php with nginx - errazudin - phpnw2010

Benchmark : nginx

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Page 31: turbocharge your php with nginx - errazudin - phpnw2010

Benchmark : apache (runs..)

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Page 32: turbocharge your php with nginx - errazudin - phpnw2010

Benchmark : apache (end)

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Page 33: turbocharge your php with nginx - errazudin - phpnw2010

Benchmark : Findings

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Apache 2.2.12 Nginx 0.7.62

Concurrency 500 500

Doc size 2195 bytes 2195 bytes

Complete Request

100% 100%

Req per secs 327 3003

Longest Req 15269ms 296ms

Page 34: turbocharge your php with nginx - errazudin - phpnw2010

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

“Every nanoseconds count!” - My Big Boss(your boss also)

http://geekonfilm.files.wordpress.com/2009/09/vader.jpg

Page 35: turbocharge your php with nginx - errazudin - phpnw2010

Resources

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

• http://wiki.nginx.org/Main

• Nedelcu’s book http://goo.gl/67OA

• http://php-fpm.org/

• http://nginx.org

• #nginx

Page 36: turbocharge your php with nginx - errazudin - phpnw2010

www.mimos.my © 2010 MIMOS Berhad. All Rights Reserved.

Demo

http://goo.gl/EbTI

Page 37: turbocharge your php with nginx - errazudin - phpnw2010

THANK YOU

www.mimos.my © 2009 MIMOS Berhad. All Rights Reserved.

@errazudin

* All images, logos and data are the copyright of their respective owners

http://joind.in/2067