Date post: | 16-Apr-2017 |
Category: |
Technology |
Upload: | nginx-inc |
View: | 874 times |
Download: | 0 times |
Maximizing PHP Performance with NGINXWednesday, 30 March 2016
MORE INFORMATION AT NGINX.COM
Your Questions
1. Who are we?● Floyd Smith, Technical Marketing Writer. Author of NGINX blog posts,
“Maximizing PHP 7 Performance with NGINX”, Part I and Part II. ● Faisal Memon, Product Marketer. Author of blog posts on load balancing,
containers, cloud, microservices and more.
2. What’s new in PHP 7?
3. How can I implement a high-performance site?
4. How do NGINX and NGINX Plus fit into my efforts?
MORE INFORMATION AT NGINX.COM
Agenda
● What’s New in PHP 7● Single-Server Performance Fixes● Multiserver Performance Fixes● PHP 7 NGINX specifics● Caching● Load Balancing● Bonus: Monitoring and Management● Questions?
MORE INFORMATION AT NGINX.COM
The Trouble with Updates
MORE INFORMATION AT NGINX.COM
What’s New in PHP 7
1. Higher performance – PHP 7 is said to be roughly 50% faster than previous versions of PHP, due to core refactoring introduced in the phpng (“PHP next-gen”) RFC. The same servercan serve more users because tasks get done faster.
2. Significant reductions in memory usage – More users can be served before a server starts paging to disk, which results in slowdowns and crashes.
3. Near-perfect compatibility – Look for changes in expression evaluation (such as for variable variables and variable properties), removal of ASP and script tags, and complete removal of formerly deprecated functionality.
4. New language features – Combined comparison operator (<=>, the “spaceship operator”), null coalesce operator (??), scalar type hints with strict mode, and return type hints with strict mode.
5. Security concerns – Performance and memory improvements reduce security vulnerabilities, but cross-site scripting (XSS) and SQL injection (SQLi) vulnerabilities are still commonly found in PHP code.
MORE INFORMATION AT NGINX.COM
PHP 7 vs. PHP 5 vs. HHVM
Source: talks.php.net/fluent15#/wpbench
MORE INFORMATION AT NGINX.COM
Agenda
● What’s New in PHP 7● Single-Server Performance Fixes● Multiserver Performance Fixes● PHP 7 NGINX specifics● Caching● Load Balancing● Bonus: Monitoring and Management● Questions?
MORE INFORMATION AT NGINX.COM
Single-Server Performance Fixes
1. Upgrade to PHP 7 – As described, results in faster app performance, reduced memory footprint, new language features.
2. Refactor your code – PHP 7 is 50% faster . How much faster can your code be? Moving to microservices makes a huge difference to single-server and multiserver performance.
3. Replace the web server with NGINX – Can use open source NGINX (free, widely used) or NGINX Plus (pre-built releases, support, monitoring and management, etc.).
4. Scale up – Get a bigger, stronger, faster machine or VM instance to run your application server on.
5. Use a CDN – Use a content delivery network (CDN) to improve disk performance.
6. More? – Please add suggestions for later discussion.
MORE INFORMATION AT NGINX.COM
Replacing Your Web Server1. Replace Apache with NGINX or NGINX Plus – Immediate performance fix.
Enables caching for static and dynamic content. (More on this soon.) Does not enable multiple app servers.
2. More performance on same hardware – Event loop replaces thread-per-connection, solves C10K problem.
3. Requires new server configuration – Replace familiar Apache configuration with tighter, more efficient (IMHO) NGINX configuration.
4. Independent of NGINX as reverse proxy server – You can use NGINX as a reverse proxy server with or without using NGINX as your web server; very flexible.
MORE INFORMATION AT NGINX.COM
Agenda
● What’s New in PHP 7● Single-Server Performance Fixes● Multiserver Performance Fixes● PHP 7 NGINX specifics● Caching● Load Balancing● Bonus: Monitoring and Management● Questions?
MORE INFORMATION AT NGINX.COM
Planning Your Site Architecture1. Current architecture – Evaluate your current site traffic and performance.
2. Goals – Immediate problems, future growth.
3. Estimate impact of changes – Open source NGINX or NGINX Plus as web server, reverse proxy server, load balancer, more.
4. Plan for growth – Estimate likely and possible growth and speed of growth.
5. Factor in the cloud – Use cloud from scratch, expand into the cloud, move into the cloud.
MORE INFORMATION AT NGINX.COM
Agenda
● What’s New in PHP 7● Single-Server Performance Fixes● Multiserver Performance Fixes● PHP 7-Specific NGINX Changes● Caching● Load Balancing● Bonus: Monitoring and Management● Questions?
MORE INFORMATION AT NGINX.COM
PHP 7-Specific Changes
upstream php-handler { server unix:/var/run/php5-fpm.sock; }
upstream php-handler { server unix:/var/run/php7.0-fpm.sock; }
PHP 5
PHP 7.0
MORE INFORMATION AT NGINX.COM
Agenda
● What’s New in PHP 7● Single-Server Performance Fixes● Multiserver Performance Fixes● PHP 7 NGINX specifics● Caching● Load Balancing● Bonus: Monitoring and Management● Questions?
MORE INFORMATION AT NGINX.COM
Why Cache with NGINX?
Source: http://bbc.in/1O8qHbi
MORE INFORMATION AT NGINX.COM
Microcaching with NGINX
• Cache content for a short time, as little as 1 second
• Site content is out of date for max 1 second
• Significant performance gains even for that short of a time
MORE INFORMATION AT NGINX.COM
Microcaching with NGINX
proxy_cache_path /tmp/cache keys_zone=cache:10m levels=1:2 inactive=600s max_size=100m;
server { proxy_cache cache; proxy_cache_valid 200 1s; ... }
• Cache responses with status code 200 for 1 second
MORE INFORMATION AT NGINX.COM
Optimized Microcaching with NGINX
server { proxy_cache cache; proxy_cache_valid 200 1s; proxy_cache_lock on; proxy_cache_use_stale updating; ... }
• proxy_cache_lock – If there are multiple simultaneous requests for the same uncached or stale content, only one request is allowed through. Others are queued.
• proxy_cache_use_stale – Serve stale content while cached entry is being updated.
MORE INFORMATION AT NGINX.COM
Cache Purging with NGINX Plus
proxy_cache_path /tmp/cache keys_zone=mycache:10m levels=1:2 inactive=60s; map $request_method $purge_method { PURGE 1; default 0; }
server { proxy_cache mycache; proxy_cache_purge $purge_method; }
$ curl -X PURGE -D – "http://www.example.com/*"HTTP/1.1 204 No Content…
MORE INFORMATION AT NGINX.COM
Agenda
● What’s New in PHP 7● Single-Server Performance Fixes● Multiserver Performance Fixes● PHP 7 NGINX specifics● Caching● Load Balancing● Bonus: Monitoring and Management● Questions?
MORE INFORMATION AT NGINX.COM
Load Balancing with NGINX
MORE INFORMATION AT NGINX.COM
Session Persistence with NGINX Plus
• Stick client to the same server for duration of a session
• Multiple methods:• NGINX tracks application session cookie: ie. PHPSESSIONID• NGINX inserts its own cookie• Sticky Route – Persistence based on cookie, HTTP header, etc.• IP Hash (Available in open source)
• Session draining – Gracefully remove servers from the load-balanced pool
MORE INFORMATION AT NGINX.COM
SSL Offloading with NGINX
MORE INFORMATION AT NGINX.COM
HTTP/2 with NGINX
NGINX translates HTTP/2 to the language your application speaks
MORE INFORMATION AT NGINX.COM
Agenda
● What’s New in PHP 7● Single-Server Performance Fixes● Multi-Server Performance Fixes● PHP 7 NGINX specifics● Caching● Load Balancing● Bonus: Monitoring and Management● Questions?
MORE INFORMATION AT NGINX.COM
Monitoring with NGINX Amplify
• Get crucial performance and security recommendations with an analysis of your NGINX configuration
• Stay on top of your systems with key visualizations of NGINX and OS metrics• Know when servers need attention with a powerful alerting system
Sign up for the beta today: www.nginx.com/amplify
MORE INFORMATION AT NGINX.COM
Monitoring and Management with NGINX Plus
• Active health checks – Catch errors before they are seen by your users. NGINX Plus actively monitors the health of your servers and directs traffic away from failed servers.
• JSON stats – Know what’s going on in your app with a wealth of status indicators. NGINX Plus provides fine-grained stats on how each of your servers are performing. The stats are in JSON format and can be exported to your favorite monitoring tool.
MORE INFORMATION AT NGINX.COM
Agenda
● What’s New in PHP 7● Single-Server Performance Fixes● Multi-Server Performance Fixes● PHP 7 NGINX specifics● Caching● Load Balancing● Bonus: Monitoring and Management● Questions?