SlideShare une entreprise Scribd logo
1  sur  15
Télécharger pour lire hors ligne
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

Contenu connexe

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

En vedette

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

En vedette (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

An Introduction to Scaling Symfony

  • 1. Scaling Symfony Whip your Website into Shape Brent Shaffer @bshaffer CentreSource Interactive Agency www.brentertainment.com 1
  • 2. 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
  • 3. 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
  • 4. 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
  • 5. 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
  • 6. 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
  • 7. 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
  • 8. 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
  • 9. 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
  • 10. 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
  • 11. 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
  • 12. 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
  • 13. 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
  • 14. 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
  • 15. Questions? Brent Shaffer @bshaffer CentreSource Interactive Agency www.brentertainment.com 15