Ori.livneh has uploaded a new change for review. https://gerrit.wikimedia.org/r/226266
Change subject: Add an additional cache layer for module revision text ...................................................................... Add an additional cache layer for module revision text On Wikimedia's memcached cluster, the most frequently retrieved keys tend to be {$wgDBname}:revisiontext:textid:*, representing the revision text of Lua modules. Since these keys are so hot, it makes sense to have an additional, lower-latency caching layer. This patch makes Scribunto use APC for caching module contents. If APC is not available, Scribunto will use a hash BagOStuff instead, which won't improve performance but won't cost much either. Note that we can't cache module objects directly, because they reference a LuaSandbox instance which gets swept on request end. Change-Id: I53dd1ecbb74b1f60e4173e169351aeefed7ddca8 --- M common/Base.php 1 file changed, 16 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Scribunto refs/changes/66/226266/1 diff --git a/common/Base.php b/common/Base.php index 9fa6907..c18d149 100644 --- a/common/Base.php +++ b/common/Base.php @@ -80,7 +80,9 @@ /** * @param $options array Associative array of options: - * - parser: A Parser object + * - parser: A Parser object + * - title: A Title object + * - cache: A BagOStuff object */ public function __construct( array $options ) { $this->options = $options; @@ -89,6 +91,11 @@ } if ( isset( $options['title'] ) ) { $this->title = $options['title']; + } + if ( isset( $options['cache'] ) ) { + $this->cache = $options['cache']; + } else { + $this->cache = ObjectCache::newAccelerator( array(), 'hash' ); } } @@ -101,6 +108,7 @@ $this->parser = null; $this->title = null; $this->modules = null; + $this->cache = null; } /** @@ -150,7 +158,13 @@ function fetchModuleFromParser( Title $title ) { $key = $title->getPrefixedDBkey(); if ( !array_key_exists( $key, $this->modules ) ) { - list( $text, $finalTitle ) = $this->parser->fetchTemplateAndTitle( $title ); + $cacheKey = wfMemcKey( __CLASS__, $key ); + $templateAndTitle = $this->cache->get( $cacheKey ); + if ( $templateAndTitle === false ) { + $templateAndTitle = $this->parser->fetchTemplateAndTitle( $title ); + $this->cache->set( $cacheKey , $templateAndTitle, 60 ); + } + list( $text, $finalTitle ) = $templateAndTitle; if ( $text === false ) { $this->modules[$key] = null; return null; -- To view, visit https://gerrit.wikimedia.org/r/226266 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I53dd1ecbb74b1f60e4173e169351aeefed7ddca8 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Scribunto Gerrit-Branch: wmf/1.26wmf14 Gerrit-Owner: Ori.livneh <o...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits