SlideShare una empresa de Scribd logo
1 de 48
CakePHP at a massive
 scale, on a budget
       Andy Gale
Introduction


• I’m a web developer
• I’ve been with websites since ’96
• I’m from Bristol, UK
© Ian Wade http://ianwadephotography.co.uk/




Clifton Suspension Bridge
Introduction

• I work for Future Publishing Plc
• We are based in Bath, UK and have offices
  in London, San Francisco, New York and
  Sydney
• We publish over 180 special-interest
  publications
Publications
To name a few:

• In the UK we publish SFX, Cycling Plus,
  TotalFilm, MBUK, Simply Knitting, Official
  Playstation Magazine, .Net
• In the US we publish Mac|Life, World of
  Warcraft Official Magazine
• In Australia we publish Guitarist, T3, Official
  Nintendo, Official Xbox 360
Websites

• TechRadar, BikeRadar, MusicRadar,
  GamesRadar, PhotoRadar
• CyclingNews, TotalFilm
• Many more...
Websites

• Most websites contain: news, features,
  reviews, products, forums
• Ad funded
• Popular sites, lots of traffic, often market
  leaders
Website Platforms
   We try to use the most appropriate
      website platform for the job
• Wordpress for small builds
  http://www.futureplc.com
• Drupal for medium builds
  http://www.photoradar.com
• CakePHP for large custom builds
  http://www.totalfilm.com
  http://www.cyclingnews.com
Our first big CakePHP build

• The first CakePHP build had 6 developers,
  2 front-end developers and most hadn’t
  used CakePHP before
• Design change halfway through site build
• But the site was completely with time to
  spare
We learnt some lessons



• Most developers thought they knew better
• They didn’t really embrace CakePHP
  conventions - myself included
• They didn’t know better
We learnt some lessons


• We ended up with at four different ways of
  doing everything
• Our future site builds with CakePHP really
  should use developers that “get” the
  framework
Launch day


• Expecting 30k page views
• Got 100k page views
• Site held up nicely
• We all went to the pub
The day after launch day

• Marketing and PR departments announced
  the new site and started pimping links
• IMDB liked one of the launch stories and
  put a link on their homepage
• We got 500k page views
• CakePHP view caching did not hold up
  because the server just couldn’t run
  enough copies of PHP
Oh crap! It broke

• How did we fix it?
• JavaScript used for dynamic aspects such as
  user login/out
• Cached full pages in Memcache via a helper
• Served directly from Memcache with Nginx
• More info:
  http://andy-gale.com/cakephp-view-memcache.html
Quick fix cache solution wasn’t perfect!

• Hub pages - i.e. the homepage, features -
  weren’t immediately updated as content
  changed
• Simple changes to content meant entire
  sections of the site should be rebuilt
• Susceptible to the “thundering herd”
  problem
Thundering Herd
Thundering Herd
               A cache issue

• When cached item expires an unlucky user
  has to rebuild item in cache
• But we have many requests every second
• That’s a lot of concurrent requests trying
  to rebuild the item in cache
• And then we have an unlucky server
Thundering Herd
          Solutions - Soft expire

• A single unlucky user rebuilds that cache
  item
• And creates a lock in the cache so no
  other users try to recreate
• Lock must expire quickly in case rebuild
  fails
Thundering Herd
       Solutions - Update the cache!!!



• The best way to prevent the thundering
  herd problem is positive cache expiry
• Update the cache when things change!
• Sometimes easier said than done
© Roberto Bettini
Our next project
• Recently acquired by Future Publishing
• World’s number one cycling site
• Flat HTML website
• Editors used text editor to hand code
  HTML and FTP to update the website
• Laborious to edit but fast to serve
Our next project
• CMS driven website needed
• De-skill editorial requirements
• More modern design
• Still needs to handle 4 million page views in
  a day during the Tour de France
• Massive peak towards the end of a stage
Page views per hour
Our next project
•   It’s a news site and needs to update
    instantly
• High traffic peaks during the Tour de
    France or doping story
