Giter VIP home page Giter VIP logo

mpchadwick_pagecachehitrate's Introduction

Mpchadwick_PageCacheHitRate

Hit rate tracking for Magento Page Cache.

Configuration

All configuration is done through an XML file in the /app/etc directory. This is because module configuration is not loaded in the case of a full hit. mpchadwick_pagecachehitrate.xml.template is included with example settings. A few notes...

  • Mpchadwick_PageCacheHitRate_Model_Processor is added as a <request_processor>.
    • Note: request_processors are loaded alphabetically based on the file name in /app/etc. It is important that Mpchadwick_PageCacheHitRate_Model_Processor be the final request_processor to know for sure if this is a full hit. By default the Enterprise_PageCache_Model_Processor is defined in enterprise.xml and will be loaded first, however if your are using something else to process the result of Enterprise_PageCache_Model_Processor you may need to change the file name in /app/etc.
  • <tracker>s can be configured in your <full_page_cache> configuration under the <mpchadwick_pagecachehitrate> node. If no trackers are specified, hit rate will not be tracked.
  • There is a <track_container_misses> setting which can be used to track individual container misses in the case of partial page hits.
  • A <metadata_source> can be configured under the <full_page_cache> configuration in the case where Enterprise_PageCache_Model_Processor is not the correct class to provide metadata. This can happen if the <ee> request processor is changed, notably with Elastera_EnterprisePageCache.

Trackers

The following trackers are available...

  • Mpchadwick_PageCacheHitRate_Model_Tracker_File A log file will be used for for tracking hit rate. A new file will be created each day.
  • Mpchadwick_PageCacheHitRate_Model_Tracker_NewRelic New Relic custom events will be used for tracking hit rate.
  • Mpchadwick_PageCacheHitRate_Model_Tracker_Redis Hit rate will be tracked in Redis. The intention is to scrape this data periodically and store it in a tool such as InfluxDb or Prometheus.

You can easily create your own tracker if you'd prefer a different means of tracking. Simply implement the Mpchadwick_PageCacheHitRate_Model_TrackerInterface interface and configure your class as the <tracker> in an xml file in /app/etc.

Dimensions

In addition to a full hit and a full miss, Enterprise_PageCache can also have partial hits. This happens if a cached response is found, but it has containers that need additional processing. The type metric is thus tracked as either a hit, a miss, or a partial.

In addition to type, the following dimensions are tracked...

  • route,
  • url
  • ip
  • hostname
  • customerGroup

For example, you may want to see your cache hit rate for a single route such as /catalog/product/view or know your cache hit rate for a single IP address if your are seeing crawling / bot activity creating performance impact on your site.

Here are some example entries using the Mpchadwick_PageCacheHitRate_Model_Tracker_File tracker...

2016-06-02T02:28:04+00:00 DEBUG (7): {"url":"http:\/\/magento-1_14_1_0.dev\/men\/shirts.html","ip":"172.16.9.1","type":"miss","route":"catalog\/category\/view"}
2016-06-02T02:28:09+00:00 DEBUG (7): {"url":"http:\/\/magento-1_14_1_0.dev\/men\/shirts.html","ip":"172.16.9.1","type":"partial","route":"catalog\/category\/view"}
2016-06-02T02:28:11+00:00 DEBUG (7): {"url":"http:\/\/magento-1_14_1_0.dev\/men\/shirts.html","ip":"172.16.9.1","type":"hit","route":"catalog\/category\/view"}

Container misses will be recorded to a separate file (if enabled). The entries will look like this...

2016-06-02T03:18:14+00:00 DEBUG (7): {"url":"http:\/\/magento-1_14_1_0.dev\/women\/women-new-arrivals.html","ip":"172.16.9.1","route":"catalog\/category\/view","container":"Enterprise_PageCache_Model_Container_Catalognavigation"}

Also note that you can configure multiple trackers. You may want to store data in both New Relic and Redis, for example.

Cardinality

By default, highly cardinal dimensions are tracked such as IP address and URL. For the Mpchadwick_PageCacheHitRate_Model_Tracker_File and Mpchadwick_PageCacheHitRate_Model_Tracker_NewRelic trackers this is probably fine. However if you are using Mpchadwick_PageCacheHitRate_Model_Tracker_Redis and sending the data to InfluxDb or Prometheus you'll probably want to decrease the cardinality of the data.

You can specify dimensions to strip on a per tracker-basis. E.g...

