52
Pushing PHP to the Limit: Web Server PHP Performance Comparisons LiteSpeed vs. Apache vs. NGINX

Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

  • Upload
    ontico

  • View
    961

  • Download
    3

Embed Size (px)

DESCRIPTION

Доклад Майкла Армстронга на HighLoad++ 2014.

Citation preview

Page 1: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

Pushing PHP to the Limit:

Web Server PHP Performance Comparisons

LiteSpeed vs. Apache vs. NGINX

Page 2: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

1.Overview of technology discussed2.Benchmarks3.Different PHP setups in LiteSpeed

Web Server (LSAPI)4.Questions

Breakdown of the presentation

Page 3: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

Web Servers

Page 4: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

● Apache (httpd)● NGINX● LiteSpeed Web Server (LSWS)● OpenLiteSpeed

Web servers (discussed)

Page 5: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

OpenLiteSpeed:● Uses OpenLiteSpeed-native configs exclusively● Free and open source

LiteSpeed Web Server:● Can use Apache configs (control panel

compatible)● Paid license system

Differences between OpenLiteSpeed and LSWS

Page 6: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

● Microsoft IIS● Tomcat● Lighty (lighttpd)● Cherokee● Others

Why not?IIS is only for Windows and nobody uses the rest of these. (Less than 0.5% of sites.)

Web servers (not discussed)

Page 7: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

PHP

Page 8: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

Because it is far and away the most used scripting language on the Internet.

(82% of sites according to the latest W3Techs survey.)

Why PHP?

Page 9: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

● PHP is a scripting language● Web servers do not process PHP

directly ● PHP is processed by a PHP engine on

the backend● Web servers use a variety of SAPIs

to communicate with the PHP engine

Web server-PHP interaction

Page 10: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

SAPIsServer Application Programming Interfaces

Page 11: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

An interface for communicating with an application (like the PHP engine).

What is an SAPI?

Page 12: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

1.mod_php (Apache)2.CGI (Apache)3.FCGI (Apache, NGINX, and LSWS)4.LSAPI (LSWS and Apache*)

SAPIs for PHP (discussed)

* mod_lsapi for Apache available only to CloudLinux users.

Page 13: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

Running scripts as a separate user (often one user per virtual host).

suEXEC?

Page 14: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

● Runs PHP as a module embedded in Apache processes

● Requires no interprocess communication

● Can use persistent processes● Fastest Apache implementation of

PHP● All scripts run as nobody● Requires Apache prefork

mod_php (DSO)

Page 15: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

● Used by Apache● PHP run through external CGI

module● Creates a new process for each

request (lots of overhead)● Slow and unscalable● Can run suEXEC

CGI

Page 16: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

● Used by Apache and NGINX● Runs PHP as an external instance● Created to be faster than CGI (less

overhead)● Persistent processes handle many

requests instead of creating a new process each time

● Saves CPU, but persistent processes can waste RAM

● Can run suEXEC

FCGI (FastCGI)

Page 17: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

● Created because none of the previous SAPIs gave the performance and control we wanted

● External instance● Similar layout to FCGI, but optimized● Can run suEXEC

LSAPI (LiteSpeed SAPI)

Page 18: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

● Utilizes web server request parsing results for less overhead

● Persistent processes dynamically forked to save resources

● Different modes of process handling for different needs

● Allows per-directory configuration overrides

LSAPI Optimizations

Page 19: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

The Benchmarks

Page 20: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

1. LSWS vs. NGINX for small PHP scripts (new and unreleased)

2. LSWS vs. OpenLiteSpeed vs. Apache vs. NGINX for small PHP scripts (previously published)

3. LSWS vs. Apache for WordPress (presented by cPanel at cPanel Conference 2014, measured speed and resource usage)

Three benchmarks

Page 21: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

Benchmark 1LSWS vs. NGINX for small PHP scripts (new)

Page 22: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

Server:● Intel Xeon E5-1620 Quad Core @ 3.60GHz ● 8GB RAM

Configs mostly defaults with small amount of optimization for NGINX. Full configs will be released on our site.

AB:ab_new -n 50000 -c 100

Setup

Page 23: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

Benchmark 1 results (no keep alive)

Page 24: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

Benchmark 1 results (keep alive)

Page 25: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

LSWS outperformed NGINX:● by 26% with keep alive connections

off● by 91% with keep alive connections

on

Benchmark 1 takeaways

Page 26: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

Benchmark 2LSWS vs. OpenLiteSpeed vs. Apache vs. NGINX for small PHP scripts (previously

published)

Page 27: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

Server:● Intel Xeon E5-1620 Quad Core @ 3.60GHz

(limited to 1 core)● 8GB RAM

Configs mostly defaults. Full configs can be found on our site.

AB:ab_new -n 50000 -c 100

Setup

Page 28: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

Benchmark 2 results(no keep alive)

Page 29: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

Benchmark 2 results (keep alive)

Page 30: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

● LSWS and OpenLiteSpeed outperformed all others

● Difference between LSWS and NGINX preserved

● Apache 2.2 with mod_PHP next fastest (about 50% slower than LSWS)

● LSAPI makes a 15-20% difference● All web servers did better with keep-alive

on

Benchmark 2 takeaways

Page 31: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

Benchmark 3LSWS vs. Apache for WordPress

(courtesy of Tristan Wallace, cPanel)

Page 32: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

VPS:● 1 core● 1GB RAM

Dedicated server:● 4 cores● 8GB RAM

Setup

Page 33: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)
Page 34: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)
Page 35: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)
Page 36: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

● Speed difference shown again, even with other applications

● Resource advantage of event-driven architecture (VPSs with Apache couldn't even handle 50 concurrent connections)

● Resource advantage of LSAPI

Benchmark 3 takeaways

Page 37: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

Benchmark WrapupWhat have we learned?

Page 38: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

● Basically, LSWS and OpenLiteSpeed beat all comers by at least 25%

● The difference was most pronounced vs. Apache setups that use suEXEC

What happened?

Page 39: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

● LSAPI is optimized● LSWS is built for performance and

geared especially for performance with LSAPI

Why?

Page 40: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

If you wish to debate these benchmarks, please contact me or post to our forum. We are happy to try different settings if there is good reason to believe they will make a difference.

Forum: http://www.litespeedtech.com/support/forum/

Me: [email protected]

Debate?

Page 41: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

LSAPIWhat can you do with it?

Page 42: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

● API for communication with an application backend

● Open source● Designed specifically for LSWS (for better

integration)● Highly optimized by default● Offers three different modes of handling PHP

processes for different needs● Allows for high-performance suEXEC setups● Available for PHP, Ruby, and Python

LiteSpeed Server API

http://www.litespeedtech.com/products/litespeed-sapi/php

Page 43: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

1.Worker2.Daemon3.ProcessGroup

LSAPI PHP Modes

All can be suEXEC

Page 44: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

● Default mode● Similar to PHP with CGI● New process each time PHP is

needed● Creating new processes has

overhead● Can save resources because there

are no more processes than needed● No effective suEXEC opcode caching

Worker Mode

Page 45: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

● Forks all processes from a persistent parent process (even in suEXEC)

● Spawning child processes is faster than creating new processes

● Allows for somewhat more effective suEXEC opcode caching

Daemon Mode

Page 46: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

WebAdmin console > Configuration > External App > your LSPHP external application:

1.Set Auto Start to "Yes".2.Set Run On Start Up to "suEXEC

Daemon".

Setting up Daemon Mode

Page 47: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

● Similar to PHP-FPM pools (except easy to set up)● Really only for suEXEC settings● One parent process for each user● Parent process spawns child processes on

demand● Spawning child processes is faster than creating

new processes● Allows for per-user opcode caching in a suEXEC

setting● Extra parent processes consume extra resources● Not available for OpenLiteSpeed

ProcessGroup Mode

Page 48: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

Add the following to an Apache configuration file:

<IfModule LiteSpeed>LSPHP_ProcessGroup onLSPHP_Workers 15</IfModule>

Setting up PHP ProcessGroup

Page 49: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

● Event-driven PHP processing● HHVM integration

Future improvements to LSAPI

Page 50: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

Conclusions

Page 51: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

● LSWS and OpenLiteSpeed serve PHP 25-100% faster than other major web servers

● Partly due to LSAPI's optimization● Partly due to LSWS and

OpenLiteSpeed's optimized integration with LSAPI

Conclusions

Page 52: Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)

● LSAPI = faster PHP● LSAPI's suEXEC implementation

allows for speed and security● LSAPI modes and config overrides

allow easy configuration for different uses

● Opcode caching even with suEXEC

Conclusions (LSAPI)