SlideShare a Scribd company logo
1 of 50
Download to read offline
Zend Server:
Scalability & Performance
By Shahahr Evron
Technical 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 & Scalability
Some 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 performance
Performance 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 CE
0
5
10
15
20
25
30
35
40
45
50
2.24
13.96 12.69
5.3
45.55
41.73
Bare PHP Optimizer+
19
Setting it up to run faster
Tuning 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 need
Why 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 configuration
Many 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 Benchmark
Caching 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 Rule
0
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 Caching
function 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-loading
Why 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 recipients
0
20
40
60
80
100
120
140
9.39
3.38 1.5
128.81 127.82 128.61
Baseline Job Queue
39
Zend Download Server
Quick & 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: shahar.e@zend.com
Learn 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.

More Related Content

More from Shahar Evron

Best Practices in PHP Application Deployment
Best Practices in PHP Application DeploymentBest Practices in PHP Application Deployment
Best Practices in PHP Application DeploymentShahar Evron
 
Amazon Cloud Services and Zend Framework
Amazon Cloud Services and Zend FrameworkAmazon Cloud Services and Zend Framework
Amazon Cloud Services and Zend FrameworkShahar Evron
 
PHP and Zend Framework on Windows
PHP and Zend Framework on WindowsPHP and Zend Framework on Windows
PHP and Zend Framework on WindowsShahar Evron
 
Scaling PHP Applications with Zend Platform
Scaling PHP Applications with Zend PlatformScaling PHP Applications with Zend Platform
Scaling PHP Applications with Zend PlatformShahar Evron
 
Zend Framework Components for non-framework Development
Zend Framework Components for non-framework DevelopmentZend Framework Components for non-framework Development
Zend Framework Components for non-framework DevelopmentShahar Evron
 
PHP ואבטחה - חלק שני
PHP ואבטחה - חלק שניPHP ואבטחה - חלק שני
PHP ואבטחה - חלק שניShahar Evron
 
PHP ואבטחה - חלק ראשון
PHP ואבטחה - חלק ראשוןPHP ואבטחה - חלק ראשון
PHP ואבטחה - חלק ראשוןShahar Evron
 
PHP - עבר הווה ועתיד
PHP - עבר הווה ועתידPHP - עבר הווה ועתיד
PHP - עבר הווה ועתידShahar Evron
 
Content Indexing with Zend_Search_Lucene
Content Indexing with Zend_Search_LuceneContent Indexing with Zend_Search_Lucene
Content Indexing with Zend_Search_LuceneShahar Evron
 
Building Scalable Development Environments
Building Scalable Development EnvironmentsBuilding Scalable Development Environments
Building Scalable Development EnvironmentsShahar Evron
 

More from Shahar Evron (11)

Best Practices in PHP Application Deployment
Best Practices in PHP Application DeploymentBest Practices in PHP Application Deployment
Best Practices in PHP Application Deployment
 
Amazon Cloud Services and Zend Framework
Amazon Cloud Services and Zend FrameworkAmazon Cloud Services and Zend Framework
Amazon Cloud Services and Zend Framework
 
PHP and Zend Framework on Windows
PHP and Zend Framework on WindowsPHP and Zend Framework on Windows
PHP and Zend Framework on Windows
 
Intro To Couch Db
Intro To Couch DbIntro To Couch Db
Intro To Couch Db
 
Scaling PHP Applications with Zend Platform
Scaling PHP Applications with Zend PlatformScaling PHP Applications with Zend Platform
Scaling PHP Applications with Zend Platform
 
Zend Framework Components for non-framework Development
Zend Framework Components for non-framework DevelopmentZend Framework Components for non-framework Development
Zend Framework Components for non-framework Development
 
PHP ואבטחה - חלק שני
PHP ואבטחה - חלק שניPHP ואבטחה - חלק שני
PHP ואבטחה - חלק שני
 
PHP ואבטחה - חלק ראשון
PHP ואבטחה - חלק ראשוןPHP ואבטחה - חלק ראשון
PHP ואבטחה - חלק ראשון
 
PHP - עבר הווה ועתיד
PHP - עבר הווה ועתידPHP - עבר הווה ועתיד
PHP - עבר הווה ועתיד
 
Content Indexing with Zend_Search_Lucene
Content Indexing with Zend_Search_LuceneContent Indexing with Zend_Search_Lucene
Content Indexing with Zend_Search_Lucene
 
Building Scalable Development Environments
Building Scalable Development EnvironmentsBuilding Scalable Development Environments
Building Scalable Development Environments
 

Zend Server: Scalability & Performance

  • 1. Zend Server: Scalability & Performance By Shahahr Evron Technical Product Manager, Zend Technologies
  • 2. 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. 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. 4 What is Zend Server? ...and why should I care?
  • 5. 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. 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
  • 8. 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. 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. 10 Zend Server's approach to Performance
  • 11. 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. 12 It's just a series of tubes, right?
  • 13. 13 Out of the box performance Performance 101
  • 14. 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 :)
  • 18. 18 Optimizer+: A quick Benchmark Magento Drupal SugarCRM CE 0 5 10 15 20 25 30 35 40 45 50 2.24 13.96 12.69 5.3 45.55 41.73 Bare PHP Optimizer+
  • 19. 19 Setting it up to run faster Tuning tips
  • 20. 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. 21 Turn off extensions you don't need Why 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. 22 Tune PHP configuration Many 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
  • 24. 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. 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. 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
  • 28. 28 Page Cache: A Quick Drupal Benchmark Caching 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 Rule 0 100 200 300 400 500 600 700 21.94 201.17 589.26
  • 29. 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. 30 Data Caching function 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. 31 Off-line processing & Task off-loading Why do now the stuff you can do later?
  • 32. 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. 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. 34 Job Queue – a Common Execution Flow
  • 35. 35 Job Queue – a Common Execution Flow
  • 36. 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. 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. 38 Job Queue 1 recipient 3 recipients 6 recipients 0 20 40 60 80 100 120 140 9.39 3.38 1.5 128.81 127.82 128.61 Baseline Job Queue
  • 39. 39 Zend Download Server Quick & Easy Apache Efficiency
  • 40. 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. 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
  • 50. 50 Thanks! Email me: shahar.e@zend.com Learn 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.