Skip to main content

Query Cache Settings

By default, Kylin enables query cache in each process to improve query performance.

Note: In order to ensure data consistency, query cache is not available in pushdown.

Use Default Cache

Kylin enables query cache by default at each node/process level. The configuration details are described below. You can change them in $KYLIN_HOME/conf/kylin.properties under Kylin installation directory.

Caution: Must restart for any configurations to take effect.

PropertiesDescriptionDefaultOptions
kylin.query.cache-enabledWhether to enable query cache. When this property is enabled, the following properties take effect.truefalse

Query Cache Criteria

Kylin doesn't cache the query result of all SQL queries by default (because the memory resource might be limited). It only caches slow queries and the result size is appropriate. The criterion are configured by the following parameters. The query that satisfies any one of the No.1, No.2, No.3 configuration and also satisfies No.4 configuration will be cached.

NoPropertiesDescriptionDefaultDefault unit
1kylin.query.cache-threshold-durationQueries whose duration is above this value2000millisecond
2kylin.query.cache-threshold-scan-countQueries whose scan row count is above this value10240row
3kylin.query.cache-threshold-scan-bytesQueries whose scan bytes is above this value1048576byte
4kylin.query.large-query-thresholdQueries whose result set size is below this value1000000cell

Ehcache Cache Configuration

By default, Kylin uses Ehcache as the query cache. You can configure Ehcache to control the query cache size and policy. You can replace the default query cache configuration by modifying the following configuration item. For more Ehcache configuration items, please refer to the official website ehcache documentation.

PropertiesDescriptionDefault
kylin.cache.configThe path to ehcache.xml. To replace the default query cache configuration file, you can create a new file xml, for exemple ekcache2.xml, in the directory ${KYLIN_HOME}/conf/, and modify the value of this configuration item: file://${KYLIN_HOME}/conf/ehcache2.xmlclasspath:ehcache.xml

Redis Cache Configuration

The default query cache cannot be shared among different nodes or processes because it is process level. Because of this, when subsequent and same queries are routed to different Kylin nodes, the cache of the first query result cannot be used in cluster deployment mode. Therefore, you can configure Redis cluster as distributed cache, which can be shared across all Kylin nodes. The detail configurations are described as below: (Redis 5.0 or 5.0.5 is recommended.)

PropertiesDescriptionDefaultOptions
kylin.cache.redis.enabledWhether to enable query cache by using Redis cluster.falsetrue
kylin.cache.redis.cluster-enabledWhether to enable Redis cluster mode.falsetrue
kylin.cache.redis.hostsRedis host. If you need to connect to a Redis cluster, please use comma to split the hosts, such as, kylin.cache.redis.hosts=localhost:6379,localhost:6380localhost:6379
kylin.cache.redis.expire-time-unitTime unit for cache period. EX means seconds and PX means milliseconds.EXPX
kylin.cache.redis.expire-timeValid cache period.86400
kylin.cache.redis.reconnection.enabledWhether to enable redis reconnection when cache degrades to ehcachetruefalse
kylin.cache.redis.reconnection.intervalAutomatic reconnection interval, in minutes60
kylin.cache.redis.passwordRedis password

Limitation

Due to metadata inconsistency between Query nodes and All/Job nodes, the redis cache swith kylin.cache.redis.enabled=true should be configured along with kylin.server.store-type=jdbc.

Caution: Redis passwords can be encrypted, please refer to: Use MySQL as Metastore