Optimizing Zend Framework

25
OPTIMIZING ZEND FRAMEWORK Juozas Kaziukėnas www.juokaz.com / [email protected] / @juokaz

description

 

Transcript of Optimizing Zend Framework

Page 1: Optimizing Zend Framework

OPTIMIZING ZEND FRAMEWORKJuozas Kaziukėnas

www.juokaz.com / [email protected] / @juokaz

Page 2: Optimizing Zend Framework

Who am I?• Juozas Kaziukėnas, Lithuanian• You can call me Joe• 2 years in Edinburgh, UK• Studying in University of Edinburgh• Software developer, consultant and evangelist• Open source developer for Zend Framework, Doctrine…• More info in www.juokaz.com and twitter @juokaz

Juozas Kaziukėnas 2010 / Leave feedback at http://joind.in/2060

Page 3: Optimizing Zend Framework

Who are you?• Zend Framework users?• Scaling problems?• Generally interested in PHP performance issues?• Want to bash Zend Framework?

Juozas Kaziukėnas 2010 / Leave feedback at http://joind.in/2060

Page 4: Optimizing Zend Framework

This talk will not necessary teach you how to make

your applications faster, it will show you how to understand them.

Juozas Kaziukėnas 2010 / Leave feedback at http://joind.in/2060

Page 5: Optimizing Zend Framework

Things we are going to talk about• “Normal” PHP code• What makes it slow?• How people find slow parts?• A key to optimizing Zend Framework applications• How slow it really is?

Juozas Kaziukėnas 2010 / Leave feedback at http://joind.in/2060

Page 6: Optimizing Zend Framework

“NORMAL” PHP CODE

Juozas Kaziukėnas 2010 / Leave feedback at http://joind.in/2060

Page 7: Optimizing Zend Framework

“Normal” PHP code• Zend Framework is different from single-php websites• Building a Facebook• Overhead• Bloated Frameworks• Zend Framework is not for “script kiddies”

Juozas Kaziukėnas 2010 / Leave feedback at http://joind.in/2060

Page 8: Optimizing Zend Framework

Zend Framework will *never* be as a one-file

PHP website

Juozas Kaziukėnas 2010 / Leave feedback at http://joind.in/2060

Page 9: Optimizing Zend Framework

WHAT MAKES IT SLOW?

Juozas Kaziukėnas 2010 / Leave feedback at http://joind.in/2060

Page 10: Optimizing Zend Framework

A problem:Usually *you* make it slow!

Juozas Kaziukėnas 2010 / Leave feedback at http://joind.in/2060

Page 11: Optimizing Zend Framework

Usually you make it slow?!• First of all:

• Not using APC cache• Not caching anything• Not reading Zend Framework performance guide (http://bit.ly/x0zIf) • Blaming framework for poor SQL queries and other bottlenecks • … a dozen more

• Those can be fixed easily, just read the manual (RTFM!)• Won’t fix all of the problems

Juozas Kaziukėnas 2010 / Leave feedback at http://joind.in/2060

Page 12: Optimizing Zend Framework

Solving some of those issues• Caching is easy, but don’t overuse it• Do as much as possible/needed asynchronously

• Gearman (http://gearman.org/)

• HTTP server optimizations• Lighttpd, Nginx

Juozas Kaziukėnas 2010 / Leave feedback at http://joind.in/2060

Page 13: Optimizing Zend Framework

HOW PEOPLE FIND SLOW PARTS?

Juozas Kaziukėnas 2010 / Leave feedback at http://joind.in/2060

Page 14: Optimizing Zend Framework

Possible ways• Crashing servers• Logging

• SQL queries• Slow requests• Memory usage behavior

• Static analysis • Profiling

Juozas Kaziukėnas 2010 / Leave feedback at http://joind.in/2060

Page 15: Optimizing Zend Framework

Profiling• Really easy to setup, only requires xdebug PHP extension

by Derick Rethans• Analyzer: KCacheGrind, WebGrind etc.• Much more faster and true than static code analysis • Can spot any problem anywhere

Juozas Kaziukėnas 2010 / Leave feedback at http://joind.in/2060

Page 16: Optimizing Zend Framework

A KEY TO OPTIMIZING ZEND FRAMEWORK APPLICATIONS

Juozas Kaziukėnas 2010 / Leave feedback at http://joind.in/2060

Page 17: Optimizing Zend Framework

Zend Framework by default is *slow*

Juozas Kaziukėnas 2010 / Leave feedback at http://joind.in/2060

Page 18: Optimizing Zend Framework

Why is it slow by default?• Application structure made for configurability and fast

building, not for large scale websites• Works in most cases, gets your site up and running• Documentation/examples are unclear• Has a performance limit:

• Zend_Application• Autoloading and plugin loading• All the magic inside views and controllers

• How slow it really is?

Juozas Kaziukėnas 2010 / Leave feedback at http://joind.in/2060

Page 19: Optimizing Zend Framework

Compromise between performance and ease-of-use

Juozas Kaziukėnas 2010 / Leave feedback at http://joind.in/2060

Page 20: Optimizing Zend Framework

HOW SLOW IT REALLY IS?

Juozas Kaziukėnas 2010 / Leave feedback at http://joind.in/2060

Page 21: Optimizing Zend Framework

Average – 30 requests per second. Or 2.5 million page views per day.

Do you need that many?

Juozas Kaziukėnas 2010 / Leave feedback at http://joind.in/2060

Page 22: Optimizing Zend Framework

If you do• Requires much more experience that just building an app• Dark magic• Use the power of Zend Framework – it’s components as

you want• Engineering task• A lot more easier with Zend Framework 2.0

Juozas Kaziukėnas 2010 / Leave feedback at http://joind.in/2060

Rules of Optimization:Rule 1: Don't do it.Rule 2 (for experts only): Don't do it yet. 

Michael A. Jackson

Page 23: Optimizing Zend Framework

Conclusion• Speed may wary A LOT• Requires experience to get it to perform better than other

frameworks• Use latest PHP version (5.3 works great!)• Monitor performance by logging • Profile application before release• Improvise

Juozas Kaziukėnas 2010 / Leave feedback at http://joind.in/2060

Page 24: Optimizing Zend Framework

If all you have is a hammer, everything looks

like a nail

Juozas Kaziukėnas 2010 / Leave feedback at http://joind.in/2060

Page 25: Optimizing Zend Framework

Thanks!• Comments welcome at http://joind.in/2060• Speak to me:

• Directly• Via email [email protected]• Via twitter @juokaz

• Have a nice conference!