<config>
    <global>
        <full_page_cache>
            <mpchadwick_pagecachehitrate>
                <trackers>
                    <redis>
                        <class>Mpchadwick_PageCacheHitRate_Model_Tracker_Redis</class>
                        <server>127.0.0.1</server>
                        <port>6379</port>
                        <database>1</database>
                        <strip>
                            <ip />
                            <url />
                        </strip>
                    </redis>
                </trackers>
            </mpchadwick_pagecachehitrate>
        </full_page_cache>
    </global>
</config>

mpchadwick_pagecachehitrate's People

Contributors

lenlorijn avatar mpchadwick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mpchadwick_pagecachehitrate's Issues

Fix partials being represented as misses (in some cases)

We can still have a partial hit even without any containers that need additional processing. This can happen here

$sessionInfo = Enterprise_PageCache_Model_Cache::getCacheInstance()->load($this->getSessionInfoCacheId());

if ($sessionInfo) {
    // Handle session info 
} else {
    // This will be a partial. There don't need to be containers for this to happen
    $isProcessed = false;
}

Probably a better approach is to check if the request is being handled by pagecache/request/process.

Implement approach for recognizing bots

UA string itself could be tracked as a dimension OR it could be run through a bot regex which gives a yes / no answer (which would decrease cardinality).

Show actual URL for misses

Per this comment url is showing the URL after having been passed through Magento's rewrite logic for misses. Would be better to try to keep consistent. Here's an example...

2016-06-02T02:07:09+00:00 DEBUG (7): {"url":"http:\/\/magento-1_14_1_0.dev\/catalog\/category\/view\/id\/40","ip":"172.16.9.1","type":"miss","route":"catalog\/category\/view"}
2016-06-02T02:07:12+00:00 DEBUG (7): {"url":"http:\/\/magento-1_14_1_0.dev\/men\/blazers.html","ip":"172.16.9.1","type":"partial","route":"catalog\/category\/view"}
2016-06-02T02:07:14+00:00 DEBUG (7): {"url":"http:\/\/magento-1_14_1_0.dev\/men\/blazers.html","ip":"172.16.9.1","type":"hit","route":"catalog\/category\/view"}

Fix PHP notices

Notice: Undefined variable: alias in Mpchadwick_PageCacheHitRate/app/code/community/Mpchadwick/PageCacheHitRate/Model/Tracker/Abstract.php on line 20

Notice: Undefined variable: alias in Mpchadwick_PageCacheHitRate/app/code/community/Mpchadwick/PageCacheHitRate/Model/Tracker/Abstract.php on line 27

Notice: Undefined index: CUSTOMER_INFO  in app/code/community/Mpchadwick/PageCacheHitRate/Model/Tracker/ParamProvider.php on line 53

Error once the page has been cached.

Hi,

On enabling the module, I am getting error has below. Magento version 1.12.0.2 and we have Redis for both the default cache ( default array) and the full page cache. Appreciate your help in the regard.

a:4:{i:0;s:46:"Mage registry key "_helper/log" already exists";i:1;s:1203:"#0 /var/www/web/app/Mage.php(222): Mage::throwException('Mage registry k...')
#1 /var/www//web/app/Mage.php(546): Mage::register('_helper/log', Object(Mage_Log_Helper_Data))
#2 /var/www/web/app/Mage.php(810): Mage::helper('log')
#3 /var/www/web/app/code/community/Mpchadwick/PageCacheHitRate/Model/Tracker/File.php(12): Mage::log('{"url":"http:\/...', NULL, 'mpchadwick_page...', true)
#4 /var/www/web/app/code/community/Mpchadwick/PageCacheHitRate/Model/Tracker/Abstract.php(27): Mpchadwick_PageCacheHitRate_Model_Tracker_File->_track('RequestResponse', Array, 'file')
#5 /var/www/web/app/code/community/Mpchadwick/PageCacheHitRate/Model/Processor.php(43): Mpchadwick_PageCacheHitRate_Model_Tracker_Abstract->track('RequestResponse', Array, 'file')
#6 /var/www/web/app/code/community/Mage/Core/Model/Cache.php(626): Mpchadwick_PageCacheHitRate_Model_Processor->extractContent('...')
#7 /var/www/web/app/code/core/Mage/Core/Model/App.php(340): Mage_Core_Model_Cache->processRequest()
#8 /var/www/web/app/Mage.php(683): Mage_Core_Model_App->run(Array)

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.