turbocharge your php with nginx - errazudin - phpnw2010

Post on 19-May-2015

3,135 views 2 download

Tags:

description

turbocharge your php with nginx by @errazudin #phpnw2010

transcript

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

Turbocharge Your PHP with Nginx

Errazudin Ishak

• me

• “engine X”

• nginx.conf

• ..with PHP

• Benchmark

• Samples

Agenda

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

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

• 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.

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

• 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.

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/

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

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

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

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

Numbers

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

Market Share for Top Servers Across All Domains

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

Source :

Netcraft

213,458,815

Market Share for Top Servers Across the Million Busiest Sites

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

Source :

Netcraft

Market Share for Top Servers Across All Domains

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

Source :

Netcraft

227,225,642

Market Share for Top Servers Across the Million Busiest Sites

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

Source :

Netcraft

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?

Me uses nginx

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

Me uses nginx

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

We also..

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

We all love nginx…

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

Modules

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

Mail, 3rd

Party

Optional

HTTP

Standard HTTP

Core

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

• FastCGI

• PHP-FPM (FastCGI Process Manager)

• Bundled with PHP 5.3.3

Nginx with PHP

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

• 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.

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.

• 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.

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

Benchmark

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

• 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.

• -n 5000

• -c 500

Benchmark : apacheBench

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

Benchmark : nginx

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

Benchmark : apache (runs..)

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

Benchmark : apache (end)

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

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

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

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

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

Demo

http://goo.gl/EbTI

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