Ori.livneh has uploaded a new change for review. https://gerrit.wikimedia.org/r/226260
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, 15 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Scribunto refs/changes/60/226260/1 diff --git a/common/Base.php b/common/Base.php index 9fa6907..a2ab71f 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,12 @@ function fetchModuleFromParser( Title $title ) { $key = $title->getPrefixedDBkey(); if ( !array_key_exists( $key, $this->modules ) ) { - list( $text, $finalTitle ) = $this->parser->fetchTemplateAndTitle( $title ); + $templateAndTitle = $this->cache->get( __CLASS__ . ':' . $key ); + if ( $templateAndTitle === false ) { + $templateAndTitle = $this->parser->fetchTemplateAndTitle( $title ); + $this->cache->set( __CLASS__ . ':' . $key, $templateAndTitle, 60 ); + } + list( $text, $finalTitle ) = $templateAndTitle; if ( $text === false ) { $this->modules[$key] = null; return null; -- To view, visit https://gerrit.wikimedia.org/r/226260 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: master Gerrit-Owner: Ori.livneh <o...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits