Krinkle has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/290825

Change subject: Add in-process caching to ChoiceDataProvider
......................................................................

Add in-process caching to ChoiceDataProvider

ChoiceDataProvider::getChoices accounts for about 7% of load.php execution time.
(Based on Wikimedia-wide sampling from Xenon over 24 hours).

Three different callers ask to query the same data from the database.

Reverse flame-graph:

https://performance.wikimedia.org/xenon/svgs/daily/2016-05-24.load.reversed.svgz

* ChoiceDataProvider::getChoices()
  - CNChoiceDataResourceLoaderModule()::getFromDb()
    - CNChoiceDataResourceLoaderModule::getChoices()
      - CNChoiceDataResourceLoaderModule::getDependencies()
        - ResourceLoader/StartupModule
      - CNChoiceDataResourceLoaderModule::getModifiedHash()
        - ResourceLoader/Module::getVersionHash()
          - ResourceLoader/StartupModule
          - ResourceLoader::makeModuleResponse()
      - CNChoiceDataResourceLoaderModule::getScript()
          - ResourceLoader::makeModuleResponse()

The web response for modules=startup computes it twice (once for dependencies,
and again for the version hash).

The web response for modules=ext.centralNotice.choiceData also computes it twice
(once for the script body, and again for the version header).

Change-Id: Iff0ea19248c9458dd109f05d620616516ee3ada6
---
M includes/ChoiceDataProvider.php
1 file changed, 16 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralNotice 
refs/changes/25/290825/1

diff --git a/includes/ChoiceDataProvider.php b/includes/ChoiceDataProvider.php
index b68a87f..809135d 100644
--- a/includes/ChoiceDataProvider.php
+++ b/includes/ChoiceDataProvider.php
@@ -5,6 +5,8 @@
  * given project and language combination.
  */
 class ChoiceDataProvider {
+       /** @var HashBagOStuff */
+       private static $cache;
 
        protected $project;
        protected $language;
@@ -14,7 +16,6 @@
         * @param string $language The language to get choices for
         */
        public function __construct( $project, $language ) {
-
                $this->project = $project;
                $this->language = $language;
        }
@@ -29,6 +30,20 @@
         *   are provided.
         */
        public function getChoices() {
+               if ( !self::$cache ) {
+                       self::$cache = new HashBagOStuff( [ 'maxKeys' => 10 ] );
+               }
+               $cache = self::$cache;
+               return $cache->getWithSetCallback(
+                       $cache->makeKey( $this->project, $this->language ),
+                       $cache::TTL_PROC_SHORT,
+                       function () {
+                               return $this->fetchChoices();
+                       }
+               );
+       }
+
+       private function fetchChoices() {
                // For speed, we'll do our own queries instead of using methods 
in
                // Campaign and Banner.
 

-- 
To view, visit https://gerrit.wikimedia.org/r/290825
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iff0ea19248c9458dd109f05d620616516ee3ada6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to