• Couldn’t tolerate the caching issues of that
    TotalFilm
• Don’t have a Facebook’s hardware budget
How would we cache it?

• Instead of caching whole pages, cache
  individual elements
• We called them “panels”
• The data in each panel relates to a model
  so when that model is saved we can update
  the cache of panels related to that model
1000 requests per second


• At peak times (i.e. at the end of a stage)
• Not the CSS, JS and other static elements
  they are served via a CDN
• That’s serving just the HTML
Can we handle that with CakePHP?


• After the success of TotalFilm we wanted
  to use CakePHP again
• But we we’re worried it wouldn’t scale to
  1000 requests a second
• So we benchmarked it
Can we handle that with CakePHP?


• CakePHP with requestAction was very
  slow
• CakePHP with elements cached was
  actually pretty quick but too slow
So what did we do?


• CakePHP for the CMS
• CakePHP generating the HTML separated
  into panels
• CakePHP for publishing HTML panels into
  Memcache
So what did we do?


• We used a very simple PHP script to
  compile the HTML into full pages
• Works out which panels are required from
  URL, fetches parts of the page from
  Memcache and compiles page
Benchmarks (average with all panels cached)
• Using CakePHP with cached elements
  0.1521 seconds

• Pagecompiler
  0.0488 seconds
• Pagecompiler with optimisation
  0.0031 seconds
How do we update the panels?



• View panel - an article
• When article changes, panel needs to be
  updated
Two types of panel


 Hub panel
  Often a listing

Difficult to update
Hub panels - Need to update?


• We stored the find params for each panel
• Check beforeSave and afterSave, compare
  the resulting arrays and if they’ve changed
  the HTML panel needs to be regenerated
Model beforeSave

Model->find() for the each panel
    associated with model



  Model afterSave

Model->find() for the each panel   Ensure find query isn’t
    associated with model               cached!!!



 Update HTML panel in cache
Lots of panels


• To avoid making the CMS really slow
  generating loads of HTML panels for every
  save we decided to use a queue
• And made a CakePHP shell to work
  through the panels and publish them
Panelworker

• CakePHP shell
• Works through the panels and publishes
  them
• Queue system prevents panels being
  regenerated over and over again when
  altered by multiple users
Panelworker



• Parent/child architecture with IPC
• Able to process 20 panels at once
• State engine with socket_select()
CMS                        Panelworker

  Place changed                  Next item from queue
 panels in queue
                               Fetch panel HTML from CMS
    Panel queue
           /news
                                 Publish panel HTML to
 /news/view/lance-is-amazing
                                       Memcache
 /races/view/tour-de-france

/features/view/some-new-bike




                               www1            www2
What else?
• We cached generated pages for 60 seconds
  in Memcache and served directly from
  Nginx to give us even more head room
• www. servers also run Panelworkers to
  enable them to get panels they don’t have
• Panels are also cached on disk for when
  they fall out of Memcache
So the site launched


• 1181 forum posts complaining
• Lance Armstrong tweets saying he hates
  the site
• But, it easily handled the traffic and we have
  loads of head room
Alternatively
• If your site needs more interactivity with
  users, replace HTML panels with data
• Use a similar system to update data in the
  cache when things change
• A queue system similar to the Panelworker
  could still be useful to keep your site
  responsive
What we’d do differently


• Instead of storing find params use a model
  method for fetching content for each panel
• Despite being fast the web site lacks
  interactively
• Use Membase instead of both Memcache
  and files to store panels
But...


• Since we did out benchmarks over a year
  ago CakePHP 1.3 seems a lot quicker
• LazyModel by Frank de Graaf (and others)
  http://bakery.cakephp.org/articles/view/optimizing-model-loading-with-lazymodel



