Transcript
Page 1: Zend Server: Scalability & Performance

Zend Server: Scalability & Performance

By Shahahr EvronTechnical Product Manager, Zend Technologies

Page 2: Zend Server: Scalability & Performance

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) שחר

Page 3: Zend Server: Scalability & Performance

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

Page 4: Zend Server: Scalability & Performance

4

What is Zend Server?...and why should I care?

Page 5: Zend Server: Scalability & Performance

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.”

Page 6: Zend Server: Scalability & Performance

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

Page 7: Zend Server: Scalability & Performance

7

Performance & ScalabilitySome terminology

Page 8: Zend Server: Scalability & Performance

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!

Page 9: Zend Server: Scalability & Performance

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!

Page 10: Zend Server: Scalability & Performance

10

Zend Server's approach to Performance

Page 11: Zend Server: Scalability & 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!

Page 12: Zend Server: Scalability & Performance

12

It's just a series of tubes, right?

Page 13: Zend Server: Scalability & Performance

13

Out of the box performancePerformance 101

Page 14: Zend Server: Scalability & Performance

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 :)

Page 15: Zend Server: Scalability & Performance

15

How Optimizer+ Works?

Page 16: Zend Server: Scalability & Performance

16

How Optimizer+ Works?

Page 17: Zend Server: Scalability & Performance

17

How Optimizer+ Works?

Page 18: Zend Server: Scalability & Performance

18

Optimizer+: A quick Benchmark

Magento Drupal SugarCRM CE05

101520253035404550

2.24

13.96 12.69

5.3

45.5541.73

Bare PHP Optimizer+

Page 19: Zend Server: Scalability & Performance

19

Setting it up to run fasterTuning tips

Page 20: Zend Server: Scalability & Performance

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

Page 21: Zend Server: Scalability & Performance

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...

Page 22: Zend Server: Scalability & Performance

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

Page 23: Zend Server: Scalability & Performance

23

Caching, Caching, Caching

Page 24: Zend Server: Scalability & Performance

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

Page 25: Zend Server: Scalability & Performance

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

Page 26: Zend Server: Scalability & Performance

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

Page 27: Zend Server: Scalability & Performance

27

Page Caching

Page 28: Zend Server: Scalability & Performance

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

Page 29: Zend Server: Scalability & Performance

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

Page 30: Zend Server: Scalability & Performance

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”

Page 31: Zend Server: Scalability & Performance

31

Off-line processing & Task off-loadingWhy do now the stuff you can do later?

Page 32: Zend Server: Scalability & Performance

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

Page 33: Zend Server: Scalability & Performance

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

Page 34: Zend Server: Scalability & Performance

34

Job Queue – a Common Execution Flow

Page 35: Zend Server: Scalability & Performance

35

Job Queue – a Common Execution Flow

Page 36: Zend Server: Scalability & Performance

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:

Page 37: Zend Server: Scalability & Performance

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:

Page 38: Zend Server: Scalability & Performance

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

Page 39: Zend Server: Scalability & Performance

39

Zend Download ServerQuick & Easy Apache Efficiency

Page 40: Zend Server: Scalability & Performance

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!

Page 41: Zend Server: Scalability & Performance

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

Page 42: Zend Server: Scalability & Performance

42

Epilogue

Page 43: Zend Server: Scalability & Performance

43

Conclusions

Page 44: Zend Server: Scalability & Performance

44

Conclusions

Page 45: Zend Server: Scalability & Performance

45

Conclusions

Page 46: Zend Server: Scalability & Performance

46

Conclusions

Page 47: Zend Server: Scalability & Performance

47

Conclusions

Page 48: Zend Server: Scalability & Performance

48

Conclusions

Page 49: Zend Server: Scalability & Performance

49

Conclusions

Page 50: Zend Server: Scalability & Performance

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.


Top Related