Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Pushing PHP to the Limit: 
Web Server PHP Performance Comparisons 
LiteSpeed vs. Apache vs. NGINX
Breakdown of the presentation 
1. Overview of technology discussed 
2. Benchmarks 
3. Different PHP setups in LiteSpeed We...
Web Servers
Web servers (discussed) 
● Apache (httpd) 
● NGINX 
● LiteSpeed Web Server (LSWS) 
● OpenLiteSpeed
Differences between 
OpenLiteSpeed and LSWS 
OpenLiteSpeed: 
● Uses OpenLiteSpeed-native configs exclusively 
● Free and o...
Web servers (not discussed) 
● Microsoft IIS 
● Tomcat 
● Lighty (lighttpd) 
● Cherokee 
● Others 
Why not? 
IIS is only f...
PHP
Why PHP? 
Because it is far and away the most used 
scripting language on the Internet. 
(82% of sites according to the la...
Web server-PHP interaction 
● PHP is a scripting language 
● Web servers do not process PHP directly 
● PHP is processed b...
SAPIs 
Server Application Programming Interfaces
What is an SAPI? 
An interface for communicating with an 
application (like the PHP engine).
SAPIs for PHP (discussed) 
1. mod_php (Apache) 
2. CGI (Apache) 
3. FCGI (Apache, NGINX, and LSWS) 
4. LSAPI (LSWS and Apa...
suEXEC? 
Running scripts as a separate user (often 
one user per virtual host).
mod_php (DSO) 
● Runs PHP as a module embedded in 
Apache processes 
● Requires no interprocess communication 
● Can use p...
CGI 
● Used by Apache 
● PHP run through external CGI module 
● Creates a new process for each request 
(lots of overhead)...
FCGI (FastCGI) 
● Used by Apache and NGINX 
● Runs PHP as an external instance 
● Created to be faster than CGI (less over...
LSAPI (LiteSpeed SAPI) 
● Created because none of the previous 
SAPIs gave the performance and control 
we wanted 
● Exter...
LSAPI Optimizations 
● Utilizes web server request parsing results 
for less overhead 
● Persistent processes dynamically ...
The Benchmarks
Three benchmarks 
1. LSWS vs. NGINX for small PHP scripts (new and 
unreleased) 
1. LSWS vs. OpenLiteSpeed vs. Apache vs. ...
Benchmark 1 
LSWS vs. NGINX for small PHP scripts (new)
Setup 
Server: 
● Intel Xeon E5-1620 Quad Core @ 3.60GHz 
● 8GB RAM 
Configs mostly defaults with small amount of optimiza...
Benchmark 1 results (no keep alive)
Benchmark 1 results (keep alive)
Benchmark 1 takeaways 
LSWS outperformed NGINX: 
● by 26% with keep alive connections off 
● by 91% with keep alive connec...
Benchmark 2 
LSWS vs. OpenLiteSpeed vs. Apache vs. NGINX for 
small PHP scripts (previously published)
Setup 
Server: 
● Intel Xeon E5-1620 Quad Core @ 3.60GHz (limited to 1 
core) 
● 8GB RAM 
Configs mostly defaults. Full co...
Benchmark 2 results 
(no keep alive)
Benchmark 2 results (keep alive)
Benchmark 2 takeaways 
● LSWS and OpenLiteSpeed outperformed all 
others 
● Difference between LSWS and NGINX preserved 
●...
Benchmark 3 
LSWS vs. Apache for WordPress 
(courtesy of Tristan Wallace, cPanel)
Setup 
VPS: 
● 1 core 
● 1GB RAM 
Dedicated server: 
● 4 cores 
● 8GB RAM
Benchmark 3 takeaways 
● Speed difference shown again, even with 
other applications 
● Resource advantage of event-driven...
Benchmark Wrapup 
What have we learned?
What happened? 
● Basically, LSWS and OpenLiteSpeed beat 
all comers by at least 25% 
● The difference was most pronounced...
Why? 
● LSAPI is optimized 
● LSWS is built for performance and geared 
especially for performance with LSAPI
Debate? 
If you wish to debate these benchmarks, please contact 
me or post to our forum. We are happy to try different 
s...
LSAPI 
What can you do with it?
LiteSpeed Server API 
● API for communication with an application backend 
● Open source 
● Designed specifically for LSWS...
LSAPI PHP Modes 
1.Worker 
2. Daemon 
3. ProcessGroup 
All can be suEXEC
Worker Mode 
● Default mode 
● Similar to PHP with CGI 
● New process each time PHP is needed 
● Creating new processes ha...
Daemon Mode 
● Forks all processes from a persistent 
parent process (even in suEXEC) 
● Spawning child processes is faste...
Setting up Daemon Mode 
WebAdmin console > Configuration > 
External App > your LSPHP external 
application: 
1. Set Auto ...
ProcessGroup Mode 
● Similar to PHP-FPM pools (except easy to set up) 
● Really only for suEXEC settings 
● One parent pro...
Setting up PHP ProcessGroup 
Add the following to an Apache 
configuration file: 
<IfModule LiteSpeed> 
LSPHP_ProcessGroup...
Future improvements to LSAPI 
● Event-driven PHP processing 
● HHVM integration
Conclusions
Conclusions 
● LSWS and OpenLiteSpeed serve PHP 25- 
100% faster than other major web 
servers 
● Partly due to LSAPI's op...
Conclusions (LSAPI) 
● LSAPI = faster PHP 
● LSAPI's suEXEC implementation allows for 
speed and security 
● LSAPI modes a...
Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)
Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)
Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed technologies)
Upcoming SlideShare
Loading in …5
×

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

2,415 views

Published on

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

Published in: Internet
  • Be the first to comment

  • Be the first to like this

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

  1. 1. Pushing PHP to the Limit: Web Server PHP Performance Comparisons LiteSpeed vs. Apache vs. NGINX
  2. 2. Breakdown of the presentation 1. Overview of technology discussed 2. Benchmarks 3. Different PHP setups in LiteSpeed Web Server (LSAPI) 4. Questions
  3. 3. Web Servers
  4. 4. Web servers (discussed) ● Apache (httpd) ● NGINX ● LiteSpeed Web Server (LSWS) ● OpenLiteSpeed
  5. 5. Differences between OpenLiteSpeed and LSWS OpenLiteSpeed: ● Uses OpenLiteSpeed-native configs exclusively ● Free and open source LiteSpeed Web Server: ● Can use Apache configs (control panel compatible) ● Paid license system
  6. 6. Web servers (not discussed) ● 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.)
  7. 7. PHP
  8. 8. Why PHP? Because it is far and away the most used scripting language on the Internet. (82% of sites according to the latest W3Techs survey.)
  9. 9. Web server-PHP interaction ● 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
  10. 10. SAPIs Server Application Programming Interfaces
  11. 11. What is an SAPI? An interface for communicating with an application (like the PHP engine).
  12. 12. SAPIs for PHP (discussed) 1. mod_php (Apache) 2. CGI (Apache) 3. FCGI (Apache, NGINX, and LSWS) 4. LSAPI (LSWS and Apache*) * mod_lsapi for Apache available only to CloudLinux users.
  13. 13. suEXEC? Running scripts as a separate user (often one user per virtual host).
  14. 14. mod_php (DSO) ● 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
  15. 15. CGI ● 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
  16. 16. FCGI (FastCGI) ● 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
  17. 17. LSAPI (LiteSpeed SAPI) ● 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
  18. 18. LSAPI Optimizations ● 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
  19. 19. The Benchmarks
  20. 20. Three benchmarks 1. LSWS vs. NGINX for small PHP scripts (new and unreleased) 1. LSWS vs. OpenLiteSpeed vs. Apache vs. NGINX for small PHP scripts (previously published) 1. LSWS vs. Apache for WordPress (presented by cPanel at cPanel Conference 2014, measured speed and resource usage)
  21. 21. Benchmark 1 LSWS vs. NGINX for small PHP scripts (new)
  22. 22. Setup 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
  23. 23. Benchmark 1 results (no keep alive)
  24. 24. Benchmark 1 results (keep alive)
  25. 25. Benchmark 1 takeaways LSWS outperformed NGINX: ● by 26% with keep alive connections off ● by 91% with keep alive connections on
  26. 26. Benchmark 2 LSWS vs. OpenLiteSpeed vs. Apache vs. NGINX for small PHP scripts (previously published)
  27. 27. Setup 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
  28. 28. Benchmark 2 results (no keep alive)
  29. 29. Benchmark 2 results (keep alive)
  30. 30. Benchmark 2 takeaways ● 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
  31. 31. Benchmark 3 LSWS vs. Apache for WordPress (courtesy of Tristan Wallace, cPanel)
  32. 32. Setup VPS: ● 1 core ● 1GB RAM Dedicated server: ● 4 cores ● 8GB RAM
  33. 33. Benchmark 3 takeaways ● 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
  34. 34. Benchmark Wrapup What have we learned?
  35. 35. What happened? ● Basically, LSWS and OpenLiteSpeed beat all comers by at least 25% ● The difference was most pronounced vs. Apache setups that use suEXEC
  36. 36. Why? ● LSAPI is optimized ● LSWS is built for performance and geared especially for performance with LSAPI
  37. 37. Debate? 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: marmstrong@litespeedtech.com
  38. 38. LSAPI What can you do with it?
  39. 39. LiteSpeed Server API ● 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 http://www.litespeedtech.com/products/litespeed-sapi/php
  40. 40. LSAPI PHP Modes 1.Worker 2. Daemon 3. ProcessGroup All can be suEXEC
  41. 41. Worker Mode ● 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
  42. 42. Daemon Mode ● 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
  43. 43. Setting up Daemon Mode WebAdmin console > Configuration > External App > your LSPHP external application: 1. Set Auto Start to "Yes". 2. Set Run On Start Up to "suEXEC Daemon".
  44. 44. ProcessGroup Mode ● 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
  45. 45. Setting up PHP ProcessGroup Add the following to an Apache configuration file: <IfModule LiteSpeed> LSPHP_ProcessGroup on LSPHP_Workers 15 </IfModule>
  46. 46. Future improvements to LSAPI ● Event-driven PHP processing ● HHVM integration
  47. 47. Conclusions
  48. 48. Conclusions ● 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
  49. 49. Conclusions (LSAPI) ● 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

×