Status: | effective |
Progress: | 100% |
Version: | 2.5.0+ |
Help:Query cache
Table of Contents | |
---|---|
Semantic MediaWiki 2.5.0Released on 14 March 2017 and compatible with MW 1.23.0 - 1.29.x. adds an experimental feature to support a simple query cache1 with the objective to minimize the computational effort for queries that share the same query signature. A query signature is a fingerprint that identifies each query on characteristics that influences (e.g. condition, limit, offset, and sort/order) the result set of a query. This experimental feature is disabled by default.
Usage[edit]
The simple query cache is used for:
- Queries that have the same signature will be redirected to the cache instead of seeking an active "QueryEngine" connection and hereby reduce DB connections and computation effort
- Only the subject list is being cached as result of the query answering, leaving individual "PrintRequest's" to the distinctive printer and avoids conflict with existing or future "ResultPrinter" when generating the output representation
When the query result cache is enabled, current queries will be reassigned a new query ID 23 to increase the pool of queries that share potentially the same signature and hereby broaden the range of a cache reuse and minimize cache fragmentation.
The eviction4 of a cache is normally triggered by:
- A time constraint (see configuration parameter
$smwgQueryResultCacheLifetime
Sets the cache lifetime of embedded queries and their results fetched from the query engine}) - A manually intervention (see configuration parameter
$smwgQueryResultCacheRefreshOnPurge
Sets whether it is possible to manually refresh the query cache by doing a "purge" action), or - An embedded query update (see configuration parameter
$smwgEnabledQueryDependencyLinksStore
Sets whether tracking and storing of dependencies of embedded queries may be used) if enabled with any monitored change to a dependency chain to trigger an automatic purge of related queries
A recommended cache provider is redis
5 to account for an optimal response time, storage capacity, and independence from the DB master. The cache statistics with its relative small size will be stored using CACHE_DB
to improve durability of the collected data and make it independent of the query cache operations.
Operational relevance and statistics[edit]
To make a decision about whether the query result cache bears some operational relevance (meaning the benefits outweigh the cost of keeping an additional cache instance, or the median response time proves some generalisable advantage) with cache statistics being kept for the duration of the query cache lifetime, allowing it to gather some data about performance and use.
- Example
{
"misses": 545,
"deletes": 56,
"hits": {
"nonEmbedded": 636,
"embedded": 39
},
"medianRetrievalResponseTime": {
"uncached": 0.030940875770042,
"cached": 0.0069486399265745
},
"noCache": {
"byLimit": 30
},
"ratio": {
"hit": 0.5533,
"miss": 0.4467
},
"meta": {
"version": "0.2",
"cacheLifetime": {
"embedded": 86400,
"nonEmbedded": 600
},
"collectionDate": {
"start": "2016-11-30 14:17:21",
"update": "2016-12-07 10:13:54"
}
}
}
Configuration parameters[edit]
- Configuration parameter
$smwgQueryResultCacheType
Sets whether the query result cache may be used − Allows to enable the feature - Configuration parameter
$smwgQueryResultCacheLifetime
Sets the cache lifetime of embedded queries and their results fetched from the query engine − Allows to set the lifetime of embedded queries and their results - Configuration parameter
$smwgQueryResultNonEmbeddedCacheLifetime
Sets the cache lifetime of non-embedded queries and their results fetched from the query engine − Allows to set the lifetime of non-embedded queries and their results - Configuration parameter
$smwgQueryResultCacheRefreshOnPurge
Sets whether it is possible to manually refresh the query cache by doing a "purge" action − Allows to control the option to manually refresh embedded queries and their results
See also[edit]
- Help page on cache statistics
- Help pages on query management and query dependency
- Help page on concept caching
- Help page on speeding up Semantic MediaWiki
- Help page on caching
- Help page on embedded query updates
- Help page on query performance
- Help page on page loading time
- Help page on the parser cache
References
- ^ Semantic MediaWiki: GitHub pull request gh:smw:1251
- ^ Semantic MediaWiki: GitHub pull request gh:smw:2099
- ^ Semantic MediaWiki: GitHub pull request gh:smw:2176
- ^ Chapter 4. Cache Eviction being described as " ... the process by which old, relatively unused, or excessively voluminous data can be dropped from the cache ..."
- ^ Why Redis beats Memcached for caching "... Memcached and Redis serve as in-memory, key-value data stores ... Redis gives you much greater flexibility regarding the objects you can cache. While Memcached limits key names to 250 bytes and works with plain strings only, Redis allows key names and values to be as large as 512MB ..."