• Although it still connects to MySQL when
  there is no need :(
But...




• For the new build we’re implementing the
  following caching system...
Questions or comments?


Twitter: @andygale
http://www.cyclingnews.com
http://www.totalfilm.com
http://www.andy-gale.com

Más contenido relacionado

La actualidad más candente

Java EE Servlet/JSP Tutorial- Cookbook 2
Java EE Servlet/JSP Tutorial- Cookbook 2Java EE Servlet/JSP Tutorial- Cookbook 2
Java EE Servlet/JSP Tutorial- Cookbook 2billdigman
 
Sympal - The flexible Symfony CMS
Sympal - The flexible Symfony CMSSympal - The flexible Symfony CMS
Sympal - The flexible Symfony CMSJonathan Wage
 
How to make your Webpack builds 10x faster
How to make your Webpack builds 10x fasterHow to make your Webpack builds 10x faster
How to make your Webpack builds 10x fastertrueter
 
Speeding up your WordPress Site - WordCamp Toronto 2015
Speeding up your WordPress Site - WordCamp Toronto 2015Speeding up your WordPress Site - WordCamp Toronto 2015
Speeding up your WordPress Site - WordCamp Toronto 2015Alan Lok
 
Bangalore meetup slides_dec_7th_2019
Bangalore meetup slides_dec_7th_2019Bangalore meetup slides_dec_7th_2019
Bangalore meetup slides_dec_7th_2019pruthviraj krishnam
 
IWMW 2003: Content Management - Buy or Build?
IWMW 2003: Content Management - Buy or Build?IWMW 2003: Content Management - Buy or Build?
IWMW 2003: Content Management - Buy or Build?IWMW
 
Deploying A Static Website Using WordPress
 Deploying A Static Website Using WordPress Deploying A Static Website Using WordPress
Deploying A Static Website Using WordPressDaniel Schutzsmith
 
IWMW 2003: Content Management - Buy or Build?
IWMW 2003: Content Management - Buy or Build?IWMW 2003: Content Management - Buy or Build?
IWMW 2003: Content Management - Buy or Build?IWMW
 
WordCamp Kent 2019 - WP 101: Local Development - Themes and Plugins
WordCamp Kent 2019 - WP 101: Local Development - Themes and PluginsWordCamp Kent 2019 - WP 101: Local Development - Themes and Plugins
WordCamp Kent 2019 - WP 101: Local Development - Themes and PluginsJoe Querin
 
ServerBeach and WordPress BlogWorldExpo 2007
ServerBeach and WordPress BlogWorldExpo 2007ServerBeach and WordPress BlogWorldExpo 2007
ServerBeach and WordPress BlogWorldExpo 2007Barry Abrahamson
 
High Performance WordPress
High Performance WordPressHigh Performance WordPress
High Performance WordPressBarry Abrahamson
 
High Performance WordPress II
High Performance WordPress IIHigh Performance WordPress II
High Performance WordPress IIBarry Abrahamson
 
Task runners + theming automating your workflow
Task runners + theming  automating your workflowTask runners + theming  automating your workflow
Task runners + theming automating your workflowJoshua Gilmer
 
HyperDB, MySQL Performance, & Flavors of MySQL
HyperDB, MySQL Performance, & Flavors of MySQLHyperDB, MySQL Performance, & Flavors of MySQL
HyperDB, MySQL Performance, & Flavors of MySQLEvan Volgas
 
High Performance WordPress - WordCamp Jerusalem 2010
High Performance WordPress - WordCamp Jerusalem 2010High Performance WordPress - WordCamp Jerusalem 2010
High Performance WordPress - WordCamp Jerusalem 2010Barry Abrahamson
 
Bodócz Tamás- Web Perfomance & Caching Issues
Bodócz Tamás- Web Perfomance & Caching IssuesBodócz Tamás- Web Perfomance & Caching Issues
Bodócz Tamás- Web Perfomance & Caching Issuesveszpremimeetup
 
Save Time by Managing WordPress from the Command Line
Save Time by Managing WordPress from the Command LineSave Time by Managing WordPress from the Command Line
Save Time by Managing WordPress from the Command LineShawn Hooper
 

La actualidad más candente (20)

Java EE Servlet/JSP Tutorial- Cookbook 2
Java EE Servlet/JSP Tutorial- Cookbook 2Java EE Servlet/JSP Tutorial- Cookbook 2
Java EE Servlet/JSP Tutorial- Cookbook 2
 
Sympal - The flexible Symfony CMS
Sympal - The flexible Symfony CMSSympal - The flexible Symfony CMS
Sympal - The flexible Symfony CMS
 
How to make your Webpack builds 10x faster
How to make your Webpack builds 10x fasterHow to make your Webpack builds 10x faster
How to make your Webpack builds 10x faster
 
Speeding up your WordPress Site - WordCamp Toronto 2015
Speeding up your WordPress Site - WordCamp Toronto 2015Speeding up your WordPress Site - WordCamp Toronto 2015
Speeding up your WordPress Site - WordCamp Toronto 2015
 
Bangalore meetup slides_dec_7th_2019
Bangalore meetup slides_dec_7th_2019Bangalore meetup slides_dec_7th_2019
Bangalore meetup slides_dec_7th_2019
 
IWMW 2003: Content Management - Buy or Build?
IWMW 2003: Content Management - Buy or Build?IWMW 2003: Content Management - Buy or Build?
IWMW 2003: Content Management - Buy or Build?
 
Deploying A Static Website Using WordPress
 Deploying A Static Website Using WordPress Deploying A Static Website Using WordPress
Deploying A Static Website Using WordPress
 
IWMW 2003: Content Management - Buy or Build?
IWMW 2003: Content Management - Buy or Build?IWMW 2003: Content Management - Buy or Build?
IWMW 2003: Content Management - Buy or Build?
 
WordCamp Kent 2019 - WP 101: Local Development - Themes and Plugins
WordCamp Kent 2019 - WP 101: Local Development - Themes and PluginsWordCamp Kent 2019 - WP 101: Local Development - Themes and Plugins
WordCamp Kent 2019 - WP 101: Local Development - Themes and Plugins
 
ServerBeach and WordPress BlogWorldExpo 2007
ServerBeach and WordPress BlogWorldExpo 2007ServerBeach and WordPress BlogWorldExpo 2007
ServerBeach and WordPress BlogWorldExpo 2007
 
High Performance WordPress
High Performance WordPressHigh Performance WordPress
High Performance WordPress
 
High Performance WordPress II
High Performance WordPress IIHigh Performance WordPress II
High Performance WordPress II
 
Task runners + theming automating your workflow
Task runners + theming  automating your workflowTask runners + theming  automating your workflow
Task runners + theming automating your workflow
 
HyperDB, MySQL Performance, & Flavors of MySQL
HyperDB, MySQL Performance, & Flavors of MySQLHyperDB, MySQL Performance, & Flavors of MySQL
HyperDB, MySQL Performance, & Flavors of MySQL
 
High Performance WordPress - WordCamp Jerusalem 2010
High Performance WordPress - WordCamp Jerusalem 2010High Performance WordPress - WordCamp Jerusalem 2010
High Performance WordPress - WordCamp Jerusalem 2010
 
Bodócz Tamás- Web Perfomance & Caching Issues
Bodócz Tamás- Web Perfomance & Caching IssuesBodócz Tamás- Web Perfomance & Caching Issues
Bodócz Tamás- Web Perfomance & Caching Issues
 
Managed WordPress Demystified
Managed WordPress DemystifiedManaged WordPress Demystified
Managed WordPress Demystified
 
More Multisite for the Masses
More Multisite for the MassesMore Multisite for the Masses
More Multisite for the Masses
 
Save Time by Managing WordPress from the Command Line
Save Time by Managing WordPress from the Command LineSave Time by Managing WordPress from the Command Line
Save Time by Managing WordPress from the Command Line
 
ReactPHP + Symfony
ReactPHP + SymfonyReactPHP + Symfony
ReactPHP + Symfony
 

Similar a CakePHP at a Massive Scale on a Budget

Improving Performance on Magento 1*
Improving Performance on Magento 1*Improving Performance on Magento 1*
Improving Performance on Magento 1*David Z. Lerner
 
Symfony2 for legacy app rejuvenation: the eZ Publish case study
Symfony2 for legacy app rejuvenation: the eZ Publish case studySymfony2 for legacy app rejuvenation: the eZ Publish case study
Symfony2 for legacy app rejuvenation: the eZ Publish case studyGaetano Giunta
 
Nsc 2013 06-17 - random rants on 2013
Nsc 2013 06-17 - random rants on 2013Nsc 2013 06-17 - random rants on 2013
Nsc 2013 06-17 - random rants on 2013Mikael Svenson
 
Live Coverage at The New York Times
Live Coverage at The New York TimesLive Coverage at The New York Times
Live Coverage at The New York TimesScott Taylor
 
Squeeze Maximum Performance From Your Joomla Website
Squeeze Maximum Performance From Your Joomla WebsiteSqueeze Maximum Performance From Your Joomla Website
Squeeze Maximum Performance From Your Joomla WebsiteSiteGround.com
 
Empowering Publishers - Hosting Provider Selection Process - May-15-2013
Empowering Publishers - Hosting Provider Selection Process - May-15-2013Empowering Publishers - Hosting Provider Selection Process - May-15-2013
Empowering Publishers - Hosting Provider Selection Process - May-15-2013Amazon Web Services
 
WordPress performance tuning
WordPress performance tuningWordPress performance tuning
WordPress performance tuningVladimír Smitka
 
Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!Jeremy Likness
 
Tim Scollick - Flex, Seo And You
Tim Scollick - Flex, Seo And YouTim Scollick - Flex, Seo And You
Tim Scollick - Flex, Seo And YouRefresh Events
 
Content Migrations: Getting from A to B
Content Migrations: Getting from A to BContent Migrations: Getting from A to B
Content Migrations: Getting from A to BBlend Interactive
 
Giuliana Benedetti - Can Magento handle 1M products?
Giuliana Benedetti - Can Magento handle 1M products?Giuliana Benedetti - Can Magento handle 1M products?
Giuliana Benedetti - Can Magento handle 1M products?Meet Magento Italy
 
Cms & wordpress theme development 2011
Cms & wordpress theme development 2011Cms & wordpress theme development 2011
Cms & wordpress theme development 2011Dave Wallace
 
Imagine 2014: The Devil is in the Details How to Optimize Magento Hosting to ...
Imagine 2014: The Devil is in the Details How to Optimize Magento Hosting to ...Imagine 2014: The Devil is in the Details How to Optimize Magento Hosting to ...
Imagine 2014: The Devil is in the Details How to Optimize Magento Hosting to ...George White
 
JS digest. Decemebr 2017
JS digest. Decemebr 2017JS digest. Decemebr 2017
JS digest. Decemebr 2017ElifTech
 
Content Management Systems and Refactoring - Drupal, WordPress and eZ Publish
Content Management Systems and Refactoring - Drupal, WordPress and eZ PublishContent Management Systems and Refactoring - Drupal, WordPress and eZ Publish
Content Management Systems and Refactoring - Drupal, WordPress and eZ PublishJani Tarvainen
 
Parallel and Asynchronous Programming - ITProDevConnections 2012 (English)
Parallel and Asynchronous Programming -  ITProDevConnections 2012 (English)Parallel and Asynchronous Programming -  ITProDevConnections 2012 (English)
Parallel and Asynchronous Programming - ITProDevConnections 2012 (English)Panagiotis Kanavos
 
OVERVIEW OF FACEBOOK SCALABLE ARCHITECTURE.
OVERVIEW  OF FACEBOOK SCALABLE ARCHITECTURE.OVERVIEW  OF FACEBOOK SCALABLE ARCHITECTURE.
OVERVIEW OF FACEBOOK SCALABLE ARCHITECTURE.Rishikese MR
 
Packing It In: Images, Containers and Config Management
Packing It In: Images, Containers and Config ManagementPacking It In: Images, Containers and Config Management
Packing It In: Images, Containers and Config ManagementMichael Goetz
 
Ruby in office time reboot
Ruby in office time rebootRuby in office time reboot
Ruby in office time rebootKentaro Goto
 

Similar a CakePHP at a Massive Scale on a Budget (20)

Improving Performance on Magento 1*
Improving Performance on Magento 1*Improving Performance on Magento 1*
Improving Performance on Magento 1*
 
Symfony2 for legacy app rejuvenation: the eZ Publish case study
Symfony2 for legacy app rejuvenation: the eZ Publish case studySymfony2 for legacy app rejuvenation: the eZ Publish case study
Symfony2 for legacy app rejuvenation: the eZ Publish case study
 
Nsc 2013 06-17 - random rants on 2013
Nsc 2013 06-17 - random rants on 2013Nsc 2013 06-17 - random rants on 2013
Nsc 2013 06-17 - random rants on 2013
 
Live Coverage at The New York Times
Live Coverage at The New York TimesLive Coverage at The New York Times
Live Coverage at The New York Times
 
Squeeze Maximum Performance From Your Joomla Website
Squeeze Maximum Performance From Your Joomla WebsiteSqueeze Maximum Performance From Your Joomla Website
Squeeze Maximum Performance From Your Joomla Website
 
Last Call Media Drupal 8 Case Study
Last Call Media Drupal 8 Case StudyLast Call Media Drupal 8 Case Study
Last Call Media Drupal 8 Case Study
 
Empowering Publishers - Hosting Provider Selection Process - May-15-2013
Empowering Publishers - Hosting Provider Selection Process - May-15-2013Empowering Publishers - Hosting Provider Selection Process - May-15-2013
Empowering Publishers - Hosting Provider Selection Process - May-15-2013
 
WordPress performance tuning
WordPress performance tuningWordPress performance tuning
WordPress performance tuning
 
Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!
 
Tim Scollick - Flex, Seo And You
Tim Scollick - Flex, Seo And YouTim Scollick - Flex, Seo And You
Tim Scollick - Flex, Seo And You
 
Content Migrations: Getting from A to B
Content Migrations: Getting from A to BContent Migrations: Getting from A to B
Content Migrations: Getting from A to B
 
Giuliana Benedetti - Can Magento handle 1M products?
Giuliana Benedetti - Can Magento handle 1M products?Giuliana Benedetti - Can Magento handle 1M products?
Giuliana Benedetti - Can Magento handle 1M products?
 
Cms & wordpress theme development 2011
Cms & wordpress theme development 2011Cms & wordpress theme development 2011
Cms & wordpress theme development 2011
 
Imagine 2014: The Devil is in the Details How to Optimize Magento Hosting to ...
Imagine 2014: The Devil is in the Details How to Optimize Magento Hosting to ...Imagine 2014: The Devil is in the Details How to Optimize Magento Hosting to ...
Imagine 2014: The Devil is in the Details How to Optimize Magento Hosting to ...
 
JS digest. Decemebr 2017
JS digest. Decemebr 2017JS digest. Decemebr 2017
JS digest. Decemebr 2017
 
Content Management Systems and Refactoring - Drupal, WordPress and eZ Publish
Content Management Systems and Refactoring - Drupal, WordPress and eZ PublishContent Management Systems and Refactoring - Drupal, WordPress and eZ Publish
Content Management Systems and Refactoring - Drupal, WordPress and eZ Publish
 
Parallel and Asynchronous Programming - ITProDevConnections 2012 (English)
Parallel and Asynchronous Programming -  ITProDevConnections 2012 (English)Parallel and Asynchronous Programming -  ITProDevConnections 2012 (English)
Parallel and Asynchronous Programming - ITProDevConnections 2012 (English)
 
OVERVIEW OF FACEBOOK SCALABLE ARCHITECTURE.
OVERVIEW  OF FACEBOOK SCALABLE ARCHITECTURE.OVERVIEW  OF FACEBOOK SCALABLE ARCHITECTURE.
OVERVIEW OF FACEBOOK SCALABLE ARCHITECTURE.
 
Packing It In: Images, Containers and Config Management
Packing It In: Images, Containers and Config ManagementPacking It In: Images, Containers and Config Management
Packing It In: Images, Containers and Config Management
 
Ruby in office time reboot
Ruby in office time rebootRuby in office time reboot
Ruby in office time reboot
 

Último

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 

Último (20)

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 

CakePHP at a Massive Scale on a Budget

  • 1. CakePHP at a massive scale, on a budget Andy Gale
  • 2. Introduction • I’m a web developer • I’ve been with websites since ’96 • I’m from Bristol, UK
  • 3. © Ian Wade http://ianwadephotography.co.uk/ Clifton Suspension Bridge
  • 4. Introduction • I work for Future Publishing Plc • We are based in Bath, UK and have offices in London, San Francisco, New York and Sydney • We publish over 180 special-interest publications
  • 5. Publications To name a few: • In the UK we publish SFX, Cycling Plus, TotalFilm, MBUK, Simply Knitting, Official Playstation Magazine, .Net • In the US we publish Mac|Life, World of Warcraft Official Magazine • In Australia we publish Guitarist, T3, Official Nintendo, Official Xbox 360
  • 6. Websites • TechRadar, BikeRadar, MusicRadar, GamesRadar, PhotoRadar • CyclingNews, TotalFilm • Many more...
  • 7. Websites • Most websites contain: news, features, reviews, products, forums • Ad funded • Popular sites, lots of traffic, often market leaders
  • 8. Website Platforms We try to use the most appropriate website platform for the job • Wordpress for small builds http://www.futureplc.com • Drupal for medium builds http://www.photoradar.com • CakePHP for large custom builds http://www.totalfilm.com http://www.cyclingnews.com
  • 9.
  • 10. Our first big CakePHP build • The first CakePHP build had 6 developers, 2 front-end developers and most hadn’t used CakePHP before • Design change halfway through site build • But the site was completely with time to spare
  • 11. We learnt some lessons • Most developers thought they knew better • They didn’t really embrace CakePHP conventions - myself included • They didn’t know better
  • 12. We learnt some lessons • We ended up with at four different ways of doing everything • Our future site builds with CakePHP really should use developers that “get” the framework
  • 13. Launch day • Expecting 30k page views • Got 100k page views • Site held up nicely • We all went to the pub
  • 14. The day after launch day • Marketing and PR departments announced the new site and started pimping links • IMDB liked one of the launch stories and put a link on their homepage • We got 500k page views • CakePHP view caching did not hold up because the server just couldn’t run enough copies of PHP
  • 15. Oh crap! It broke • How did we fix it? • JavaScript used for dynamic aspects such as user login/out • Cached full pages in Memcache via a helper • Served directly from Memcache with Nginx • More info: http://andy-gale.com/cakephp-view-memcache.html
  • 16. Quick fix cache solution wasn’t perfect! • Hub pages - i.e. the homepage, features - weren’t immediately updated as content changed • Simple changes to content meant entire sections of the site should be rebuilt • Susceptible to the “thundering herd” problem
  • 18. Thundering Herd A cache issue • When cached item expires an unlucky user has to rebuild item in cache • But we have many requests every second • That’s a lot of concurrent requests trying to rebuild the item in cache • And then we have an unlucky server
  • 19. Thundering Herd Solutions - Soft expire • A single unlucky user rebuilds that cache item • And creates a lock in the cache so no other users try to recreate • Lock must expire quickly in case rebuild fails
  • 20. Thundering Herd Solutions - Update the cache!!! • The best way to prevent the thundering herd problem is positive cache expiry • Update the cache when things change! • Sometimes easier said than done
  • 22. Our next project • Recently acquired by Future Publishing • World’s number one cycling site • Flat HTML website • Editors used text editor to hand code HTML and FTP to update the website • Laborious to edit but fast to serve
  • 23. Our next project • CMS driven website needed • De-skill editorial requirements • More modern design • Still needs to handle 4 million page views in a day during the Tour de France • Massive peak towards the end of a stage
  • 25. Our next project • It’s a news site and needs to update instantly • High traffic peaks during the Tour de France or doping story • Couldn’t tolerate the caching issues of that TotalFilm • Don’t have a Facebook’s hardware budget
  • 26. How would we cache it? • Instead of caching whole pages, cache individual elements • We called them “panels” • The data in each panel relates to a model so when that model is saved we can update the cache of panels related to that model
  • 27.
  • 28. 1000 requests per second • At peak times (i.e. at the end of a stage) • Not the CSS, JS and other static elements they are served via a CDN • That’s serving just the HTML
  • 29. Can we handle that with CakePHP? • After the success of TotalFilm we wanted to use CakePHP again • But we we’re worried it wouldn’t scale to 1000 requests a second • So we benchmarked it
  • 30. Can we handle that with CakePHP? • CakePHP with requestAction was very slow • CakePHP with elements cached was actually pretty quick but too slow
  • 31. So what did we do? • CakePHP for the CMS • CakePHP generating the HTML separated into panels • CakePHP for publishing HTML panels into Memcache
  • 32. So what did we do? • We used a very simple PHP script to compile the HTML into full pages • Works out which panels are required from URL, fetches parts of the page from Memcache and compiles page
  • 33. Benchmarks (average with all panels cached) • Using CakePHP with cached elements 0.1521 seconds • Pagecompiler 0.0488 seconds • Pagecompiler with optimisation 0.0031 seconds
  • 34. How do we update the panels? • View panel - an article • When article changes, panel needs to be updated
  • 35. Two types of panel Hub panel Often a listing Difficult to update
  • 36. Hub panels - Need to update? • We stored the find params for each panel • Check beforeSave and afterSave, compare the resulting arrays and if they’ve changed the HTML panel needs to be regenerated
  • 37. Model beforeSave Model->find() for the each panel associated with model Model afterSave Model->find() for the each panel Ensure find query isn’t associated with model cached!!! Update HTML panel in cache
  • 38. Lots of panels • To avoid making the CMS really slow generating loads of HTML panels for every save we decided to use a queue • And made a CakePHP shell to work through the panels and publish them
  • 39. Panelworker • CakePHP shell • Works through the panels and publishes them • Queue system prevents panels being regenerated over and over again when altered by multiple users
  • 40. Panelworker • Parent/child architecture with IPC • Able to process 20 panels at once • State engine with socket_select()
  • 41. CMS Panelworker Place changed Next item from queue panels in queue Fetch panel HTML from CMS Panel queue /news Publish panel HTML to /news/view/lance-is-amazing Memcache /races/view/tour-de-france /features/view/some-new-bike www1 www2
  • 42. What else? • We cached generated pages for 60 seconds in Memcache and served directly from Nginx to give us even more head room • www. servers also run Panelworkers to enable them to get panels they don’t have • Panels are also cached on disk for when they fall out of Memcache
  • 43. So the site launched • 1181 forum posts complaining • Lance Armstrong tweets saying he hates the site • But, it easily handled the traffic and we have loads of head room
  • 44. Alternatively • If your site needs more interactivity with users, replace HTML panels with data • Use a similar system to update data in the cache when things change • A queue system similar to the Panelworker could still be useful to keep your site responsive
  • 45. What we’d do differently • Instead of storing find params use a model method for fetching content for each panel • Despite being fast the web site lacks interactively • Use Membase instead of both Memcache and files to store panels
  • 46. But... • Since we did out benchmarks over a year ago CakePHP 1.3 seems a lot quicker • LazyModel by Frank de Graaf (and others) http://bakery.cakephp.org/articles/view/optimizing-model-loading-with-lazymodel • Although it still connects to MySQL when there is no need :(
  • 47. But... • For the new build we’re implementing the following caching system...
  • 48. Questions or comments? Twitter: @andygale http://www.cyclingnews.com http://www.totalfilm.com http://www.andy-gale.com

Notas del editor