An Introduction to Scaling Symfony
Upcoming SlideShare
Loading in...5
×
 

An Introduction to Scaling Symfony

on

  • 15,449 views

A brief introduction to cache strategy and other performance-enhancing techniques when using the symfony full-stack framework.

A brief introduction to cache strategy and other performance-enhancing techniques when using the symfony full-stack framework.

Statistics

Views

Total Views
15,449
Views on SlideShare
10,459
Embed Views
4,990

Actions

Likes
20
Downloads
149
Comments
0

12 Embeds 4,990

http://www.scoop.it 4919
http://www.slideshare.net 38
http://www.sfexception.com 13
http://sanjaysurani.blogspot.com 4
http://symfony2developer.com 4
http://translate.googleusercontent.com 4
http://dev.symfony2developer.com 3
http://www.linkedin.com 1
https://www.google.ca 1
https://www.google.co.il 1
http://cache.baiducontent.com 1
http://www.brijj.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

An Introduction to Scaling Symfony An Introduction to Scaling Symfony Presentation Transcript

  • Scaling Symfony Whip your Website into Shape Brent Shaffer @bshaffer CentreSource Interactive Agency www.brentertainment.com 1
  • Can Symfony Scale? Dan Grossman: Symfony is used for Delicious and Yahoo! Bookmarks, which “[proves] it’s enterprise-ready and able to scale up to millions of active users” Delicious says: “our new platform has been stable and is meeting our performance goals. In the days of the old Delicious, we had to put a lot of effort into just keeping the lights on and struggling to keep up with “growth. With our new infrastructure, these problems are largely gone and our pagers have never been so quiet. But more importantly the Delicious service is now faster and more reliable, which was a key goal of this project. In fact, I’m very happy to say that Delicious has experienced zero downtime since the day after launch” *http://www.dangrossman.info/2008/08/03/delicious-proof-that-symfony-is-a-scalable-framework/ 2
  • It’s All About The Cache Cache == Time Performance time, processing time, etc. Time == Money Money == Cash Cache == Cash?* *Yes, this is a bad joke. Please disregard it. 3
  • Where Do I Spend my Cache? Types of Cache Cache Drivers Memcache Byte-Code Cache APC Doctrine Query Cache FileCache* Doctrine Result Cache XCache Page Cache E Accelerator* Partial Cache DB Cache (Doctrine Only) Array Cache (Memory Storage) *Not available in Doctrine 4
  • Query Caching Query Lifecycle: “The query cache has no disadvantages... 1.Init new DQL query always use query caching in your 2.Parse DQL query production environment” 3.Build database specific SQL query - Doctrine Website 4.Execute the SQL query 5.Build the result set 6.Return the result set There IS a disadvantage: Query Cache must be cleared upon updates to your DB. - Less-than Doctrine2: Restart Apache, remove database if applicable, etc. - Doctrine 2: use “clear cache” task Query Caching can be specified at the manager, connection, and query levels $managerOrConn->setAttribute(Doctrine::ATTR_QUERY_CACHE, $q = Doctrine_Query::create() new Doctrine_Cache_Apc()); ->useQueryCache(new Doctrine_Cache_Memcache()); Always use Prepared Statements (placeholders for dynamic content) Right! WRONG! $query->where('a.id = ?', $id); $query->where('a.id = '. $id); 5
  • Result Caching Query Lifecycle: 1.Init new DQL query 2.Parse DQL query 3.Build database specific SQL query 4.Execute the SQL query 5.Build the result set 6.Return the result set Use Doctrine Attributes to set result caching at the manager, connection, or query level $managerOrConn->setAttribute( $q = Doctrine_Query::create() Doctrine::ATTR_RESULT_CACHE, new Doctrine_Cache_Apc()); ->useResultCache(new Doctrine_Cache_Memcache()); $managerOrConn->setAttribute( Doctrine::ATTR_RESULT_CACHE_LIFESPAN, new Doctrine_Cache_Apc()); Activate Result Cache on a query level $query->useResultCache(); // Designate query to use result cache $query->expireResultCache(); // Force result cache expiration $query->expireQueryCache(); // Force query cache expiration 6
  • View Cache Action Cache # /path/to/project/apps/myapp/modules/mymodule/config/cache.yml list: enabled: true with_layout: false # Default Value lifetime: 86400 # Default Value Partial/Component/Slot Cache # /path/to/project/apps/myapp/modules/mymodule/config/cache.yml _partial_or_component: enabled: true with_layout: false # Default Value lifetime: 86400 # Default Value Template Fragment Cache <?php use_helper('Cache') ?> 7
  • Action Caching Action Cache Lifecycle An incoming request with GET parameters or submitted with the POST, PUT, or DELETE method will never be cached by symfony, regardless of the configuration. 8
  • Action Caching Layout Cache Lifecycle This time, the whole response object is stored in cache.This means that the cache with layout is much faster than the cache without it. 9
  • Doctrine View Cache (http://symplist.net/plugins/sfDoctrineViewCachePlugin) Utilizes Doctrine Routes and a Doctrine Behavior to clear the view cache for specified actions of the same class # /path/to/project/config/doctrine/schema.yml BlogPost: actAs: sfViewCache: global: true # clear cache globally clear_routes: frontend # clear sfDoctrineRoutes for this object class on_delete: false # trigger on event (also: on_create and on_update) Can specify if cache is cleared on Insert, Update, and Delete Limitations: 1. No application control for individual routes 4. All configurations take place in your model’s SCHEMA?! 2. Redeclaration of routing rules (name to module/action/ params) 5. Great concept, lacks polish 3. No official release 10
  • Partial/Component/Slot Caching Slots are part of the template, and caching an action will also store the value of the slots defined in this action's template. So the cache works natively for slots. Partial/component caching is only useful when utilized outside of action caching or with partials/components within a layout. Caching for global partials and components (the ones located in the application templates/ directory) takes place in the application cache.yml. 11
  • Fragment Caching Use Cache Helper <!-- Template Code (not cached) --> <h1>Welcome, <?php echo $sf_user->getGuardUser() ?>!</h1> <!-- Cached code --> <?php if (!cache('products', 43200)): ?> <?php foreach ($products as $product): ?> <li><?php echo link_to($product, '@product?slug='.$product['slug']) ?></li> <?php endforeach; ?> <?php cache_save() ?> <?php endif; ?> Fragment caching is useful only if contained in an uncached view 12
  • Tips and Tricks sfTesterViewCache public function isCached($boolean, $with_layout = false) sfSuperCache Writes view cache to web directory to allow apache to serve up pages without starting symfony npAssetsOptimizer - minification http://symplist.net/plugins/npAssetsOptimizerPlugin 13
  • Tips and Tricks Lazy Route Serialization all: routing: class: sfPatternRouting param: generate_shortest_url: true extra_parameters_as_query_string: true lazy_routes_deserialize: true Clear individual templates / environments: $ php symfony cc --type=template --env=prod --app=frontend (config, i18n, routing, module and template types) System Tuning Mysql - http://www.day32.com/MySQL/ 14
  • Questions? Brent Shaffer @bshaffer CentreSource Interactive Agency www.brentertainment.com 15