Zend Server: Scalability & Performance
-
Upload
shahar-evron -
Category
Technology
-
view
13.424 -
download
1
description
Transcript of Zend Server: Scalability & Performance
Zend Server: Scalability & Performance
By Shahahr EvronTechnical Product Manager, Zend Technologies
2
Welcome!
I am:▶ A PHP programmer since 2002▶ At Zend since 2005▶ Technical Product Manager for Zend Server
Yes, I have a difficult name (at least for English speakers)
▶ Shachar (German, Dutch)
▶ Shajar (Spanish)
▶ Шахар (Russian)
▶ (Arabic) شخر
▶ (Hebrew) שחר
3
Agenda
▶ What is Zend Server?
▶ Performance and Scalability
▶ Zend Server's approach to performance
▶ Out of the box performance: Optimizer+
▶ Setting it up to run faster
▶ Caching, Caching, Caching
▶ Task off-loading and off-line processing
4
What is Zend Server?...and why should I care?
5
...Well, Just ask your friend at marketing!
“Zend Server is a complete, enterprise-ready Web Application Server for
running and managing PHP applications that require a high level of reliability, performance and
security.”
6
Let's try to make sense out of that..
Zend Server Is:▶ A complete, well tested PHP runtime environment▶ Supported and updated by Zend▶ Comes with a set of extra features that:
● Improve the performance and reliability of PHP applications● Make it easier to manage a consistent PHP environment
Comes in two flavors:▶ Zend Server▶ Zend Server Community Edition
7
Performance & ScalabilitySome terminology
8
What performance are we talking about?
Improving an application's performance can mean:
▶ Making it run faster ● More requests per second on the server side● Less load time on the user side
▶ Making it run more efficiently● Use less memory / CPU / disk IO / network bandwidth● Distribute load evenly over time / hardware
These are not always the same, and setting goals is important!
9
What about Scalability?
Scalability can mean different things:▶ Ability to gracefully handle more users▶ Ability to gracefully handle more data ▶ Ability to gracefully handle more code
Scalability can be improved by performance optimizations...
▶ But they are not the same, and sometimes even conflict!
10
Zend Server's approach to Performance
11
Comprehensive Performance
A Web App's performance depends on many factors...▶ Network▶ Web server load▶ PHP processing time▶ Database load▶ Application logic▶ ...?
...that is why improving your applications performance will require applying a range of measures
▶ Zend Server provides a set of different tools to help you do that!
12
It's just a series of tubes, right?
13
Out of the box performancePerformance 101
14
Opcode Caching and Optimization
Zend Server includes Optimizer+:▶ PHP Opcode is read once from disk and compiled▶ The compiled opcode goes through a set of optimizations▶ The optimized opcode is stored in shared memory
● No need to read from disk again unless the code changes● No need to compile the code on each request / file inclusion● Optimized code potentially executes faster
▶ Works out of the box, no setup needed!● Can be made even better with some tuning :)
15
How Optimizer+ Works?
16
How Optimizer+ Works?
17
How Optimizer+ Works?
18
Optimizer+: A quick Benchmark
Magento Drupal SugarCRM CE05
101520253035404550
2.24
13.96 12.69
5.3
45.5541.73
Bare PHP Optimizer+
19
Setting it up to run fasterTuning tips
20
Tuning Zend Server for Performance
Zend Server comes with a default “good for all” setup▶ You should go over the performance guide when moving to
production!
Some things you should definitely do:▶ Turn off extensions you don't need ▶ Tune PHP configuration▶ Tune Zend Monitoring Rules
21
Turn off extensions you don't needWhy load extensions you don't use?
▶ Per-process memory can be reduced▶ Less work at MINIT and possibly at RINIT / RSHUTDOWN▶ Generally a good security practice
A quick test on per-process Apache memory usage shows:▶ With 55 extensions: 9.3mb▶ With 31 extensions: 7.2mb
● Almost 30% more concurrent requests on an average machine!
Of course, you must know what can be turned off...
22
Tune PHP configurationMany PHP directives can be optimized for performance
▶ Those have relatively small effect▶ ...but they are easy to fix, and you should know them!
Here are some examples:▶ include_path, realpath_cache_size, realpath_cache_ttl▶ output_buffering▶ register_long_arrays, register_argc_argv▶ magic_quotes_gpc▶ error_reporting▶ memory_limit, max_execution_time▶ session.auto_start
23
Caching, Caching, Caching
24
Caching?
“In computer science, a cache is a collection of data duplicating original values stored elsewhere
or computed earlier, where the original data is expensive to fetch or to compute, compared to the
cost of reading the cache.”-- Wikipedia
25
Caching with Zend Server...
Zend Server provides several caching tools▶ Zend Data Cache
● Disk storage● Shared memory storage
▶ Zend Page Cache▶ Common Caching Extensions
● memcache ● APC compatibility layer
You can get the best results by combining some or all of those
▶ You can abstract storage backends using ZF's Zend_Cache
26
Page Caching
Page Caching allows you to cache full HTTP responses▶ Super fast!▶ Based on a rule system – no code changes required▶ Cached / live decision can be based on request or session data▶ Variants can be created based on request or session data▶ Client-side caching is utilized if supported by browser
Setting it up requires some careful planning
...but the performance gains are usually worth the effort
27
Page Caching
28
Page Cache: A Quick Drupal BenchmarkCaching node pages for guest users
▶ Can be done with no effort using a SESSION based rule▶ Much better results can be achieved using a COOKIE based rule
● ...no need to run code up to session_start
No Cache Session Rule Other Rule0
100
200
300
400
500
600
700
21.94
201.17
589.26
29
Data Caching
Zend Server's Data Caching API allows you to:▶ Programatically place data items into cache
● And also get them and delete them ;)
▶ Use shared memory or disk storage as needed▶ Organize cached items into namespaces▶ Clear cached content from Zend Server's UI
Data Caching more of a “precision guided” caching tool▶ Requires code changed (but is easy to use)▶ Not as effective performance wise as Page Cache▶ Very flexible
30
Data Cachingfunction getRecentPosts($count = 5) { // Try to fetch from the cache first $recentPosts = zend_shm_cache_fetch('recentposts-' . $count);
if ($recentPosts === false) { // Get the PDO adapter for the DB $dbAdapter = myBlogDb::getPdoAdapter();
// Build the query $query = "SELECT title, author, pubdate FROM posts ORDER BY pubdate DESC LIMIT ?"; $dbStatement = $dbAdapter->prepare($query); // Execute the query $recentPosts = array(); if ($dbStatement->execute(array($count))) { while($post = $dbStatement->fetch(PDO::FETCH_ASSOC)) { $recentPosts[] = $post; } // Store the results in cache zend_shm_cache_store('recentposts-' . $count, $recentPosts, 24 * 3600); } }
return $recentPosts; } Read more: http://devzone.zend.com/article/4457
Or just Google “Zend Server Caching Guide”
31
Off-line processing & Task off-loadingWhy do now the stuff you can do later?
32
Job Queue
Off-line processing?▶ Web applications tend to “live” in HTTP request/response cycles▶ What do you do when you need to take something off-line?▶ What do you do when you need periodical execution?
It's also a matter of user experience:▶ Sometimes, it's just silly to let the user wait
Zend Server Job Queue allows you to take it off-line!▶ Run things asynchronously, later, on a different server▶ Run things periodically
33
So is it some glorified Cron?
No!▶ You can run things now, but without waiting for them to finish▶ You can run things once, but not right now▶ You can run things periodically (like cron)
● But have full control over them – start, stop, suspend, resume from PHP API
▶ Job Queue gives you full visibility into what's going on● Get alerts on failed jobs, analyze errors and re-queue ● Keep track of past, current and pending jobs● Integrates with Zend Monitor
▶ You don't need to hack it all to work for you
34
Job Queue – a Common Execution Flow
35
Job Queue – a Common Execution Flow
36
Job Queue
if (GlobalConfig::get('useJobQueue')) { // Use job queue to off-load email sending $params = array( 'recipients' => $recipients, 'message' => $message ); $queue = new ZendJobQueue(); $queue->createHttpJob('http://localhost/mail/job.php',
$params); } else { // No job queue, send emails directly send_mail($recipients, $message); }
Front-end code:
37
Job Queue
$params = ZendJobQueue::getCurrentJobParams();
if (isset($params['recipients']) && isset($params['message'])) {
send_mail($params['recipients'], $params['message']); ZendJobQueue::setCurrentJobStatus(ZendJobQueue::OK); } else { ZendJobQueue::setCurrentJobStatus(ZendJobQueue::FAILURE, "Missing recipients list or message"); }
Back-end code:
38
Job Queue
1 recipient 3 recipients 6 recipients0
20
40
60
80
100
120
140
9.393.38 1.5
128.81 127.82 128.61
Baseline Job Queue
39
Zend Download ServerQuick & Easy Apache Efficiency
40
What is Zend Download Server
If you use Apache in Prefork mode:▶ Each process handles one request at a time▶ Your server's # of processes is limited (usually by RAM)▶ Once your server's processes are maxed, you have a problem!
Solutions:▶ Add more hardware (← last resort!)▶ Switch to a threaded web server + FastCGI PHP
● lighttpd, optimized threaded Apache, nginx etc.
▶ Off-load static downloads● To a separate web server, separate machine, CDN / 3rd party storage
▶ Set up Zend Download Server!
41
How does Zend Download Server help?
Zend Download Server improves Apache's scalability by:▶ “Hijacking” static downloads to a separate, efficient process▶ Freeing Apache processes to do the “hard work” (== PHP)
Usage modes:▶ Can be set up to automatically send specific file types▶ Can be used through API (zend_send_file, zend_send_buffer)
Benefits:▶ Easy to set up and use, no code changes▶ Easy to integrate with your PHP app's logic
● e.g. authenticated downloads
42
Epilogue
43
Conclusions
44
Conclusions
45
Conclusions
46
Conclusions
47
Conclusions
48
Conclusions
49
Conclusions
50
Thanks!Email me: [email protected] more at http://www.zend.com/server
Copyright © 2009 Zend Technologies Ltd.
This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.