SlideShare une entreprise Scribd logo
1  sur  20
Télécharger pour lire hors ligne
PAUL PARTINGTON
Magento Developer at CTI Digital
@paul_partington
What are We Talking
About?
• Caching approaches
• Look at an issue with the configuration cache that
we found
• How we fixed it
Web Server 1
Web Server 2
Magento
Block
Layout
Configuration
Collections
EAV
API
Full Page Cache
Database
APC Cache
Query Cache
Varnish
Cache Storage
• File
• Database
• Redis or Memcached
The Configuration Cache
• Combines the XML files in the system
• Adds in the system configuration
• Every time you add a new module the size
increases
• Every time you add a new website you increase the
size of the configuration XML
• Adds around 125KB on Magento EE 1.14.2.0
Multisite
I think I see where you’re
going with this
• Multiple Websites (9)
• High Traffic
• Caches are going to get cleared
• The configuration cache was cleared and took the
site down
Why’s this happening?
• While the configuration cache is being created,
every request causes the cache generation process
to start
• CPU load increased as the request uses more
memory and takes longer to finish
app/code/core/Mage/Model/App.php
protected function _initModules()
{
if (!$this->_config->loadModulesCache() {
$this->_config->loadModules();
...
}
}
0
0.25
0.5
0.75
1
1.25
-20 -10 0 10 20 30
CPULoad
Time
CPU Load
Cache Policy
• Caches should only be cleared at non-peak times
• Clients should be aware of the effects that clearing
a cache can have
What did we do?
• Created a module
• https://github.com/ctidigital/Configuration-Cache-
Lock
• Similar fix -
https://github.com/madepeople/Made_Cache
How does the module
work?
• Creates a cache lock in a Redis database
• Keep the cache creation to a single request
<global>
...
<cache_lock>
<enable>1</enable> <!-- If cache locking is enabled or not -->
<server>127.0.0.1</server> <!-- The Redis database IP -->
<port>6379</port> <!-- The Redis port -->
<database>0</database> <!-- The Redis Database to use -->
<password></password> <!-- The password of the Redis server -->
<timeout>2.5</timeout> <!-- The Redis timeout -->
<key>cache_lock</key> <!-- The name of lock in the Redis Database -->
<max_attempts>10</max_attempts> <!-- The maximum amount of times to retry the
connection. Defaults to 10. -->
<retry_time>10000000</retry_time> <!-- The amount of microseconds to wait between checking
the cache has generated. Defaults to
10000000 -->
</cache_lock>
...
Edit your local.xml
• Creates a local override of Mage_Core_Model_App
(sorry!)
• New method called _initModulesWithLocking()
protected function _initModulesWithLocking ()
{
if ($this->_config->loadModulesCache()) {
return $this;
}
...
// If the cache is currently being regenerated
if ($ctiCache->getIsCacheLocked()) {
$cacheLock = true;
}
// If the cache needs to be created
if ($cacheLock === false) {
// Create a new cache lock
$ctiCache->acquireCacheLock();
$this->_config->loadModules();
...
// Release the cache lock
$ctiCache->releaseCacheLock();
return $this;
}
...
while ($cacheLock === true && $attempts < $maxAttempts) {
$attempts++;
usleep($ctiCache->getRetryTime());
if ($this->_config->loadModulesCache()) {
return $this;
}
}
0
0.25
0.5
0.75
1
1.25
-20 -10 0 10 20 30
CPULoad
Time
Without the Cache Lock With the Cache Lock
An Unexpected Extra
• Prevents module updates from running more than
once
• Poorly written update scripts may display an error if
ran more than once
Further Reading
• http://alanstorm.com/magento_config_a_critique_an
d_caching
Thank You
• @paul_partington
• @CTIDigitalUK

Contenu connexe

Tendances

Tuning the Performance of Your ColdFusion Environment to Racecar Specs!
Tuning the Performance of Your ColdFusion Environment to Racecar Specs!Tuning the Performance of Your ColdFusion Environment to Racecar Specs!
Tuning the Performance of Your ColdFusion Environment to Racecar Specs!Hostway|HOSTING
 
How to improve your apache web server’s performance
How to improve your apache web server’s performanceHow to improve your apache web server’s performance
How to improve your apache web server’s performanceAndolasoft Inc
 
High Performance Web Sites
High Performance Web SitesHigh Performance Web Sites
High Performance Web SitesRavi Raj
 
Accelerate your ColdFusion Applications using Caching
Accelerate your ColdFusion Applications using CachingAccelerate your ColdFusion Applications using Caching
Accelerate your ColdFusion Applications using CachingColdFusionConference
 
cache concepts and varnish-cache
cache concepts and varnish-cachecache concepts and varnish-cache
cache concepts and varnish-cacheMarc Cortinas Val
 
Memcached B box presentation
Memcached B box presentationMemcached B box presentation
Memcached B box presentationNagesh Chinkeri
 
Roy foubister (hosting high traffic sites on a tight budget)
Roy foubister (hosting high traffic sites on a tight budget)Roy foubister (hosting high traffic sites on a tight budget)
Roy foubister (hosting high traffic sites on a tight budget)WordCamp Cape Town
 
WordPress Speed Optimization
WordPress Speed OptimizationWordPress Speed Optimization
WordPress Speed OptimizationDinesh Jain
 
Memcache Integration with Innodb
Memcache Integration with InnodbMemcache Integration with Innodb
Memcache Integration with InnodbMindfire Solutions
 
17937858 squid-server - [the-xp.blogspot.com]
17937858 squid-server - [the-xp.blogspot.com]17937858 squid-server - [the-xp.blogspot.com]
17937858 squid-server - [the-xp.blogspot.com]Krisman Tarigan
 
HTTP caching with Varnish
HTTP caching with VarnishHTTP caching with Varnish
HTTP caching with VarnishDavid de Boer
 
MySQL High Availability Deep Dive
MySQL High Availability Deep DiveMySQL High Availability Deep Dive
MySQL High Availability Deep Divehastexo
 
Scale Apache with Nginx
Scale Apache with NginxScale Apache with Nginx
Scale Apache with NginxBud Siddhisena
 
Aem dispatcher – tips & tricks
Aem dispatcher – tips & tricksAem dispatcher – tips & tricks
Aem dispatcher – tips & tricksAshokkumar T A
 
Web performance across the HTTP to HTTPS transition
Web performance across the HTTP to HTTPS transitionWeb performance across the HTTP to HTTPS transition
Web performance across the HTTP to HTTPS transitionseanwalbran
 
Presentation on Instant page speed optimization
Presentation on Instant page speed optimizationPresentation on Instant page speed optimization
Presentation on Instant page speed optimizationSanjeev Kumar Jaiswal
 
WordPress At Scale. WordCamp Dhaka 2019
WordPress At Scale. WordCamp Dhaka 2019WordPress At Scale. WordCamp Dhaka 2019
WordPress At Scale. WordCamp Dhaka 2019Anam Ahmed
 
High Performance WordPress - WordCamp Jerusalem 2010
High Performance WordPress - WordCamp Jerusalem 2010High Performance WordPress - WordCamp Jerusalem 2010
High Performance WordPress - WordCamp Jerusalem 2010Barry Abrahamson
 
Caching with Memcached and APC
Caching with Memcached and APCCaching with Memcached and APC
Caching with Memcached and APCBen Ramsey
 

Tendances (20)

Tuning the Performance of Your ColdFusion Environment to Racecar Specs!
Tuning the Performance of Your ColdFusion Environment to Racecar Specs!Tuning the Performance of Your ColdFusion Environment to Racecar Specs!
Tuning the Performance of Your ColdFusion Environment to Racecar Specs!
 
How to improve your apache web server’s performance
How to improve your apache web server’s performanceHow to improve your apache web server’s performance
How to improve your apache web server’s performance
 
High Performance Web Sites
High Performance Web SitesHigh Performance Web Sites
High Performance Web Sites
 
Accelerate your ColdFusion Applications using Caching
Accelerate your ColdFusion Applications using CachingAccelerate your ColdFusion Applications using Caching
Accelerate your ColdFusion Applications using Caching
 
ReplacingSquidWithATS
ReplacingSquidWithATSReplacingSquidWithATS
ReplacingSquidWithATS
 
cache concepts and varnish-cache
cache concepts and varnish-cachecache concepts and varnish-cache
cache concepts and varnish-cache
 
Memcached B box presentation
Memcached B box presentationMemcached B box presentation
Memcached B box presentation
 
Roy foubister (hosting high traffic sites on a tight budget)
Roy foubister (hosting high traffic sites on a tight budget)Roy foubister (hosting high traffic sites on a tight budget)
Roy foubister (hosting high traffic sites on a tight budget)
 
WordPress Speed Optimization
WordPress Speed OptimizationWordPress Speed Optimization
WordPress Speed Optimization
 
Memcache Integration with Innodb
Memcache Integration with InnodbMemcache Integration with Innodb
Memcache Integration with Innodb
 
17937858 squid-server - [the-xp.blogspot.com]
17937858 squid-server - [the-xp.blogspot.com]17937858 squid-server - [the-xp.blogspot.com]
17937858 squid-server - [the-xp.blogspot.com]
 
HTTP caching with Varnish
HTTP caching with VarnishHTTP caching with Varnish
HTTP caching with Varnish
 
MySQL High Availability Deep Dive
MySQL High Availability Deep DiveMySQL High Availability Deep Dive
MySQL High Availability Deep Dive
 
Scale Apache with Nginx
Scale Apache with NginxScale Apache with Nginx
Scale Apache with Nginx
 
Aem dispatcher – tips & tricks
Aem dispatcher – tips & tricksAem dispatcher – tips & tricks
Aem dispatcher – tips & tricks
 
Web performance across the HTTP to HTTPS transition
Web performance across the HTTP to HTTPS transitionWeb performance across the HTTP to HTTPS transition
Web performance across the HTTP to HTTPS transition
 
Presentation on Instant page speed optimization
Presentation on Instant page speed optimizationPresentation on Instant page speed optimization
Presentation on Instant page speed optimization
 
WordPress At Scale. WordCamp Dhaka 2019
WordPress At Scale. WordCamp Dhaka 2019WordPress At Scale. WordCamp Dhaka 2019
WordPress At Scale. WordCamp Dhaka 2019
 
High Performance WordPress - WordCamp Jerusalem 2010
High Performance WordPress - WordCamp Jerusalem 2010High Performance WordPress - WordCamp Jerusalem 2010
High Performance WordPress - WordCamp Jerusalem 2010
 
Caching with Memcached and APC
Caching with Memcached and APCCaching with Memcached and APC
Caching with Memcached and APC
 

Similaire à Mage Titans 2015

Anthony Somerset - Site Speed = Success!
Anthony Somerset - Site Speed = Success!Anthony Somerset - Site Speed = Success!
Anthony Somerset - Site Speed = Success!WordCamp Cape Town
 
Configuring Apache Servers for Better Web Perormance
Configuring Apache Servers for Better Web PerormanceConfiguring Apache Servers for Better Web Perormance
Configuring Apache Servers for Better Web PerormanceSpark::red
 
Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it FastBarry Jones
 
Performance Optimization using Caching | Swatantra Kumar
Performance Optimization using Caching | Swatantra KumarPerformance Optimization using Caching | Swatantra Kumar
Performance Optimization using Caching | Swatantra KumarSwatantra Kumar
 
(DAT407) Amazon ElastiCache: Deep Dive
(DAT407) Amazon ElastiCache: Deep Dive(DAT407) Amazon ElastiCache: Deep Dive
(DAT407) Amazon ElastiCache: Deep DiveAmazon Web Services
 
Tuning Your SharePoint Environment
Tuning Your SharePoint EnvironmentTuning Your SharePoint Environment
Tuning Your SharePoint Environmentvmaximiuk
 
Cloud computing 3702
Cloud computing 3702Cloud computing 3702
Cloud computing 3702Jess Coburn
 
Nginx Scalable Stack
Nginx Scalable StackNginx Scalable Stack
Nginx Scalable StackBruno Paiuca
 
Building low latency java applications with ehcache
Building low latency java applications with ehcacheBuilding low latency java applications with ehcache
Building low latency java applications with ehcacheChris Westin
 
Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011Wim Godden
 
(ATS4-PLAT08) Server Pool Management
(ATS4-PLAT08) Server Pool Management(ATS4-PLAT08) Server Pool Management
(ATS4-PLAT08) Server Pool ManagementBIOVIA
 
More Cache for Less Cash (DevLink 2014)
More Cache for Less Cash (DevLink 2014)More Cache for Less Cash (DevLink 2014)
More Cache for Less Cash (DevLink 2014)Michael Collier
 
Adm02. IBM Connections Adminblast
Adm02. IBM Connections AdminblastAdm02. IBM Connections Adminblast
Adm02. IBM Connections Adminblastpanagenda
 
Improving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetImproving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetAchieve Internet
 
Improving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetImproving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetAchieve Internet
 

Similaire à Mage Titans 2015 (20)

Anthony Somerset - Site Speed = Success!
Anthony Somerset - Site Speed = Success!Anthony Somerset - Site Speed = Success!
Anthony Somerset - Site Speed = Success!
 
Configuring Apache Servers for Better Web Perormance
Configuring Apache Servers for Better Web PerormanceConfiguring Apache Servers for Better Web Perormance
Configuring Apache Servers for Better Web Perormance
 
Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it Fast
 
Performance Optimization using Caching | Swatantra Kumar
Performance Optimization using Caching | Swatantra KumarPerformance Optimization using Caching | Swatantra Kumar
Performance Optimization using Caching | Swatantra Kumar
 
Caching
CachingCaching
Caching
 
(DAT407) Amazon ElastiCache: Deep Dive
(DAT407) Amazon ElastiCache: Deep Dive(DAT407) Amazon ElastiCache: Deep Dive
(DAT407) Amazon ElastiCache: Deep Dive
 
60 Admin Tips
60 Admin Tips60 Admin Tips
60 Admin Tips
 
Tuning Your SharePoint Environment
Tuning Your SharePoint EnvironmentTuning Your SharePoint Environment
Tuning Your SharePoint Environment
 
Cloud computing 3702
Cloud computing 3702Cloud computing 3702
Cloud computing 3702
 
Nginx Scalable Stack
Nginx Scalable StackNginx Scalable Stack
Nginx Scalable Stack
 
Building low latency java applications with ehcache
Building low latency java applications with ehcacheBuilding low latency java applications with ehcache
Building low latency java applications with ehcache
 
Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011
 
(ATS4-PLAT08) Server Pool Management
(ATS4-PLAT08) Server Pool Management(ATS4-PLAT08) Server Pool Management
(ATS4-PLAT08) Server Pool Management
 
Performance out
Performance outPerformance out
Performance out
 
More Cache for Less Cash (DevLink 2014)
More Cache for Less Cash (DevLink 2014)More Cache for Less Cash (DevLink 2014)
More Cache for Less Cash (DevLink 2014)
 
Adm02. IBM Connections Adminblast
Adm02. IBM Connections AdminblastAdm02. IBM Connections Adminblast
Adm02. IBM Connections Adminblast
 
Mini-Training: To cache or not to cache
Mini-Training: To cache or not to cacheMini-Training: To cache or not to cache
Mini-Training: To cache or not to cache
 
Top ten-list
Top ten-listTop ten-list
Top ten-list
 
Improving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetImproving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve Internet
 
Improving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetImproving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve Internet
 

Mage Titans 2015

  • 1. PAUL PARTINGTON Magento Developer at CTI Digital @paul_partington
  • 2. What are We Talking About? • Caching approaches • Look at an issue with the configuration cache that we found • How we fixed it
  • 3. Web Server 1 Web Server 2 Magento Block Layout Configuration Collections EAV API Full Page Cache Database APC Cache Query Cache Varnish
  • 4. Cache Storage • File • Database • Redis or Memcached
  • 5. The Configuration Cache • Combines the XML files in the system • Adds in the system configuration • Every time you add a new module the size increases
  • 6. • Every time you add a new website you increase the size of the configuration XML • Adds around 125KB on Magento EE 1.14.2.0 Multisite
  • 7. I think I see where you’re going with this • Multiple Websites (9) • High Traffic • Caches are going to get cleared • The configuration cache was cleared and took the site down
  • 8. Why’s this happening? • While the configuration cache is being created, every request causes the cache generation process to start • CPU load increased as the request uses more memory and takes longer to finish
  • 9. app/code/core/Mage/Model/App.php protected function _initModules() { if (!$this->_config->loadModulesCache() { $this->_config->loadModules(); ... } }
  • 10. 0 0.25 0.5 0.75 1 1.25 -20 -10 0 10 20 30 CPULoad Time CPU Load
  • 11. Cache Policy • Caches should only be cleared at non-peak times • Clients should be aware of the effects that clearing a cache can have
  • 12. What did we do? • Created a module • https://github.com/ctidigital/Configuration-Cache- Lock • Similar fix - https://github.com/madepeople/Made_Cache
  • 13. How does the module work? • Creates a cache lock in a Redis database • Keep the cache creation to a single request
  • 14. <global> ... <cache_lock> <enable>1</enable> <!-- If cache locking is enabled or not --> <server>127.0.0.1</server> <!-- The Redis database IP --> <port>6379</port> <!-- The Redis port --> <database>0</database> <!-- The Redis Database to use --> <password></password> <!-- The password of the Redis server --> <timeout>2.5</timeout> <!-- The Redis timeout --> <key>cache_lock</key> <!-- The name of lock in the Redis Database --> <max_attempts>10</max_attempts> <!-- The maximum amount of times to retry the connection. Defaults to 10. --> <retry_time>10000000</retry_time> <!-- The amount of microseconds to wait between checking the cache has generated. Defaults to 10000000 --> </cache_lock> ... Edit your local.xml
  • 15. • Creates a local override of Mage_Core_Model_App (sorry!) • New method called _initModulesWithLocking()
  • 16. protected function _initModulesWithLocking () { if ($this->_config->loadModulesCache()) { return $this; } ... // If the cache is currently being regenerated if ($ctiCache->getIsCacheLocked()) { $cacheLock = true; } // If the cache needs to be created if ($cacheLock === false) { // Create a new cache lock $ctiCache->acquireCacheLock(); $this->_config->loadModules(); ... // Release the cache lock $ctiCache->releaseCacheLock(); return $this; } ... while ($cacheLock === true && $attempts < $maxAttempts) { $attempts++; usleep($ctiCache->getRetryTime()); if ($this->_config->loadModulesCache()) { return $this; } }
  • 17. 0 0.25 0.5 0.75 1 1.25 -20 -10 0 10 20 30 CPULoad Time Without the Cache Lock With the Cache Lock
  • 18. An Unexpected Extra • Prevents module updates from running more than once • Poorly written update scripts may display an error if ran more than once

Notes de l'éditeur

  1. This is a talk about the Magento cache and a particular issue we had.
  2. Want to discuss caching in Magento An issue we found with one of the caches and a bit of look into why it happened How we fixed the issue
  3. The purpose of a cache is to keep the output of a repetitive action so that it can be used later Magento’s main caches are Block, Layout, Configuration Only block cache helps the front end code Enterprise or CE - Full Page Caches APC Cache - caches the output of the compiled byte code in PHP MySQL cache - Caches the output of a query so that it can be retrieved later Varnish - caches entire pages and ‘holepunches’ out the unique elements Varnish potentially won’t hit PHP so is very fast Need knowledge of VCL for total control Main aim is to stop the requests hitting Magento
  4. File - slow to write to/read from If you get multiple web servers you need to have centralised cache Database is not a good idea as it means more connections Keeping cache in Redis or Memcached - necessary for multiple web servers but useful if only on one web server While caching isn’t a solution to poor performance it’s necessary to have caching in there to make the site usable
  5. The configuration cache combines all the XML files in the system and adds in the system configuration values Enterprise is around 729KB The size increases every time you add a new module Example Sage Pay adds in 17KB per website
  6. One of Magento’s really great features is being able to have multiple websites on one installation Allows several sites to share a single code base Adding a new website copies the entire system configuration values and stores it for that website Every new website on out of the box Enterprise adds around 125KB If you have a larger set of modules this can quite quickly grow
  7. We have a client who has 9 websites on a Magento Enterprise installation Around 70 additional modules - mostly custom but also some third party Site had been live for a month or two and was running fine Seasonal and had just launched a new catalogue so there’s a higher amount of traffic than usual Caches are going to cleared whether you like it or not Client phoned us up to say they had cleared the cache and now the site’s down Took a bit of time to narrow down the issue - considered it was likely FPC Turned out the configuration cache was what caused the issue This client’s configuration file was 3.5MB The combination of high traffic and a large config file was to blame As a related note, we have a client that has 180 websites. The config file size 47MB - didn’t think the talk would be too relevant if the result was “don’t put 180 websites on Magento”
  8. When the cache is cleared each new request triggers off the cache creation Large amounts of traffic and multiple websites with a large configuration size means that the CPU load increase The server can run low on memory and start using SWAP CPU load can be compared to traffic lanes - once the lanes are full there start to be delays The overhead of the server means you’re looking at about 0.7 for your CPU load on each core
  9. Loaded by app/Mage.php()
  10. CPU load down the left - top value is 1 Red line is when the cache was cleared Ran using a Siege test
  11. Caches should only be cleared at non-peak times Only the essential caches should be cleared This helped the client and should be in place any way
  12. We Googled but didn’t find much, so we created a module https://github.com/madepeople/Made_Cache - couldn’t use as it meant using a whole new caching set up so we had to make our own
  13. Uses a Redis database to create a cache lock While the lock is in place each request waits until the cache has finished generating The module allows a configurable amount of retry attempts and the amount of time between the retries can be configured After every retry it rechecks to see if the cache is loaded If it has been loaded the request continues as normal This means less strain on the server Requires the Colin Mollenhour Redis module
  14. Overrides the App model Overrides the original initModules() method to check if the cache lock is enabled
  15. If the cache doesn’t need recreating then it returns straight away If it gets past here then we need to create the cache Checks if there is a cache lock If no lock is in place then the lock is created and the cache generation started Any other requests will see the lock is in place and will wait until it’s ready If it runs out of attempts it shows the 503 maintenance page
  16. When deploying changes with updates to the database, many requests may cause the update to run at the same time and this can cause conflicts There are several strategies to get around this such as applying updates on one set of servers and switching the site over and putting the site into maintenance mode Due to when the updates are ran, the cache lock prevents multiple requests from running the same update