You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2021/02/04 00:23:25 UTC
[GitHub] [druid] techdocsmith opened a new pull request #10848: refactor query caching
techdocsmith opened a new pull request #10848:
URL: https://github.com/apache/druid/pull/10848
Refactor Query Caching docs.
* Separates caching concepts and strategy from instructions to enable the cache
* Includes some more context and examples
### Description
Clarify caching concepts, strategy, and configuration
This PR has:
- [x] been self-reviewed.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] techdocsmith commented on a change in pull request #10848: refactor query caching docs
Posted by GitBox <gi...@apache.org>.
techdocsmith commented on a change in pull request #10848:
URL: https://github.com/apache/druid/pull/10848#discussion_r588591618
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +22,75 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently accessed data. This topic defines the different types of caching for Druid. It describes the default caching behavior and provides guidance and examples to help you hone your caching strategy.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+If you're unfamiliar with Druid architecture, review the following topics before proceeding with caching:
+- [Druid Design](../design/architecture.md)
+- [Segments](../design/segments.md)
+- [Query execution](./query-execution)
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+For instructions to configure caching see [Using query caching](./using-caching.md).
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports segment caching which stores _partial results_ of a query for a specific segment, and whole-query caching which stores all results for a query. To avoid returning stale results, Druid invalidates the cache the moment any underlying data changes for both types of cache.
-## Using and populating cache
+Druid can store cache data the local JVM heap or in an external distributed key/value store. See [Cache configuration](../configuration/index.md#cache-configuration) for information on how to configure cache storage.
-All caches have a pair of parameters that control the behavior of how individual queries interact with the cache, a 'use' cache parameter, and a 'populate' cache parameter. These settings must be enabled at the service level via [runtime properties](../configuration/index.md) to utilize cache, but can be controlled on a per query basis by setting them on the [query context](../querying/query-context.md). The 'use' parameter obviously controls if a query will utilize cached results. The 'populate' parameter controls if a query will update cached results. These are separate parameters to allow queries on uncommon data to utilize cached results without polluting the cache with results that are unlikely to be re-used by other queries, for example large reports or very old data.
+### Segment caching
-## Query caching on Brokers
+The primary form of caching in Druid is the **segment cache**. The segment cache stores query results on a per-segment basis. It is enabled on Historical services by default.
-Brokers support both segment-level and whole-query result level caching. Segment-level caching is controlled by the
-parameters `useCache` and `populateCache`. Whole-query result level caching is controlled by the parameters
-`useResultLevelCache` and `populateResultLevelCache` and [runtime properties](../configuration/index.md)
-`druid.broker.cache.*`.
+When your queries include data from segments that are mutable and undergoing real-time ingestion, use a segment cache. In this case Druid caches query results for immutable historical segments when possible. It re-computes results for the real-time segments at query time.
-Enabling segment-level caching on the Broker can yield faster results than if query caches were enabled on Historicals for small
-clusters. This is the recommended setup for smaller production clusters (< 5 servers). Populating segment-level caches on
-the Broker is _not_ recommended for large production clusters, since when the property `druid.broker.cache.populateCache` is
-set to `true` (and query context parameter `populateCache` is _not_ set to `false`), results from Historicals are returned
-on a per segment basis, and Historicals will not be able to do any local result merging. This impairs the ability of the
-Druid cluster to scale well.
+For example, you have queries that frequently include incoming data from a Kafka or Kinesis stream alongside unchanging segments. Whole-query caching is not helpful in this scenario because the new data from real-time ingestion continually invalidates the cache. Segment caching lets Druid cache results from older immutable segments and merge them with updated data.
-## Query caching on Historicals
+### Whole-query caching
-Historicals only support segment-level caching. Segment-level caching is controlled by the query context
-parameters `useCache` and `populateCache` and [runtime properties](../configuration/index.md)
-`druid.historical.cache.*`.
+If real-time ingestion invalidating the cache is not an issue for your queries, you can use **whole-query caching** on the Broker to increase query efficiency. Segment caching is less efficient in this case because it requires Druid to merge the per-segment results for each query, even when the results are cached. For instance, whole-query caching is a good option when you have queries that include data from a batch ingestion task that runs every few hours or once a day.
-Larger production clusters should enable segment-level cache population on Historicals only (not on Brokers) to avoid
-having to use Brokers to merge all query results. Enabling cache population on the Historicals instead of the Brokers
-enables the Historicals to do their own local result merging and puts less strain on the Brokers.
+## Where to enable caching
-## Query caching on Ingestion Tasks
+**Segment cache** is available as follows:
+- On Brokers for small production clusters with less than five servers.
Review comment:
Great suggestion. especially since this moves the default to the top of the list.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] techdocsmith commented on a change in pull request #10848: refactor query caching docs
Posted by GitBox <gi...@apache.org>.
techdocsmith commented on a change in pull request #10848:
URL: https://github.com/apache/druid/pull/10848#discussion_r588589809
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +22,75 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently accessed data. This topic defines the different types of caching for Druid. It describes the default caching behavior and provides guidance and examples to help you hone your caching strategy.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+If you're unfamiliar with Druid architecture, review the following topics before proceeding with caching:
+- [Druid Design](../design/architecture.md)
+- [Segments](../design/segments.md)
+- [Query execution](./query-execution)
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+For instructions to configure caching see [Using query caching](./using-caching.md).
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports segment caching which stores _partial results_ of a query for a specific segment, and whole-query caching which stores all results for a query. To avoid returning stale results, Druid invalidates the cache the moment any underlying data changes for both types of cache.
-## Using and populating cache
+Druid can store cache data the local JVM heap or in an external distributed key/value store. See [Cache configuration](../configuration/index.md#cache-configuration) for information on how to configure cache storage.
-All caches have a pair of parameters that control the behavior of how individual queries interact with the cache, a 'use' cache parameter, and a 'populate' cache parameter. These settings must be enabled at the service level via [runtime properties](../configuration/index.md) to utilize cache, but can be controlled on a per query basis by setting them on the [query context](../querying/query-context.md). The 'use' parameter obviously controls if a query will utilize cached results. The 'populate' parameter controls if a query will update cached results. These are separate parameters to allow queries on uncommon data to utilize cached results without polluting the cache with results that are unlikely to be re-used by other queries, for example large reports or very old data.
+### Segment caching
-## Query caching on Brokers
+The primary form of caching in Druid is the **segment cache**. The segment cache stores query results on a per-segment basis. It is enabled on Historical services by default.
-Brokers support both segment-level and whole-query result level caching. Segment-level caching is controlled by the
-parameters `useCache` and `populateCache`. Whole-query result level caching is controlled by the parameters
-`useResultLevelCache` and `populateResultLevelCache` and [runtime properties](../configuration/index.md)
-`druid.broker.cache.*`.
+When your queries include data from segments that are mutable and undergoing real-time ingestion, use a segment cache. In this case Druid caches query results for immutable historical segments when possible. It re-computes results for the real-time segments at query time.
-Enabling segment-level caching on the Broker can yield faster results than if query caches were enabled on Historicals for small
-clusters. This is the recommended setup for smaller production clusters (< 5 servers). Populating segment-level caches on
-the Broker is _not_ recommended for large production clusters, since when the property `druid.broker.cache.populateCache` is
-set to `true` (and query context parameter `populateCache` is _not_ set to `false`), results from Historicals are returned
-on a per segment basis, and Historicals will not be able to do any local result merging. This impairs the ability of the
-Druid cluster to scale well.
+For example, you have queries that frequently include incoming data from a Kafka or Kinesis stream alongside unchanging segments. Whole-query caching is not helpful in this scenario because the new data from real-time ingestion continually invalidates the cache. Segment caching lets Druid cache results from older immutable segments and merge them with updated data.
Review comment:
I reversed the sentences to put the emphasis on Per-segment caching and how this is a negative example for whole query
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] techdocsmith commented on a change in pull request #10848: refactor query caching docs
Posted by GitBox <gi...@apache.org>.
techdocsmith commented on a change in pull request #10848:
URL: https://github.com/apache/druid/pull/10848#discussion_r589841039
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +23,87 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently accessed data. This topic defines the different types of caching for Druid. It describes the default caching behavior and provides guidance and examples to help you hone your caching strategy.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+If you're unfamiliar with Druid architecture, review the following topics before proceeding with caching:
+- [Druid Design](../design/architecture.md)
+- [Segments](../design/segments.md)
+- [Query execution](./query-execution)
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+For instructions to configure query caching see [Using query caching](./using-caching.md).
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports the following types of caches:
-## Using and populating cache
+- **Per-segment** caching which stores _partial results_ of a query for a specific segment. Per-segment caching is enabled on Historicals by default.
+- **Whole-query** caching which stores all results for a query.
-All caches have a pair of parameters that control the behavior of how individual queries interact with the cache, a 'use' cache parameter, and a 'populate' cache parameter. These settings must be enabled at the service level via [runtime properties](../configuration/index.md) to utilize cache, but can be controlled on a per query basis by setting them on the [query context](../querying/query-context.md). The 'use' parameter obviously controls if a query will utilize cached results. The 'populate' parameter controls if a query will update cached results. These are separate parameters to allow queries on uncommon data to utilize cached results without polluting the cache with results that are unlikely to be re-used by other queries, for example large reports or very old data.
+To avoid returning stale results, Druid invalidates the cache the moment any underlying data changes for both types of cache.
-## Query caching on Brokers
+Druid can store cache data the local JVM heap or in an external distributed key/value store. The default is a local cache based upon [Caffeine](https://github.com/ben-manes/caffeine). Maximum cache storage defaults to the minimum value of 1 GiB or the ten percent of the maximum runtime memory for the JVM with no cache expiration. See [Cache configuration](../configuration/index.md#cache-configuration) for information on how to configure cache storage.
-Brokers support both segment-level and whole-query result level caching. Segment-level caching is controlled by the
-parameters `useCache` and `populateCache`. Whole-query result level caching is controlled by the parameters
-`useResultLevelCache` and `populateResultLevelCache` and [runtime properties](../configuration/index.md)
-`druid.broker.cache.*`.
+### Per-segment caching
-Enabling segment-level caching on the Broker can yield faster results than if query caches were enabled on Historicals for small
-clusters. This is the recommended setup for smaller production clusters (< 5 servers). Populating segment-level caches on
-the Broker is _not_ recommended for large production clusters, since when the property `druid.broker.cache.populateCache` is
-set to `true` (and query context parameter `populateCache` is _not_ set to `false`), results from Historicals are returned
-on a per segment basis, and Historicals will not be able to do any local result merging. This impairs the ability of the
-Druid cluster to scale well.
+The primary form of caching in Druid is the **per-segment cache** which stores query results on a per-segment basis. It is enabled on Historical services by default.
-## Query caching on Historicals
+When your queries include data from segments that are mutable and undergoing real-time ingestion, use a segment cache. In this case Druid caches query results for immutable historical segments when possible. It re-computes results for the real-time segments at query time.
-Historicals only support segment-level caching. Segment-level caching is controlled by the query context
-parameters `useCache` and `populateCache` and [runtime properties](../configuration/index.md)
-`druid.historical.cache.*`.
+For example, you have queries that frequently include incoming data from a Kafka or Kinesis stream alongside unchanging segments. Per-segment caching lets Druid cache results from older immutable segments and merge them with updated data. Whole-query caching would not be helpful in this scenario because the new data from real-time ingestion continually invalidates the cache.
-Larger production clusters should enable segment-level cache population on Historicals only (not on Brokers) to avoid
-having to use Brokers to merge all query results. Enabling cache population on the Historicals instead of the Brokers
-enables the Historicals to do their own local result merging and puts less strain on the Brokers.
+### Whole-query caching
-## Query caching on Ingestion Tasks
+If real-time ingestion invalidating the cache is not an issue for your queries, you can use **whole-query caching** on the Broker to increase query efficiency. The Broker performs whole-query caching operations before sending fan out queries to Historicals. Therefore Druid no longer needs to merge the per-segment results on the Broker.
-Task executor processes such as the Peon or the experimental Indexer only support segment-level caching. Segment-level
-caching is controlled by the query context parameters `useCache` and `populateCache`
-and [runtime properties](../configuration/index.md) `druid.realtime.cache.*`.
+For instance, whole-query caching is a good option when you have queries that include data from a batch ingestion task that runs every few hours or once a day. Per-segment caching would be less efficient in this case because it requires Druid to merge the per-segment results for each query, even when the results are cached.
+
+## Where to enable caching
+
+**Per-segment cache** is available as follows:
+
+- On Historicals, the default. Enable segment-level cache population on Historicals for larger production clusters to prevent Brokers from having to merge all query results. When you enable cache population on Historicals instead of Brokers, the Historicals merge their own local results and put less strain on the Brokers.
+
+- On ingestion tasks in the Peon or Indexer service. Larger production clusters should enable segment-level cache population on task execution services only to prevent Brokers from having to merge all query results. When you enable cache population on task execution services instead of Brokers, the the task execution services to merge their own local results and put less strain on the Brokers.
+
+ Task executor services only support caches that store data locally. For example the `caffeine` cache. This restriction exists because the cache stores results at the level of intermediate partial segments generated by the ingestion tasks. These intermediate partial segments may not be identical across task replicas. Therefore task executor services ignore remote cache types such as `memcached`.
+
+- On Brokers for small production clusters with less than five servers.
+
+ Do not use per-segment caches on the Broker for large production clusters. When `druid.broker.cache.populateCache` is `true` and query context parameter `populateCache` _is not_ `false`, Historicals return results on a per-segment basis without merging results locally thus negatively impacting cluster scalability.
+
+**Whole-query cache** is only available on Brokers.
+
+## Performance considerations for caching
+Caching enables increased concurrency on the same system, therefore leading to noticeable performance improvements for queries on Druid clusters handling throughput for concurrent, mixed workloads.
+
+If you are looking to improve response time for a single query or page load, you should ignore caching. In general, response time for a single task should meet performance objectives even when the cache is cold.
+
+During query processing, the per-segment cache intercepts the query and sends the results directly to the Broker. This way the query bypasses the data server processing threads. For queries requiring minimal processing in the Broker, cached queries are very quick. If work done on the Broker causes a query bottleneck, enabling caching results in little noticeable query improvement.
+
+The largest performance gains from segment caching tend to apply to `topN` and time series queries. The impact is less for `groupBy` queries. The same applies to queries with or without joins.
Review comment:
```suggestion
The largest performance gains from segment caching tend to apply to `topN` and time series queries. The impact is less for `groupBy` queries.
```
I removed that sentence. I lifted it from a perf topic by @gianm and I can't find the source context now.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] techdocsmith commented on a change in pull request #10848: refactor query caching docs
Posted by GitBox <gi...@apache.org>.
techdocsmith commented on a change in pull request #10848:
URL: https://github.com/apache/druid/pull/10848#discussion_r577996930
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,90 @@
+---
+id: using-caching
+title: "Using query caching"
Review comment:
let's do that in another PR, I think.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] suneet-s merged pull request #10848: refactor query caching docs
Posted by GitBox <gi...@apache.org>.
suneet-s merged pull request #10848:
URL: https://github.com/apache/druid/pull/10848
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] suneet-s commented on a change in pull request #10848: refactor query caching docs
Posted by GitBox <gi...@apache.org>.
suneet-s commented on a change in pull request #10848:
URL: https://github.com/apache/druid/pull/10848#discussion_r580536570
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +22,75 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently accessed data. This topic defines the different types of caching for Druid. It describes the default caching behavior and provides guidance and examples to help you hone your caching strategy.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+If you're unfamiliar with Druid architecture, review the following topics before proceeding with caching:
+- [Druid Design](../design/architecture.md)
+- [Segments](../design/segments.md)
+- [Query execution](./query-execution)
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+For instructions to configure caching see [Using query caching](./using-caching.md).
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports segment caching which stores _partial results_ of a query for a specific segment, and whole-query caching which stores all results for a query. To avoid returning stale results, Druid invalidates the cache the moment any underlying data changes for both types of cache.
-## Using and populating cache
+Druid can store cache data the local JVM heap or in an external distributed key/value store. See [Cache configuration](../configuration/index.md#cache-configuration) for information on how to configure cache storage.
Review comment:
```suggestion
Druid can store cache data in the local JVM heap or in an external distributed key/value store. See [Cache configuration](../configuration/index.md#cache-configuration) for information on how to configure cache storage.
```
IMO It would be good to describe the defaults in this page. That way, as an operator, this is the page that I can read to know what the initial state of the system is and where to go to know how to change config options
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +22,75 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently accessed data. This topic defines the different types of caching for Druid. It describes the default caching behavior and provides guidance and examples to help you hone your caching strategy.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+If you're unfamiliar with Druid architecture, review the following topics before proceeding with caching:
+- [Druid Design](../design/architecture.md)
+- [Segments](../design/segments.md)
+- [Query execution](./query-execution)
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+For instructions to configure caching see [Using query caching](./using-caching.md).
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports segment caching which stores _partial results_ of a query for a specific segment, and whole-query caching which stores all results for a query. To avoid returning stale results, Druid invalidates the cache the moment any underlying data changes for both types of cache.
-## Using and populating cache
+Druid can store cache data the local JVM heap or in an external distributed key/value store. See [Cache configuration](../configuration/index.md#cache-configuration) for information on how to configure cache storage.
-All caches have a pair of parameters that control the behavior of how individual queries interact with the cache, a 'use' cache parameter, and a 'populate' cache parameter. These settings must be enabled at the service level via [runtime properties](../configuration/index.md) to utilize cache, but can be controlled on a per query basis by setting them on the [query context](../querying/query-context.md). The 'use' parameter obviously controls if a query will utilize cached results. The 'populate' parameter controls if a query will update cached results. These are separate parameters to allow queries on uncommon data to utilize cached results without polluting the cache with results that are unlikely to be re-used by other queries, for example large reports or very old data.
+### Segment caching
-## Query caching on Brokers
+The primary form of caching in Druid is the **segment cache**. The segment cache stores query results on a per-segment basis. It is enabled on Historical services by default.
-Brokers support both segment-level and whole-query result level caching. Segment-level caching is controlled by the
-parameters `useCache` and `populateCache`. Whole-query result level caching is controlled by the parameters
-`useResultLevelCache` and `populateResultLevelCache` and [runtime properties](../configuration/index.md)
-`druid.broker.cache.*`.
+When your queries include data from segments that are mutable and undergoing real-time ingestion, use a segment cache. In this case Druid caches query results for immutable historical segments when possible. It re-computes results for the real-time segments at query time.
-Enabling segment-level caching on the Broker can yield faster results than if query caches were enabled on Historicals for small
-clusters. This is the recommended setup for smaller production clusters (< 5 servers). Populating segment-level caches on
-the Broker is _not_ recommended for large production clusters, since when the property `druid.broker.cache.populateCache` is
-set to `true` (and query context parameter `populateCache` is _not_ set to `false`), results from Historicals are returned
-on a per segment basis, and Historicals will not be able to do any local result merging. This impairs the ability of the
-Druid cluster to scale well.
+For example, you have queries that frequently include incoming data from a Kafka or Kinesis stream alongside unchanging segments. Whole-query caching is not helpful in this scenario because the new data from real-time ingestion continually invalidates the cache. Segment caching lets Druid cache results from older immutable segments and merge them with updated data.
Review comment:
Does this belong under the next section?
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +22,75 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently accessed data. This topic defines the different types of caching for Druid. It describes the default caching behavior and provides guidance and examples to help you hone your caching strategy.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+If you're unfamiliar with Druid architecture, review the following topics before proceeding with caching:
+- [Druid Design](../design/architecture.md)
+- [Segments](../design/segments.md)
+- [Query execution](./query-execution)
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+For instructions to configure caching see [Using query caching](./using-caching.md).
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports segment caching which stores _partial results_ of a query for a specific segment, and whole-query caching which stores all results for a query. To avoid returning stale results, Druid invalidates the cache the moment any underlying data changes for both types of cache.
Review comment:
Should this section include a description of "whole-query caching" as well?
Maybe this is where we document that segment caching is enabled by default while whole query caching is disabled
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +22,75 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently accessed data. This topic defines the different types of caching for Druid. It describes the default caching behavior and provides guidance and examples to help you hone your caching strategy.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+If you're unfamiliar with Druid architecture, review the following topics before proceeding with caching:
+- [Druid Design](../design/architecture.md)
+- [Segments](../design/segments.md)
+- [Query execution](./query-execution)
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+For instructions to configure caching see [Using query caching](./using-caching.md).
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports segment caching which stores _partial results_ of a query for a specific segment, and whole-query caching which stores all results for a query. To avoid returning stale results, Druid invalidates the cache the moment any underlying data changes for both types of cache.
-## Using and populating cache
+Druid can store cache data the local JVM heap or in an external distributed key/value store. See [Cache configuration](../configuration/index.md#cache-configuration) for information on how to configure cache storage.
-All caches have a pair of parameters that control the behavior of how individual queries interact with the cache, a 'use' cache parameter, and a 'populate' cache parameter. These settings must be enabled at the service level via [runtime properties](../configuration/index.md) to utilize cache, but can be controlled on a per query basis by setting them on the [query context](../querying/query-context.md). The 'use' parameter obviously controls if a query will utilize cached results. The 'populate' parameter controls if a query will update cached results. These are separate parameters to allow queries on uncommon data to utilize cached results without polluting the cache with results that are unlikely to be re-used by other queries, for example large reports or very old data.
+### Segment caching
-## Query caching on Brokers
+The primary form of caching in Druid is the **segment cache**. The segment cache stores query results on a per-segment basis. It is enabled on Historical services by default.
-Brokers support both segment-level and whole-query result level caching. Segment-level caching is controlled by the
-parameters `useCache` and `populateCache`. Whole-query result level caching is controlled by the parameters
-`useResultLevelCache` and `populateResultLevelCache` and [runtime properties](../configuration/index.md)
-`druid.broker.cache.*`.
+When your queries include data from segments that are mutable and undergoing real-time ingestion, use a segment cache. In this case Druid caches query results for immutable historical segments when possible. It re-computes results for the real-time segments at query time.
-Enabling segment-level caching on the Broker can yield faster results than if query caches were enabled on Historicals for small
-clusters. This is the recommended setup for smaller production clusters (< 5 servers). Populating segment-level caches on
-the Broker is _not_ recommended for large production clusters, since when the property `druid.broker.cache.populateCache` is
-set to `true` (and query context parameter `populateCache` is _not_ set to `false`), results from Historicals are returned
-on a per segment basis, and Historicals will not be able to do any local result merging. This impairs the ability of the
-Druid cluster to scale well.
+For example, you have queries that frequently include incoming data from a Kafka or Kinesis stream alongside unchanging segments. Whole-query caching is not helpful in this scenario because the new data from real-time ingestion continually invalidates the cache. Segment caching lets Druid cache results from older immutable segments and merge them with updated data.
-## Query caching on Historicals
+### Whole-query caching
-Historicals only support segment-level caching. Segment-level caching is controlled by the query context
-parameters `useCache` and `populateCache` and [runtime properties](../configuration/index.md)
-`druid.historical.cache.*`.
+If real-time ingestion invalidating the cache is not an issue for your queries, you can use **whole-query caching** on the Broker to increase query efficiency. Segment caching is less efficient in this case because it requires Druid to merge the per-segment results for each query, even when the results are cached. For instance, whole-query caching is a good option when you have queries that include data from a batch ingestion task that runs every few hours or once a day.
Review comment:
I think we should describe that whole query caching is done at the broker, before fan out queries are sent to the historical. This is useful because Druid will no longer need to merge the per-segment results back on the broker.
Your description of the scenarios where this is helpful is great!
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +22,75 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently accessed data. This topic defines the different types of caching for Druid. It describes the default caching behavior and provides guidance and examples to help you hone your caching strategy.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+If you're unfamiliar with Druid architecture, review the following topics before proceeding with caching:
+- [Druid Design](../design/architecture.md)
+- [Segments](../design/segments.md)
+- [Query execution](./query-execution)
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+For instructions to configure caching see [Using query caching](./using-caching.md).
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports segment caching which stores _partial results_ of a query for a specific segment, and whole-query caching which stores all results for a query. To avoid returning stale results, Druid invalidates the cache the moment any underlying data changes for both types of cache.
-## Using and populating cache
+Druid can store cache data the local JVM heap or in an external distributed key/value store. See [Cache configuration](../configuration/index.md#cache-configuration) for information on how to configure cache storage.
-All caches have a pair of parameters that control the behavior of how individual queries interact with the cache, a 'use' cache parameter, and a 'populate' cache parameter. These settings must be enabled at the service level via [runtime properties](../configuration/index.md) to utilize cache, but can be controlled on a per query basis by setting them on the [query context](../querying/query-context.md). The 'use' parameter obviously controls if a query will utilize cached results. The 'populate' parameter controls if a query will update cached results. These are separate parameters to allow queries on uncommon data to utilize cached results without polluting the cache with results that are unlikely to be re-used by other queries, for example large reports or very old data.
+### Segment caching
-## Query caching on Brokers
+The primary form of caching in Druid is the **segment cache**. The segment cache stores query results on a per-segment basis. It is enabled on Historical services by default.
-Brokers support both segment-level and whole-query result level caching. Segment-level caching is controlled by the
-parameters `useCache` and `populateCache`. Whole-query result level caching is controlled by the parameters
-`useResultLevelCache` and `populateResultLevelCache` and [runtime properties](../configuration/index.md)
-`druid.broker.cache.*`.
+When your queries include data from segments that are mutable and undergoing real-time ingestion, use a segment cache. In this case Druid caches query results for immutable historical segments when possible. It re-computes results for the real-time segments at query time.
-Enabling segment-level caching on the Broker can yield faster results than if query caches were enabled on Historicals for small
-clusters. This is the recommended setup for smaller production clusters (< 5 servers). Populating segment-level caches on
-the Broker is _not_ recommended for large production clusters, since when the property `druid.broker.cache.populateCache` is
-set to `true` (and query context parameter `populateCache` is _not_ set to `false`), results from Historicals are returned
-on a per segment basis, and Historicals will not be able to do any local result merging. This impairs the ability of the
-Druid cluster to scale well.
+For example, you have queries that frequently include incoming data from a Kafka or Kinesis stream alongside unchanging segments. Whole-query caching is not helpful in this scenario because the new data from real-time ingestion continually invalidates the cache. Segment caching lets Druid cache results from older immutable segments and merge them with updated data.
-## Query caching on Historicals
+### Whole-query caching
-Historicals only support segment-level caching. Segment-level caching is controlled by the query context
-parameters `useCache` and `populateCache` and [runtime properties](../configuration/index.md)
-`druid.historical.cache.*`.
+If real-time ingestion invalidating the cache is not an issue for your queries, you can use **whole-query caching** on the Broker to increase query efficiency. Segment caching is less efficient in this case because it requires Druid to merge the per-segment results for each query, even when the results are cached. For instance, whole-query caching is a good option when you have queries that include data from a batch ingestion task that runs every few hours or once a day.
-Larger production clusters should enable segment-level cache population on Historicals only (not on Brokers) to avoid
-having to use Brokers to merge all query results. Enabling cache population on the Historicals instead of the Brokers
-enables the Historicals to do their own local result merging and puts less strain on the Brokers.
+## Where to enable caching
-## Query caching on Ingestion Tasks
+**Segment cache** is available as follows:
+- On Brokers for small production clusters with less than five servers.
-Task executor processes such as the Peon or the experimental Indexer only support segment-level caching. Segment-level
-caching is controlled by the query context parameters `useCache` and `populateCache`
-and [runtime properties](../configuration/index.md) `druid.realtime.cache.*`.
+ Do not use segment caches on the Broker for large production clusters. When `druid.broker.cache.populateCache` is `true` and query context parameter `populateCache` _is not_ `false`, Historicals return results on a per-segment basis without merging results locally thus negatively impacting cluster scalability.
+
+- On Historicals, the default. Enable segment-level cache population on Historicals for larger production clusters to prevent Brokers from having to merge all query results. When you enable cache population on Historicals instead of Brokers, the Historicals merge their own local results and put less strain on the Brokers.
+
+- On ingestion tasks in the Peon or Indexer service. Larger production clusters should enable segment-level cache population on task execution services only to prevent Brokers from having to merge all query results. When you enable cache population on task execution services instead of Brokers, the the task execution services to merge their own local results and put less strain on the Brokers.
+
+ Task executor services only support caches that store data locally. For example the `caffeine` cache. This restriction exists because the cache stores results at the level of intermediate partial segments generated by the ingestion tasks. These intermediate partial segments may not be identical across task replicas. Therefore task executor services ignore remote cache types such as `memcached`.
+
+**Whole-query cache** is only available on Brokers.
+
+## Performance considerations for caching
+
+Consider the following as you develop your caching strategy:
+- Caching enables increased concurrency on the same system, therefore leading to noticeable performance improvements for queries on Druid clusters handling throughput for concurrent, mixed workloads.
+
+- If you are looking to improve response time for a single query or page load, you should ignore caching. In general, response time for a single task should meet performance objectives even when the cache is cold.
+
+- During query processing, the segment cache intercepts the query and sends the results directly to the Broker. This way the query bypasses the data server processing threads. For queries requiring minimal processing in the Broker, cached queries are very quick. If work done on the Broker causes a query bottleneck, enabling caching results in little noticeable query improvement.
+
+- The largest performance gains from segment caching tend to apply to `topN` and time series queries. The impact is less for `groupBy` queries. The same applies to queries with or without joins.
+
+### Scenarios where caching does not increase query performance
+
+Caching does not solve all types of query peformance issues. For each cache type there are scenarios where caching is likely to be of little benefit.
+
+**Segment caching** doesn't work for TBD.
+
+**Whole-query caching** doesn't work for the following:
+- `GroupBy` v2 queries
+- queries with joins
+- queries on real-time data.
Review comment:
I think we shouldn't mention this here. The other 2 in the list are specific limitations of the Druid system. This point talks about the fact that if you are querying real time data (last 5 minutes), you will never have a cached response since data for the last 5 minutes is always coming in. What do you think?
```suggestion
```
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +22,75 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently accessed data. This topic defines the different types of caching for Druid. It describes the default caching behavior and provides guidance and examples to help you hone your caching strategy.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+If you're unfamiliar with Druid architecture, review the following topics before proceeding with caching:
+- [Druid Design](../design/architecture.md)
+- [Segments](../design/segments.md)
+- [Query execution](./query-execution)
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+For instructions to configure caching see [Using query caching](./using-caching.md).
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports segment caching which stores _partial results_ of a query for a specific segment, and whole-query caching which stores all results for a query. To avoid returning stale results, Druid invalidates the cache the moment any underlying data changes for both types of cache.
-## Using and populating cache
+Druid can store cache data the local JVM heap or in an external distributed key/value store. See [Cache configuration](../configuration/index.md#cache-configuration) for information on how to configure cache storage.
-All caches have a pair of parameters that control the behavior of how individual queries interact with the cache, a 'use' cache parameter, and a 'populate' cache parameter. These settings must be enabled at the service level via [runtime properties](../configuration/index.md) to utilize cache, but can be controlled on a per query basis by setting them on the [query context](../querying/query-context.md). The 'use' parameter obviously controls if a query will utilize cached results. The 'populate' parameter controls if a query will update cached results. These are separate parameters to allow queries on uncommon data to utilize cached results without polluting the cache with results that are unlikely to be re-used by other queries, for example large reports or very old data.
+### Segment caching
-## Query caching on Brokers
+The primary form of caching in Druid is the **segment cache**. The segment cache stores query results on a per-segment basis. It is enabled on Historical services by default.
-Brokers support both segment-level and whole-query result level caching. Segment-level caching is controlled by the
-parameters `useCache` and `populateCache`. Whole-query result level caching is controlled by the parameters
-`useResultLevelCache` and `populateResultLevelCache` and [runtime properties](../configuration/index.md)
-`druid.broker.cache.*`.
+When your queries include data from segments that are mutable and undergoing real-time ingestion, use a segment cache. In this case Druid caches query results for immutable historical segments when possible. It re-computes results for the real-time segments at query time.
-Enabling segment-level caching on the Broker can yield faster results than if query caches were enabled on Historicals for small
-clusters. This is the recommended setup for smaller production clusters (< 5 servers). Populating segment-level caches on
-the Broker is _not_ recommended for large production clusters, since when the property `druid.broker.cache.populateCache` is
-set to `true` (and query context parameter `populateCache` is _not_ set to `false`), results from Historicals are returned
-on a per segment basis, and Historicals will not be able to do any local result merging. This impairs the ability of the
-Druid cluster to scale well.
+For example, you have queries that frequently include incoming data from a Kafka or Kinesis stream alongside unchanging segments. Whole-query caching is not helpful in this scenario because the new data from real-time ingestion continually invalidates the cache. Segment caching lets Druid cache results from older immutable segments and merge them with updated data.
-## Query caching on Historicals
+### Whole-query caching
-Historicals only support segment-level caching. Segment-level caching is controlled by the query context
-parameters `useCache` and `populateCache` and [runtime properties](../configuration/index.md)
-`druid.historical.cache.*`.
+If real-time ingestion invalidating the cache is not an issue for your queries, you can use **whole-query caching** on the Broker to increase query efficiency. Segment caching is less efficient in this case because it requires Druid to merge the per-segment results for each query, even when the results are cached. For instance, whole-query caching is a good option when you have queries that include data from a batch ingestion task that runs every few hours or once a day.
-Larger production clusters should enable segment-level cache population on Historicals only (not on Brokers) to avoid
-having to use Brokers to merge all query results. Enabling cache population on the Historicals instead of the Brokers
-enables the Historicals to do their own local result merging and puts less strain on the Brokers.
+## Where to enable caching
-## Query caching on Ingestion Tasks
+**Segment cache** is available as follows:
+- On Brokers for small production clusters with less than five servers.
-Task executor processes such as the Peon or the experimental Indexer only support segment-level caching. Segment-level
-caching is controlled by the query context parameters `useCache` and `populateCache`
-and [runtime properties](../configuration/index.md) `druid.realtime.cache.*`.
+ Do not use segment caches on the Broker for large production clusters. When `druid.broker.cache.populateCache` is `true` and query context parameter `populateCache` _is not_ `false`, Historicals return results on a per-segment basis without merging results locally thus negatively impacting cluster scalability.
+
+- On Historicals, the default. Enable segment-level cache population on Historicals for larger production clusters to prevent Brokers from having to merge all query results. When you enable cache population on Historicals instead of Brokers, the Historicals merge their own local results and put less strain on the Brokers.
+
+- On ingestion tasks in the Peon or Indexer service. Larger production clusters should enable segment-level cache population on task execution services only to prevent Brokers from having to merge all query results. When you enable cache population on task execution services instead of Brokers, the the task execution services to merge their own local results and put less strain on the Brokers.
+
+ Task executor services only support caches that store data locally. For example the `caffeine` cache. This restriction exists because the cache stores results at the level of intermediate partial segments generated by the ingestion tasks. These intermediate partial segments may not be identical across task replicas. Therefore task executor services ignore remote cache types such as `memcached`.
+
+**Whole-query cache** is only available on Brokers.
+
+## Performance considerations for caching
+
+Consider the following as you develop your caching strategy:
+- Caching enables increased concurrency on the same system, therefore leading to noticeable performance improvements for queries on Druid clusters handling throughput for concurrent, mixed workloads.
+
+- If you are looking to improve response time for a single query or page load, you should ignore caching. In general, response time for a single task should meet performance objectives even when the cache is cold.
+
+- During query processing, the segment cache intercepts the query and sends the results directly to the Broker. This way the query bypasses the data server processing threads. For queries requiring minimal processing in the Broker, cached queries are very quick. If work done on the Broker causes a query bottleneck, enabling caching results in little noticeable query improvement.
+
+- The largest performance gains from segment caching tend to apply to `topN` and time series queries. The impact is less for `groupBy` queries. The same applies to queries with or without joins.
+
+### Scenarios where caching does not increase query performance
+
+Caching does not solve all types of query peformance issues. For each cache type there are scenarios where caching is likely to be of little benefit.
+
+**Segment caching** doesn't work for TBD.
Review comment:
@abhishekagarwal87 You did some investigation into segment caching a little while ago. Do you happen to know where to find the list of places where segment caching isn't supported yet
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,92 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services to populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cache for results.
+- `populateCache` to instruct a query to cache its results.
+
+The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example, large reports or queries on very old data.
+
+To use caching, you must first enable the settings for a service in the runtime properties. Afterward, you can control which queries use the cache or populate the cache on a per-query basis within the query context.
+
+The query context settings do not override the server settings. For example, it is possible to set a query context to use the cache, but if it is not enabled at the service level, there's no cache to use.
+
+## Enabling query caching on Brokers
+Brokers support both segment-level and whole-query result level caching.
+
+To control **segment caching** on the Broker, set the `useCache` and `populateCache`runtime properties. For example, to set the Broker to use and populate the segment cache for queries:
+```
+druid.broker.cache.useCache=true
+druid.broker.cache.populateCache=true
+```
+To control **whole-query caching** on the Broker, set the `useResultLevelCache` and `populateResultLevelCache` runtime properties. For example, to set the Broker to use and populate the whole-query cache for queries:
+```
+druid.broker.cache.useResultLevelCache=true
+druid.broker.cache.populateResultLevelCache=true
+```
+See [Broker caching](../configuration/index.md#broker-caching) for a description of all available Broker cache configurations.
+
+## Enabling query caching on Historicals
+Historicals only support **segment-level** caching. To control caching on the Historical, set the `useCache` and `populateCache` runtime properties. For example, to set the Historical to both use and populate the segment cache for queries:
+ ```
+ druid.broker.cache.useCache=true
+ druid.broker.cache.populateCache=true
+ ```
+See [Historical caching](../configuration/index.md#historical-caching) for a description of all available Historical cache configurations.
+
+## Enabling query caching on task executor services
+Task executor services, the Peon or the Indexer, only support **segment-level** caching. To control caching on a task executor service, set the `useCache` and `populateCache` runtime properties. For example, to set the Peon to both use and populate the segment cache for queries:
+
+```
+druid.realtime.cache.useCache=true
+druid.realtime.cache.populateCache=true
+```
+
+See [Peon caching](configuration/index.md#peon-caching) for a description of all available task executor service caching options.
+
+## Enabling caching in the query context
+After you enable caching for a service, set cache options for individual queries in the query [context](./query-context.md). For example, you can `POST` a Druid SQL request to the HTTP POST API and include the context as a JSON object:
+
+```
+{
+ "query" : "SELECT COUNT(*) FROM data_source WHERE foo = 'bar' AND __time > TIMESTAMP '2020-01-01 00:00:00'",
+ "context" : {
+ "useCache" : "true",
+ "populateCache" : "false"
+ }
+}
+```
+In this example `populateCache` is `false` because the query references data that is over a year old. For more information, see [Druid SQL client APIs](./sql.md#client-apis).
+
+reiterate that populateCache : true must be set somehwere on at least 1 service. By defaults it's on on Historical and that serves the majority of use cases.
Review comment:
needs a touch up
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,92 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services to populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cache for results.
+- `populateCache` to instruct a query to cache its results.
+
+The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example, large reports or queries on very old data.
+
+To use caching, you must first enable the settings for a service in the runtime properties. Afterward, you can control which queries use the cache or populate the cache on a per-query basis within the query context.
+
+The query context settings do not override the server settings. For example, it is possible to set a query context to use the cache, but if it is not enabled at the service level, there's no cache to use.
+
+## Enabling query caching on Brokers
+Brokers support both segment-level and whole-query result level caching.
+
+To control **segment caching** on the Broker, set the `useCache` and `populateCache`runtime properties. For example, to set the Broker to use and populate the segment cache for queries:
+```
+druid.broker.cache.useCache=true
+druid.broker.cache.populateCache=true
+```
+To control **whole-query caching** on the Broker, set the `useResultLevelCache` and `populateResultLevelCache` runtime properties. For example, to set the Broker to use and populate the whole-query cache for queries:
+```
+druid.broker.cache.useResultLevelCache=true
+druid.broker.cache.populateResultLevelCache=true
+```
+See [Broker caching](../configuration/index.md#broker-caching) for a description of all available Broker cache configurations.
+
+## Enabling query caching on Historicals
+Historicals only support **segment-level** caching. To control caching on the Historical, set the `useCache` and `populateCache` runtime properties. For example, to set the Historical to both use and populate the segment cache for queries:
+ ```
+ druid.broker.cache.useCache=true
+ druid.broker.cache.populateCache=true
+ ```
+See [Historical caching](../configuration/index.md#historical-caching) for a description of all available Historical cache configurations.
+
+## Enabling query caching on task executor services
+Task executor services, the Peon or the Indexer, only support **segment-level** caching. To control caching on a task executor service, set the `useCache` and `populateCache` runtime properties. For example, to set the Peon to both use and populate the segment cache for queries:
+
+```
+druid.realtime.cache.useCache=true
+druid.realtime.cache.populateCache=true
+```
+
+See [Peon caching](configuration/index.md#peon-caching) for a description of all available task executor service caching options.
+
+## Enabling caching in the query context
+After you enable caching for a service, set cache options for individual queries in the query [context](./query-context.md). For example, you can `POST` a Druid SQL request to the HTTP POST API and include the context as a JSON object:
+
+```
+{
+ "query" : "SELECT COUNT(*) FROM data_source WHERE foo = 'bar' AND __time > TIMESTAMP '2020-01-01 00:00:00'",
+ "context" : {
+ "useCache" : "true",
+ "populateCache" : "false"
+ }
+}
+```
+In this example `populateCache` is `false` because the query references data that is over a year old. For more information, see [Druid SQL client APIs](./sql.md#client-apis).
Review comment:
`because the query references data that is over a year old. `
This reads as if the system is smart enough to make this call. I think we want to say something along the lines of the user making the query does not want to fill up the cache with results for old segments, so they may decide to disable populating the cache for old data, but still want to use the cache for recent data. In this scenario, they'd set the query context like this. What do you think?
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +22,75 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently accessed data. This topic defines the different types of caching for Druid. It describes the default caching behavior and provides guidance and examples to help you hone your caching strategy.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+If you're unfamiliar with Druid architecture, review the following topics before proceeding with caching:
+- [Druid Design](../design/architecture.md)
+- [Segments](../design/segments.md)
+- [Query execution](./query-execution)
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+For instructions to configure caching see [Using query caching](./using-caching.md).
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports segment caching which stores _partial results_ of a query for a specific segment, and whole-query caching which stores all results for a query. To avoid returning stale results, Druid invalidates the cache the moment any underlying data changes for both types of cache.
-## Using and populating cache
+Druid can store cache data the local JVM heap or in an external distributed key/value store. See [Cache configuration](../configuration/index.md#cache-configuration) for information on how to configure cache storage.
-All caches have a pair of parameters that control the behavior of how individual queries interact with the cache, a 'use' cache parameter, and a 'populate' cache parameter. These settings must be enabled at the service level via [runtime properties](../configuration/index.md) to utilize cache, but can be controlled on a per query basis by setting them on the [query context](../querying/query-context.md). The 'use' parameter obviously controls if a query will utilize cached results. The 'populate' parameter controls if a query will update cached results. These are separate parameters to allow queries on uncommon data to utilize cached results without polluting the cache with results that are unlikely to be re-used by other queries, for example large reports or very old data.
+### Segment caching
-## Query caching on Brokers
+The primary form of caching in Druid is the **segment cache**. The segment cache stores query results on a per-segment basis. It is enabled on Historical services by default.
-Brokers support both segment-level and whole-query result level caching. Segment-level caching is controlled by the
-parameters `useCache` and `populateCache`. Whole-query result level caching is controlled by the parameters
-`useResultLevelCache` and `populateResultLevelCache` and [runtime properties](../configuration/index.md)
-`druid.broker.cache.*`.
+When your queries include data from segments that are mutable and undergoing real-time ingestion, use a segment cache. In this case Druid caches query results for immutable historical segments when possible. It re-computes results for the real-time segments at query time.
-Enabling segment-level caching on the Broker can yield faster results than if query caches were enabled on Historicals for small
-clusters. This is the recommended setup for smaller production clusters (< 5 servers). Populating segment-level caches on
-the Broker is _not_ recommended for large production clusters, since when the property `druid.broker.cache.populateCache` is
-set to `true` (and query context parameter `populateCache` is _not_ set to `false`), results from Historicals are returned
-on a per segment basis, and Historicals will not be able to do any local result merging. This impairs the ability of the
-Druid cluster to scale well.
+For example, you have queries that frequently include incoming data from a Kafka or Kinesis stream alongside unchanging segments. Whole-query caching is not helpful in this scenario because the new data from real-time ingestion continually invalidates the cache. Segment caching lets Druid cache results from older immutable segments and merge them with updated data.
-## Query caching on Historicals
+### Whole-query caching
-Historicals only support segment-level caching. Segment-level caching is controlled by the query context
-parameters `useCache` and `populateCache` and [runtime properties](../configuration/index.md)
-`druid.historical.cache.*`.
+If real-time ingestion invalidating the cache is not an issue for your queries, you can use **whole-query caching** on the Broker to increase query efficiency. Segment caching is less efficient in this case because it requires Druid to merge the per-segment results for each query, even when the results are cached. For instance, whole-query caching is a good option when you have queries that include data from a batch ingestion task that runs every few hours or once a day.
-Larger production clusters should enable segment-level cache population on Historicals only (not on Brokers) to avoid
-having to use Brokers to merge all query results. Enabling cache population on the Historicals instead of the Brokers
-enables the Historicals to do their own local result merging and puts less strain on the Brokers.
+## Where to enable caching
-## Query caching on Ingestion Tasks
+**Segment cache** is available as follows:
+- On Brokers for small production clusters with less than five servers.
Review comment:
nit: Maybe this should be last in the list, since it's the least impactful.
Caching on the historicals - applies to almost everyone.
Caching on the ingestion tasks - useful if you're querying realtime data
Caching on the broker - not useful in production scenarios... I can't think of a reason to ever to this tbh
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,92 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services to populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cache for results.
+- `populateCache` to instruct a query to cache its results.
+
+The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example, large reports or queries on very old data.
+
+To use caching, you must first enable the settings for a service in the runtime properties. Afterward, you can control which queries use the cache or populate the cache on a per-query basis within the query context.
+
+The query context settings do not override the server settings. For example, it is possible to set a query context to use the cache, but if it is not enabled at the service level, there's no cache to use.
Review comment:
I think this is a little more nuanced. It doesn't enable the feature if it's disabled in the server settings, but a query can specify that it doesn't want to populate the cache or use the cache, even if those settings are made in the server settings
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] techdocsmith commented on a change in pull request #10848: refactor query caching docs
Posted by GitBox <gi...@apache.org>.
techdocsmith commented on a change in pull request #10848:
URL: https://github.com/apache/druid/pull/10848#discussion_r588608529
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,92 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services to populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cache for results.
+- `populateCache` to instruct a query to cache its results.
+
+The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example, large reports or queries on very old data.
+
+To use caching, you must first enable the settings for a service in the runtime properties. Afterward, you can control which queries use the cache or populate the cache on a per-query basis within the query context.
+
+The query context settings do not override the server settings. For example, it is possible to set a query context to use the cache, but if it is not enabled at the service level, there's no cache to use.
Review comment:
I just removed this. I think the sentence in the previous paragraph is pretty clear.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] techdocsmith commented on a change in pull request #10848: refactor query caching docs
Posted by GitBox <gi...@apache.org>.
techdocsmith commented on a change in pull request #10848:
URL: https://github.com/apache/druid/pull/10848#discussion_r588580930
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +22,75 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently accessed data. This topic defines the different types of caching for Druid. It describes the default caching behavior and provides guidance and examples to help you hone your caching strategy.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+If you're unfamiliar with Druid architecture, review the following topics before proceeding with caching:
+- [Druid Design](../design/architecture.md)
+- [Segments](../design/segments.md)
+- [Query execution](./query-execution)
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+For instructions to configure caching see [Using query caching](./using-caching.md).
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports segment caching which stores _partial results_ of a query for a specific segment, and whole-query caching which stores all results for a query. To avoid returning stale results, Druid invalidates the cache the moment any underlying data changes for both types of cache.
-## Using and populating cache
+Druid can store cache data the local JVM heap or in an external distributed key/value store. See [Cache configuration](../configuration/index.md#cache-configuration) for information on how to configure cache storage.
Review comment:
I've added the (relevant?) defaults. These will need checking because the language/code for the maximum cache storage was confusing.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] suneet-s commented on pull request #10848: refactor query caching docs
Posted by GitBox <gi...@apache.org>.
suneet-s commented on pull request #10848:
URL: https://github.com/apache/druid/pull/10848#issuecomment-792895530
Overall looks great! Looks like the docs job is failing. I've offered a few minor touchups. I'll leave it to you to decide which ones you think we should add. Once CI is passes I can take another look and merge 🎉
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] techdocsmith commented on pull request #10848: refactor query caching
Posted by GitBox <gi...@apache.org>.
techdocsmith commented on pull request #10848:
URL: https://github.com/apache/druid/pull/10848#issuecomment-772928845
@sthetland PTAL
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] techdocsmith commented on a change in pull request #10848: refactor query caching docs
Posted by GitBox <gi...@apache.org>.
techdocsmith commented on a change in pull request #10848:
URL: https://github.com/apache/druid/pull/10848#discussion_r588608926
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,92 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services to populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cache for results.
+- `populateCache` to instruct a query to cache its results.
+
+The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example, large reports or queries on very old data.
+
+To use caching, you must first enable the settings for a service in the runtime properties. Afterward, you can control which queries use the cache or populate the cache on a per-query basis within the query context.
+
+The query context settings do not override the server settings. For example, it is possible to set a query context to use the cache, but if it is not enabled at the service level, there's no cache to use.
+
+## Enabling query caching on Brokers
+Brokers support both segment-level and whole-query result level caching.
+
+To control **segment caching** on the Broker, set the `useCache` and `populateCache`runtime properties. For example, to set the Broker to use and populate the segment cache for queries:
+```
+druid.broker.cache.useCache=true
+druid.broker.cache.populateCache=true
+```
+To control **whole-query caching** on the Broker, set the `useResultLevelCache` and `populateResultLevelCache` runtime properties. For example, to set the Broker to use and populate the whole-query cache for queries:
+```
+druid.broker.cache.useResultLevelCache=true
+druid.broker.cache.populateResultLevelCache=true
+```
+See [Broker caching](../configuration/index.md#broker-caching) for a description of all available Broker cache configurations.
+
+## Enabling query caching on Historicals
+Historicals only support **segment-level** caching. To control caching on the Historical, set the `useCache` and `populateCache` runtime properties. For example, to set the Historical to both use and populate the segment cache for queries:
+ ```
+ druid.broker.cache.useCache=true
+ druid.broker.cache.populateCache=true
+ ```
+See [Historical caching](../configuration/index.md#historical-caching) for a description of all available Historical cache configurations.
+
+## Enabling query caching on task executor services
+Task executor services, the Peon or the Indexer, only support **segment-level** caching. To control caching on a task executor service, set the `useCache` and `populateCache` runtime properties. For example, to set the Peon to both use and populate the segment cache for queries:
+
+```
+druid.realtime.cache.useCache=true
+druid.realtime.cache.populateCache=true
+```
+
+See [Peon caching](configuration/index.md#peon-caching) for a description of all available task executor service caching options.
+
+## Enabling caching in the query context
+After you enable caching for a service, set cache options for individual queries in the query [context](./query-context.md). For example, you can `POST` a Druid SQL request to the HTTP POST API and include the context as a JSON object:
+
+```
+{
+ "query" : "SELECT COUNT(*) FROM data_source WHERE foo = 'bar' AND __time > TIMESTAMP '2020-01-01 00:00:00'",
+ "context" : {
+ "useCache" : "true",
+ "populateCache" : "false"
+ }
+}
+```
+In this example `populateCache` is `false` because the query references data that is over a year old. For more information, see [Druid SQL client APIs](./sql.md#client-apis).
Review comment:
Great edit
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] techdocsmith commented on pull request #10848: refactor query caching docs
Posted by GitBox <gi...@apache.org>.
techdocsmith commented on pull request #10848:
URL: https://github.com/apache/druid/pull/10848#issuecomment-780906331
@sthetland I think I got most of your suggestions, but had reorganized the doc, PTAL.
@suneet-s ,based upon our conversation I improved (or tried to) the context and organization of the caching topic. Still waiting for the list of scenarios where segment caching doesn't work.
FYI @2bethere
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] techdocsmith commented on a change in pull request #10848: refactor query caching docs
Posted by GitBox <gi...@apache.org>.
techdocsmith commented on a change in pull request #10848:
URL: https://github.com/apache/druid/pull/10848#discussion_r588555745
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +22,75 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently accessed data. This topic defines the different types of caching for Druid. It describes the default caching behavior and provides guidance and examples to help you hone your caching strategy.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+If you're unfamiliar with Druid architecture, review the following topics before proceeding with caching:
+- [Druid Design](../design/architecture.md)
+- [Segments](../design/segments.md)
+- [Query execution](./query-execution)
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+For instructions to configure caching see [Using query caching](./using-caching.md).
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports segment caching which stores _partial results_ of a query for a specific segment, and whole-query caching which stores all results for a query. To avoid returning stale results, Druid invalidates the cache the moment any underlying data changes for both types of cache.
Review comment:
this was there: `whole-query caching which stores all results for a query.`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] abhishekagarwal87 commented on a change in pull request #10848: refactor query caching docs
Posted by GitBox <gi...@apache.org>.
abhishekagarwal87 commented on a change in pull request #10848:
URL: https://github.com/apache/druid/pull/10848#discussion_r585456741
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +22,75 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently accessed data. This topic defines the different types of caching for Druid. It describes the default caching behavior and provides guidance and examples to help you hone your caching strategy.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+If you're unfamiliar with Druid architecture, review the following topics before proceeding with caching:
+- [Druid Design](../design/architecture.md)
+- [Segments](../design/segments.md)
+- [Query execution](./query-execution)
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+For instructions to configure caching see [Using query caching](./using-caching.md).
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports segment caching which stores _partial results_ of a query for a specific segment, and whole-query caching which stores all results for a query. To avoid returning stale results, Druid invalidates the cache the moment any underlying data changes for both types of cache.
-## Using and populating cache
+Druid can store cache data the local JVM heap or in an external distributed key/value store. See [Cache configuration](../configuration/index.md#cache-configuration) for information on how to configure cache storage.
-All caches have a pair of parameters that control the behavior of how individual queries interact with the cache, a 'use' cache parameter, and a 'populate' cache parameter. These settings must be enabled at the service level via [runtime properties](../configuration/index.md) to utilize cache, but can be controlled on a per query basis by setting them on the [query context](../querying/query-context.md). The 'use' parameter obviously controls if a query will utilize cached results. The 'populate' parameter controls if a query will update cached results. These are separate parameters to allow queries on uncommon data to utilize cached results without polluting the cache with results that are unlikely to be re-used by other queries, for example large reports or very old data.
+### Segment caching
-## Query caching on Brokers
+The primary form of caching in Druid is the **segment cache**. The segment cache stores query results on a per-segment basis. It is enabled on Historical services by default.
-Brokers support both segment-level and whole-query result level caching. Segment-level caching is controlled by the
-parameters `useCache` and `populateCache`. Whole-query result level caching is controlled by the parameters
-`useResultLevelCache` and `populateResultLevelCache` and [runtime properties](../configuration/index.md)
-`druid.broker.cache.*`.
+When your queries include data from segments that are mutable and undergoing real-time ingestion, use a segment cache. In this case Druid caches query results for immutable historical segments when possible. It re-computes results for the real-time segments at query time.
-Enabling segment-level caching on the Broker can yield faster results than if query caches were enabled on Historicals for small
-clusters. This is the recommended setup for smaller production clusters (< 5 servers). Populating segment-level caches on
-the Broker is _not_ recommended for large production clusters, since when the property `druid.broker.cache.populateCache` is
-set to `true` (and query context parameter `populateCache` is _not_ set to `false`), results from Historicals are returned
-on a per segment basis, and Historicals will not be able to do any local result merging. This impairs the ability of the
-Druid cluster to scale well.
+For example, you have queries that frequently include incoming data from a Kafka or Kinesis stream alongside unchanging segments. Whole-query caching is not helpful in this scenario because the new data from real-time ingestion continually invalidates the cache. Segment caching lets Druid cache results from older immutable segments and merge them with updated data.
-## Query caching on Historicals
+### Whole-query caching
-Historicals only support segment-level caching. Segment-level caching is controlled by the query context
-parameters `useCache` and `populateCache` and [runtime properties](../configuration/index.md)
-`druid.historical.cache.*`.
+If real-time ingestion invalidating the cache is not an issue for your queries, you can use **whole-query caching** on the Broker to increase query efficiency. Segment caching is less efficient in this case because it requires Druid to merge the per-segment results for each query, even when the results are cached. For instance, whole-query caching is a good option when you have queries that include data from a batch ingestion task that runs every few hours or once a day.
-Larger production clusters should enable segment-level cache population on Historicals only (not on Brokers) to avoid
-having to use Brokers to merge all query results. Enabling cache population on the Historicals instead of the Brokers
-enables the Historicals to do their own local result merging and puts less strain on the Brokers.
+## Where to enable caching
-## Query caching on Ingestion Tasks
+**Segment cache** is available as follows:
+- On Brokers for small production clusters with less than five servers.
-Task executor processes such as the Peon or the experimental Indexer only support segment-level caching. Segment-level
-caching is controlled by the query context parameters `useCache` and `populateCache`
-and [runtime properties](../configuration/index.md) `druid.realtime.cache.*`.
+ Do not use segment caches on the Broker for large production clusters. When `druid.broker.cache.populateCache` is `true` and query context parameter `populateCache` _is not_ `false`, Historicals return results on a per-segment basis without merging results locally thus negatively impacting cluster scalability.
+
+- On Historicals, the default. Enable segment-level cache population on Historicals for larger production clusters to prevent Brokers from having to merge all query results. When you enable cache population on Historicals instead of Brokers, the Historicals merge their own local results and put less strain on the Brokers.
+
+- On ingestion tasks in the Peon or Indexer service. Larger production clusters should enable segment-level cache population on task execution services only to prevent Brokers from having to merge all query results. When you enable cache population on task execution services instead of Brokers, the the task execution services to merge their own local results and put less strain on the Brokers.
+
+ Task executor services only support caches that store data locally. For example the `caffeine` cache. This restriction exists because the cache stores results at the level of intermediate partial segments generated by the ingestion tasks. These intermediate partial segments may not be identical across task replicas. Therefore task executor services ignore remote cache types such as `memcached`.
+
+**Whole-query cache** is only available on Brokers.
+
+## Performance considerations for caching
+
+Consider the following as you develop your caching strategy:
+- Caching enables increased concurrency on the same system, therefore leading to noticeable performance improvements for queries on Druid clusters handling throughput for concurrent, mixed workloads.
+
+- If you are looking to improve response time for a single query or page load, you should ignore caching. In general, response time for a single task should meet performance objectives even when the cache is cold.
+
+- During query processing, the segment cache intercepts the query and sends the results directly to the Broker. This way the query bypasses the data server processing threads. For queries requiring minimal processing in the Broker, cached queries are very quick. If work done on the Broker causes a query bottleneck, enabling caching results in little noticeable query improvement.
+
+- The largest performance gains from segment caching tend to apply to `topN` and time series queries. The impact is less for `groupBy` queries. The same applies to queries with or without joins.
+
+### Scenarios where caching does not increase query performance
+
+Caching does not solve all types of query peformance issues. For each cache type there are scenarios where caching is likely to be of little benefit.
+
+**Segment caching** doesn't work for TBD.
Review comment:
https://github.com/abhishekagarwal87/druid/blob/7e94c7a8595d922edc6cc60737db4be8c749c928/docs/querying/caching.md#unsupported-queries
^ I have documented here but it was removed in https://github.com/apache/druid/pull/10528/files. Not sure why.
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +22,75 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently accessed data. This topic defines the different types of caching for Druid. It describes the default caching behavior and provides guidance and examples to help you hone your caching strategy.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+If you're unfamiliar with Druid architecture, review the following topics before proceeding with caching:
+- [Druid Design](../design/architecture.md)
+- [Segments](../design/segments.md)
+- [Query execution](./query-execution)
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+For instructions to configure caching see [Using query caching](./using-caching.md).
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports segment caching which stores _partial results_ of a query for a specific segment, and whole-query caching which stores all results for a query. To avoid returning stale results, Druid invalidates the cache the moment any underlying data changes for both types of cache.
Review comment:
We should call it "per-segment query caching" instead of `segment caching`. Reason being that within druid, segment cache refers to the segments on data servers' disks that are downloaded from the deep storage.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] techdocsmith commented on a change in pull request #10848: refactor query caching docs
Posted by GitBox <gi...@apache.org>.
techdocsmith commented on a change in pull request #10848:
URL: https://github.com/apache/druid/pull/10848#discussion_r588555745
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +22,75 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently accessed data. This topic defines the different types of caching for Druid. It describes the default caching behavior and provides guidance and examples to help you hone your caching strategy.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+If you're unfamiliar with Druid architecture, review the following topics before proceeding with caching:
+- [Druid Design](../design/architecture.md)
+- [Segments](../design/segments.md)
+- [Query execution](./query-execution)
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+For instructions to configure caching see [Using query caching](./using-caching.md).
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports segment caching which stores _partial results_ of a query for a specific segment, and whole-query caching which stores all results for a query. To avoid returning stale results, Druid invalidates the cache the moment any underlying data changes for both types of cache.
Review comment:
this was there: `whole-query caching which stores all results for a query. Separated these out into bullets to make it clearer. Added that per-segment caching is on for Historicals by default.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] sthetland commented on a change in pull request #10848: refactor query caching docs
Posted by GitBox <gi...@apache.org>.
sthetland commented on a change in pull request #10848:
URL: https://github.com/apache/druid/pull/10848#discussion_r569873583
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +22,61 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently-accessed data.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+When considering a caching strategy consider the following:
+- Caching enables increased concurrency on the same system, therefore leading to noticeable performance improvements for queries on Druid clusters handling throughput for concurrent, mixed workloads.
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+- If you are looking to improve response time for a single query or page load, you should ignore caching. In general, response time for a single task should meet performance objectives even when the cache is cold.
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports the following types of query result caching:
+- **Segment cache** stores _partial results_ of a query for a specific segment.
+- **Whole-query cache** stores all results for a query.
-## Using and populating cache
+To avoid returning stale results, Druid invalidates a cache the moment any underlying data changes regardless of the cache type.
-All caches have a pair of parameters that control the behavior of how individual queries interact with the cache, a 'use' cache parameter, and a 'populate' cache parameter. These settings must be enabled at the service level via [runtime properties](../configuration/index.md) to utilize cache, but can be controlled on a per query basis by setting them on the [query context](../querying/query-context.md). The 'use' parameter obviously controls if a query will utilize cached results. The 'populate' parameter controls if a query will update cached results. These are separate parameters to allow queries on uncommon data to utilize cached results without polluting the cache with results that are unlikely to be re-used by other queries, for example large reports or very old data.
+The primary form of caching in Druid is the segment cache. The segment cache stores query results on a per-segment basis. It is enabled on Historical services by default.
-## Query caching on Brokers
+During query processing, the segment cache intercepts query to bypass the data server processing threads and sends the results directly to the Broker. For queries require minimal processing in the Broker, cached queries are very quick. If work done on the Broker causes a query bottleneck, enabling caching results in little noticeable query improvement.
Review comment:
```suggestion
During query processing, the segment cache intercepts the query, so that it bypasses the data server processing threads, and sends the results directly to the Broker. For queries requiring minimal processing in the Broker, cached queries are very quick. If work done on the Broker causes a query bottleneck, enabling caching results in little noticeable query improvement.
```
Not 100% sure about my edit of the first sentence here, but it's based on my assumption that it's the query that is bypassing threads, not the segment cache, so clarifying on that assumption.
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +22,61 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently-accessed data.
Review comment:
```suggestion
You can enable caching in Apache Druid to improve query times for frequently accessed data.
```
(the old `-ly` hyphen exemption)
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,90 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
Review comment:
```suggestion
This topic covers how to configure services to populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
```
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,90 @@
+---
+id: using-caching
+title: "Using query caching"
Review comment:
just a thought: this page is now entirely config instructions, but it appears under a "Concepts" heading in the left TOC. Not sure how much of an issue that is -- there are other config instructions under that heading -- but it's more apparent now with this standalone page.. We might want to rethink that heading or page locations in the TOC, perhaps in another PR.
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,90 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cached for results.
+- `populateCache` to instruct a query to cache its results.
+
+The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example large reports or queries on very old data.
+
+To use caching, you must first enable the settings for a service in the runtime properties. Afterward, you can control which queries use the cache or populate the cache on a per-query basis within the query context.
+
+The query context settings do not override the server settings. For example, it is possible to set a query context to use the cache, but if it is not enabled at the service level, there's no cache to use.
+
+## Enabling query caching on Brokers
+Brokers support both segment-level and whole-query result level caching.
+
+To control **segment caching** on the Broker, set the `useCache` and `populateCache`runtime properties. For example, to set the Broker to both use and populate the segment cache for queries:
+```
+druid.broker.cache.useCache=true
+druid.broker.cache.populateCache=true
+```
+To control **whole-query caching** on the Broker, set the`useResultLevelCache` and `populateResultLevelCache` runtime properties. For example, to set the Broker to both use and populate the whole-query cache for queries:
+```
+druid.broker.cache.useResultLevelCache=true
+druid.broker.cache.populateResultLevelCache=true
+```
+See [Broker caching](../configuration/index.md#broker-caching) for a description of all available Broker cache configurations.
+
+## Enabling query caching on Historicals
+Historicals only support **segment-level** caching. To control caching on the Historical, set the `useCache` and `populateCache` runtime properties. For example, to set the Historical to both use and populate the segment cache for queries:
+ ```
+ druid.broker.cache.useCache=true
+ druid.broker.cache.populateCache=true
+ ```
+See [Historical caching](../configuration/index.md#historical-caching) for a description of all available Historical cache configurations.
+
+## Enabling query caching on task executor services
+Task executor services, the Peon or the Indexer, only support **segment-level** caching. To control caching on a taske executor service, set the `useCache` and `populateCache` runtime properties. For example, to set the Peon to both use and populate the segment cache for queries:
+
+```
+druid.realtime.cache.useCache=true
+druid.realtime.cache.populateCache=true
+```
+
+See [Peon caching](configuration/index.md#peon-caching) for a description of all available task exector service caching options.
+
+## Enabling caching in the query context
+After you enable cacheing for a service, set cache options for individual queries in the query [context](./query-context.md). For example, you can `POST` a Druid SQL request to the HTTP POST API and include the context as a JSON object:
+
+```
+{
+ "query" : "SELECT COUNT(*) FROM data_source WHERE foo = 'bar' AND __time > TIMESTAMP '2020-01-01 00:00:00'",
+ "context" : {
+ "useCache" : "true",
+ "populateCache" : "false"
+ }
+}
+```
+In this example `populateCahce` is `false` because the query references data that is over a year old. For more information, see [Druid SQL client APIs](./sql.html#client-apis).
+
+## Learn more
+See the following topics for more information:
+- [Query caching](./caching.md) for an overview of caching.
+- [Query context](./query-context.md)
Review comment:
For consistency, this link could use a few words of description
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +22,61 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently-accessed data.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+When considering a caching strategy consider the following:
+- Caching enables increased concurrency on the same system, therefore leading to noticeable performance improvements for queries on Druid clusters handling throughput for concurrent, mixed workloads.
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+- If you are looking to improve response time for a single query or page load, you should ignore caching. In general, response time for a single task should meet performance objectives even when the cache is cold.
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports the following types of query result caching:
+- **Segment cache** stores _partial results_ of a query for a specific segment.
+- **Whole-query cache** stores all results for a query.
-## Using and populating cache
+To avoid returning stale results, Druid invalidates a cache the moment any underlying data changes regardless of the cache type.
-All caches have a pair of parameters that control the behavior of how individual queries interact with the cache, a 'use' cache parameter, and a 'populate' cache parameter. These settings must be enabled at the service level via [runtime properties](../configuration/index.md) to utilize cache, but can be controlled on a per query basis by setting them on the [query context](../querying/query-context.md). The 'use' parameter obviously controls if a query will utilize cached results. The 'populate' parameter controls if a query will update cached results. These are separate parameters to allow queries on uncommon data to utilize cached results without polluting the cache with results that are unlikely to be re-used by other queries, for example large reports or very old data.
+The primary form of caching in Druid is the segment cache. The segment cache stores query results on a per-segment basis. It is enabled on Historical services by default.
-## Query caching on Brokers
+During query processing, the segment cache intercepts query to bypass the data server processing threads and sends the results directly to the Broker. For queries require minimal processing in the Broker, cached queries are very quick. If work done on the Broker causes a query bottleneck, enabling caching results in little noticeable query improvement.
-Brokers support both segment-level and whole-query result level caching. Segment-level caching is controlled by the
-parameters `useCache` and `populateCache`. Whole-query result level caching is controlled by the parameters
-`useResultLevelCache` and `populateResultLevelCache` and [runtime properties](../configuration/index.md)
-`druid.broker.cache.*`.
+The largest performance gains from caching tend to apply to `topN` and time series queries. The impact is less for `groupBy` queries. The same applies to queries with or without joins.
-Enabling segment-level caching on the Broker can yield faster results than if query caches were enabled on Historicals for small
-clusters. This is the recommended setup for smaller production clusters (< 5 servers). Populating segment-level caches on
-the Broker is _not_ recommended for large production clusters, since when the property `druid.broker.cache.populateCache` is
-set to `true` (and query context parameter `populateCache` is _not_ set to `false`), results from Historicals are returned
-on a per segment basis, and Historicals will not be able to do any local result merging. This impairs the ability of the
-Druid cluster to scale well.
+If you're unfamiliar with Druid architecture, review the following topics before proceeding with caching:
Review comment:
These next three links seem like they would go better at the end of the intro section, rather than here where it's already gotten into the page topic. Also, the same links are repeated at the end. I would probably just have them once, either at the end of the intro section or as they are at the end, as a more info section.
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,90 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cached for results.
+- `populateCache` to instruct a query to cache its results.
+
+The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example large reports or queries on very old data.
+
+To use caching, you must first enable the settings for a service in the runtime properties. Afterward, you can control which queries use the cache or populate the cache on a per-query basis within the query context.
+
+The query context settings do not override the server settings. For example, it is possible to set a query context to use the cache, but if it is not enabled at the service level, there's no cache to use.
+
+## Enabling query caching on Brokers
+Brokers support both segment-level and whole-query result level caching.
+
+To control **segment caching** on the Broker, set the `useCache` and `populateCache`runtime properties. For example, to set the Broker to both use and populate the segment cache for queries:
Review comment:
```suggestion
To control **segment caching** on the Broker, set the `useCache` and `populateCache`runtime properties. For example, to set the Broker to use and populate the segment cache for queries:
```
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +22,61 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently-accessed data.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+When considering a caching strategy consider the following:
+- Caching enables increased concurrency on the same system, therefore leading to noticeable performance improvements for queries on Druid clusters handling throughput for concurrent, mixed workloads.
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+- If you are looking to improve response time for a single query or page load, you should ignore caching. In general, response time for a single task should meet performance objectives even when the cache is cold.
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports the following types of query result caching:
+- **Segment cache** stores _partial results_ of a query for a specific segment.
+- **Whole-query cache** stores all results for a query.
-## Using and populating cache
+To avoid returning stale results, Druid invalidates a cache the moment any underlying data changes regardless of the cache type.
-All caches have a pair of parameters that control the behavior of how individual queries interact with the cache, a 'use' cache parameter, and a 'populate' cache parameter. These settings must be enabled at the service level via [runtime properties](../configuration/index.md) to utilize cache, but can be controlled on a per query basis by setting them on the [query context](../querying/query-context.md). The 'use' parameter obviously controls if a query will utilize cached results. The 'populate' parameter controls if a query will update cached results. These are separate parameters to allow queries on uncommon data to utilize cached results without polluting the cache with results that are unlikely to be re-used by other queries, for example large reports or very old data.
+The primary form of caching in Druid is the segment cache. The segment cache stores query results on a per-segment basis. It is enabled on Historical services by default.
-## Query caching on Brokers
+During query processing, the segment cache intercepts query to bypass the data server processing threads and sends the results directly to the Broker. For queries require minimal processing in the Broker, cached queries are very quick. If work done on the Broker causes a query bottleneck, enabling caching results in little noticeable query improvement.
-Brokers support both segment-level and whole-query result level caching. Segment-level caching is controlled by the
-parameters `useCache` and `populateCache`. Whole-query result level caching is controlled by the parameters
-`useResultLevelCache` and `populateResultLevelCache` and [runtime properties](../configuration/index.md)
-`druid.broker.cache.*`.
+The largest performance gains from caching tend to apply to `topN` and time series queries. The impact is less for `groupBy` queries. The same applies to queries with or without joins.
-Enabling segment-level caching on the Broker can yield faster results than if query caches were enabled on Historicals for small
-clusters. This is the recommended setup for smaller production clusters (< 5 servers). Populating segment-level caches on
-the Broker is _not_ recommended for large production clusters, since when the property `druid.broker.cache.populateCache` is
-set to `true` (and query context parameter `populateCache` is _not_ set to `false`), results from Historicals are returned
-on a per segment basis, and Historicals will not be able to do any local result merging. This impairs the ability of the
-Druid cluster to scale well.
+If you're unfamiliar with Druid architecture, review the following topics before proceeding with caching:
+- [Druid Design](../design/architecture.md)
+- [Segments](../design/segments.md)
-## Query caching on Historicals
+To learn how to configure and use caching see [Using query caching](./using-caching.md).
-Historicals only support segment-level caching. Segment-level caching is controlled by the query context
-parameters `useCache` and `populateCache` and [runtime properties](../configuration/index.md)
-`druid.historical.cache.*`.
+## Choosing a cache type
-Larger production clusters should enable segment-level cache population on Historicals only (not on Brokers) to avoid
-having to use Brokers to merge all query results. Enabling cache population on the Historicals instead of the Brokers
-enables the Historicals to do their own local result merging and puts less strain on the Brokers.
+When your queries include data from segments that are mutable and undergoing real-time ingestion, use a **segment cache**. In this case Druid caches query results for immutable historical segments when possible. It re-computes results for the real-time segments at query time.
-## Query caching on Ingestion Tasks
+For example, you have queries that frequently include incoming data from a Kafka or Kinesis stream alongside unchanging segments. Whole-query caching is not helpful in this scenario because the new data from real-time ingestion continually invalidates the cache. Segment caching lets Druid cache results from older immutable segments and merge them with updated data.
-Task executor processes such as the Peon or the experimental Indexer only support segment-level caching. Segment-level
-caching is controlled by the query context parameters `useCache` and `populateCache`
-and [runtime properties](../configuration/index.md) `druid.realtime.cache.*`.
+Segment caching requires Druid to merge the per-segment results for each query, even when the results are cached. If real-time ingestion invalidating the cache is not an issue for your queries, you can use **whole-query caching** to increase query efficiency. For instance, whole-query caching is a good option when you have queries that include data from a batch ingestion task that runs every few hours or once a day.
+
+## Where to enable caching
+
+**Segment cache** is available as follows:
+- On Brokers and on Historicals both for small
Review comment:
```suggestion
- On both Brokers and Historicals for small
```
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +22,61 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently-accessed data.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+When considering a caching strategy consider the following:
+- Caching enables increased concurrency on the same system, therefore leading to noticeable performance improvements for queries on Druid clusters handling throughput for concurrent, mixed workloads.
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+- If you are looking to improve response time for a single query or page load, you should ignore caching. In general, response time for a single task should meet performance objectives even when the cache is cold.
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports the following types of query result caching:
+- **Segment cache** stores _partial results_ of a query for a specific segment.
+- **Whole-query cache** stores all results for a query.
-## Using and populating cache
+To avoid returning stale results, Druid invalidates a cache the moment any underlying data changes regardless of the cache type.
-All caches have a pair of parameters that control the behavior of how individual queries interact with the cache, a 'use' cache parameter, and a 'populate' cache parameter. These settings must be enabled at the service level via [runtime properties](../configuration/index.md) to utilize cache, but can be controlled on a per query basis by setting them on the [query context](../querying/query-context.md). The 'use' parameter obviously controls if a query will utilize cached results. The 'populate' parameter controls if a query will update cached results. These are separate parameters to allow queries on uncommon data to utilize cached results without polluting the cache with results that are unlikely to be re-used by other queries, for example large reports or very old data.
+The primary form of caching in Druid is the segment cache. The segment cache stores query results on a per-segment basis. It is enabled on Historical services by default.
-## Query caching on Brokers
+During query processing, the segment cache intercepts query to bypass the data server processing threads and sends the results directly to the Broker. For queries require minimal processing in the Broker, cached queries are very quick. If work done on the Broker causes a query bottleneck, enabling caching results in little noticeable query improvement.
-Brokers support both segment-level and whole-query result level caching. Segment-level caching is controlled by the
-parameters `useCache` and `populateCache`. Whole-query result level caching is controlled by the parameters
-`useResultLevelCache` and `populateResultLevelCache` and [runtime properties](../configuration/index.md)
-`druid.broker.cache.*`.
+The largest performance gains from caching tend to apply to `topN` and time series queries. The impact is less for `groupBy` queries. The same applies to queries with or without joins.
-Enabling segment-level caching on the Broker can yield faster results than if query caches were enabled on Historicals for small
-clusters. This is the recommended setup for smaller production clusters (< 5 servers). Populating segment-level caches on
-the Broker is _not_ recommended for large production clusters, since when the property `druid.broker.cache.populateCache` is
-set to `true` (and query context parameter `populateCache` is _not_ set to `false`), results from Historicals are returned
-on a per segment basis, and Historicals will not be able to do any local result merging. This impairs the ability of the
-Druid cluster to scale well.
+If you're unfamiliar with Druid architecture, review the following topics before proceeding with caching:
+- [Druid Design](../design/architecture.md)
+- [Segments](../design/segments.md)
-## Query caching on Historicals
+To learn how to configure and use caching see [Using query caching](./using-caching.md).
-Historicals only support segment-level caching. Segment-level caching is controlled by the query context
-parameters `useCache` and `populateCache` and [runtime properties](../configuration/index.md)
-`druid.historical.cache.*`.
+## Choosing a cache type
-Larger production clusters should enable segment-level cache population on Historicals only (not on Brokers) to avoid
-having to use Brokers to merge all query results. Enabling cache population on the Historicals instead of the Brokers
-enables the Historicals to do their own local result merging and puts less strain on the Brokers.
+When your queries include data from segments that are mutable and undergoing real-time ingestion, use a **segment cache**. In this case Druid caches query results for immutable historical segments when possible. It re-computes results for the real-time segments at query time.
-## Query caching on Ingestion Tasks
+For example, you have queries that frequently include incoming data from a Kafka or Kinesis stream alongside unchanging segments. Whole-query caching is not helpful in this scenario because the new data from real-time ingestion continually invalidates the cache. Segment caching lets Druid cache results from older immutable segments and merge them with updated data.
-Task executor processes such as the Peon or the experimental Indexer only support segment-level caching. Segment-level
-caching is controlled by the query context parameters `useCache` and `populateCache`
-and [runtime properties](../configuration/index.md) `druid.realtime.cache.*`.
+Segment caching requires Druid to merge the per-segment results for each query, even when the results are cached. If real-time ingestion invalidating the cache is not an issue for your queries, you can use **whole-query caching** to increase query efficiency. For instance, whole-query caching is a good option when you have queries that include data from a batch ingestion task that runs every few hours or once a day.
+
+## Where to enable caching
+
+**Segment cache** is available as follows:
+- On Brokers and on Historicals both for small
+clusters. Use this configuration for smaller production clusters (< 5 servers).
+
+ Do not use segment caches on the Broker for large production clusters. When `druid.broker.cache.populateCache` is `true` and query context parameter `populateCache` _is not_ `false`, Historicals return results on a per-segment basis without merging results locally thus negatively impacting cluster scalability.
+
+- On Historicals only, the default. Enable segment-level cache population on Historicals only for larger production clusters to prevent Brokers having to merge all query results. When you enable cache population on Historicals instead of Brokers, the Historicals merge their own local results and put less strain on the Brokers.
Review comment:
```suggestion
- On Historicals only, the default. Enable segment-level cache population on Historicals only for larger production clusters to prevent Brokers from having to merge all query results. When you enable cache population on Historicals instead of Brokers, the Historicals merge their own local results and put less strain on the Brokers.
```
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +22,61 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently-accessed data.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+When considering a caching strategy consider the following:
+- Caching enables increased concurrency on the same system, therefore leading to noticeable performance improvements for queries on Druid clusters handling throughput for concurrent, mixed workloads.
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+- If you are looking to improve response time for a single query or page load, you should ignore caching. In general, response time for a single task should meet performance objectives even when the cache is cold.
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports the following types of query result caching:
+- **Segment cache** stores _partial results_ of a query for a specific segment.
+- **Whole-query cache** stores all results for a query.
-## Using and populating cache
+To avoid returning stale results, Druid invalidates a cache the moment any underlying data changes regardless of the cache type.
-All caches have a pair of parameters that control the behavior of how individual queries interact with the cache, a 'use' cache parameter, and a 'populate' cache parameter. These settings must be enabled at the service level via [runtime properties](../configuration/index.md) to utilize cache, but can be controlled on a per query basis by setting them on the [query context](../querying/query-context.md). The 'use' parameter obviously controls if a query will utilize cached results. The 'populate' parameter controls if a query will update cached results. These are separate parameters to allow queries on uncommon data to utilize cached results without polluting the cache with results that are unlikely to be re-used by other queries, for example large reports or very old data.
+The primary form of caching in Druid is the segment cache. The segment cache stores query results on a per-segment basis. It is enabled on Historical services by default.
-## Query caching on Brokers
+During query processing, the segment cache intercepts query to bypass the data server processing threads and sends the results directly to the Broker. For queries require minimal processing in the Broker, cached queries are very quick. If work done on the Broker causes a query bottleneck, enabling caching results in little noticeable query improvement.
-Brokers support both segment-level and whole-query result level caching. Segment-level caching is controlled by the
-parameters `useCache` and `populateCache`. Whole-query result level caching is controlled by the parameters
-`useResultLevelCache` and `populateResultLevelCache` and [runtime properties](../configuration/index.md)
-`druid.broker.cache.*`.
+The largest performance gains from caching tend to apply to `topN` and time series queries. The impact is less for `groupBy` queries. The same applies to queries with or without joins.
-Enabling segment-level caching on the Broker can yield faster results than if query caches were enabled on Historicals for small
-clusters. This is the recommended setup for smaller production clusters (< 5 servers). Populating segment-level caches on
-the Broker is _not_ recommended for large production clusters, since when the property `druid.broker.cache.populateCache` is
-set to `true` (and query context parameter `populateCache` is _not_ set to `false`), results from Historicals are returned
-on a per segment basis, and Historicals will not be able to do any local result merging. This impairs the ability of the
-Druid cluster to scale well.
+If you're unfamiliar with Druid architecture, review the following topics before proceeding with caching:
+- [Druid Design](../design/architecture.md)
+- [Segments](../design/segments.md)
-## Query caching on Historicals
+To learn how to configure and use caching see [Using query caching](./using-caching.md).
-Historicals only support segment-level caching. Segment-level caching is controlled by the query context
-parameters `useCache` and `populateCache` and [runtime properties](../configuration/index.md)
-`druid.historical.cache.*`.
+## Choosing a cache type
-Larger production clusters should enable segment-level cache population on Historicals only (not on Brokers) to avoid
-having to use Brokers to merge all query results. Enabling cache population on the Historicals instead of the Brokers
-enables the Historicals to do their own local result merging and puts less strain on the Brokers.
+When your queries include data from segments that are mutable and undergoing real-time ingestion, use a **segment cache**. In this case Druid caches query results for immutable historical segments when possible. It re-computes results for the real-time segments at query time.
-## Query caching on Ingestion Tasks
+For example, you have queries that frequently include incoming data from a Kafka or Kinesis stream alongside unchanging segments. Whole-query caching is not helpful in this scenario because the new data from real-time ingestion continually invalidates the cache. Segment caching lets Druid cache results from older immutable segments and merge them with updated data.
-Task executor processes such as the Peon or the experimental Indexer only support segment-level caching. Segment-level
-caching is controlled by the query context parameters `useCache` and `populateCache`
-and [runtime properties](../configuration/index.md) `druid.realtime.cache.*`.
+Segment caching requires Druid to merge the per-segment results for each query, even when the results are cached. If real-time ingestion invalidating the cache is not an issue for your queries, you can use **whole-query caching** to increase query efficiency. For instance, whole-query caching is a good option when you have queries that include data from a batch ingestion task that runs every few hours or once a day.
+
+## Where to enable caching
+
+**Segment cache** is available as follows:
+- On Brokers and on Historicals both for small
+clusters. Use this configuration for smaller production clusters (< 5 servers).
+
+ Do not use segment caches on the Broker for large production clusters. When `druid.broker.cache.populateCache` is `true` and query context parameter `populateCache` _is not_ `false`, Historicals return results on a per-segment basis without merging results locally thus negatively impacting cluster scalability.
+
+- On Historicals only, the default. Enable segment-level cache population on Historicals only for larger production clusters to prevent Brokers having to merge all query results. When you enable cache population on Historicals instead of Brokers, the Historicals merge their own local results and put less strain on the Brokers.
+
+- On ingestion tasks in the Peon or Indexer service only. Larger production clusters should enable segment-level cache population on task execution services only to prevent Brokers having to merge all query results. When you enable cache population on task execution services instead of Brokers, the the task execution services to merge their own local results and put less strain on the brokers.
Review comment:
```suggestion
- On ingestion tasks in the Peon or Indexer service only. Larger production clusters should enable segment-level cache population on task execution services only to prevent Brokers having to merge all query results. When you enable cache population on task execution services instead of Brokers, the task execution services merge their own local results, putting less strain on the brokers.
```
##########
File path: docs/querying/caching.md
##########
@@ -1,5 +1,5 @@
---
-id: caching
+id: using-caching
Review comment:
I think this was an unintentional change? This is the same ID value as the next file, which may be why this page doesn't appear in the sidebar TOC. (It might need to be added to sidebars.json as well)
```suggestion
id: caching
```
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,90 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cached for results.
+- `populateCache` to instruct a query to cache its results.
+
+The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example large reports or queries on very old data.
+
+To use caching, you must first enable the settings for a service in the runtime properties. Afterward, you can control which queries use the cache or populate the cache on a per-query basis within the query context.
+
+The query context settings do not override the server settings. For example, it is possible to set a query context to use the cache, but if it is not enabled at the service level, there's no cache to use.
+
+## Enabling query caching on Brokers
+Brokers support both segment-level and whole-query result level caching.
+
+To control **segment caching** on the Broker, set the `useCache` and `populateCache`runtime properties. For example, to set the Broker to both use and populate the segment cache for queries:
+```
+druid.broker.cache.useCache=true
+druid.broker.cache.populateCache=true
+```
+To control **whole-query caching** on the Broker, set the`useResultLevelCache` and `populateResultLevelCache` runtime properties. For example, to set the Broker to both use and populate the whole-query cache for queries:
+```
+druid.broker.cache.useResultLevelCache=true
+druid.broker.cache.populateResultLevelCache=true
+```
+See [Broker caching](../configuration/index.md#broker-caching) for a description of all available Broker cache configurations.
+
+## Enabling query caching on Historicals
+Historicals only support **segment-level** caching. To control caching on the Historical, set the `useCache` and `populateCache` runtime properties. For example, to set the Historical to both use and populate the segment cache for queries:
+ ```
+ druid.broker.cache.useCache=true
+ druid.broker.cache.populateCache=true
+ ```
+See [Historical caching](../configuration/index.md#historical-caching) for a description of all available Historical cache configurations.
+
+## Enabling query caching on task executor services
+Task executor services, the Peon or the Indexer, only support **segment-level** caching. To control caching on a taske executor service, set the `useCache` and `populateCache` runtime properties. For example, to set the Peon to both use and populate the segment cache for queries:
+
+```
+druid.realtime.cache.useCache=true
+druid.realtime.cache.populateCache=true
+```
+
+See [Peon caching](configuration/index.md#peon-caching) for a description of all available task exector service caching options.
+
+## Enabling caching in the query context
+After you enable cacheing for a service, set cache options for individual queries in the query [context](./query-context.md). For example, you can `POST` a Druid SQL request to the HTTP POST API and include the context as a JSON object:
+
+```
+{
+ "query" : "SELECT COUNT(*) FROM data_source WHERE foo = 'bar' AND __time > TIMESTAMP '2020-01-01 00:00:00'",
+ "context" : {
+ "useCache" : "true",
+ "populateCache" : "false"
+ }
+}
+```
+In this example `populateCahce` is `false` because the query references data that is over a year old. For more information, see [Druid SQL client APIs](./sql.html#client-apis).
Review comment:
```suggestion
In this example `populateCache` is `false` because the query references data that is over a year old. For more information, see [Druid SQL client APIs](./sql.md#client-apis).
```
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,90 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cached for results.
+- `populateCache` to instruct a query to cache its results.
+
+The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example large reports or queries on very old data.
+
+To use caching, you must first enable the settings for a service in the runtime properties. Afterward, you can control which queries use the cache or populate the cache on a per-query basis within the query context.
+
+The query context settings do not override the server settings. For example, it is possible to set a query context to use the cache, but if it is not enabled at the service level, there's no cache to use.
+
+## Enabling query caching on Brokers
+Brokers support both segment-level and whole-query result level caching.
+
+To control **segment caching** on the Broker, set the `useCache` and `populateCache`runtime properties. For example, to set the Broker to both use and populate the segment cache for queries:
+```
+druid.broker.cache.useCache=true
+druid.broker.cache.populateCache=true
+```
+To control **whole-query caching** on the Broker, set the`useResultLevelCache` and `populateResultLevelCache` runtime properties. For example, to set the Broker to both use and populate the whole-query cache for queries:
+```
+druid.broker.cache.useResultLevelCache=true
+druid.broker.cache.populateResultLevelCache=true
+```
+See [Broker caching](../configuration/index.md#broker-caching) for a description of all available Broker cache configurations.
+
+## Enabling query caching on Historicals
+Historicals only support **segment-level** caching. To control caching on the Historical, set the `useCache` and `populateCache` runtime properties. For example, to set the Historical to both use and populate the segment cache for queries:
+ ```
+ druid.broker.cache.useCache=true
+ druid.broker.cache.populateCache=true
+ ```
+See [Historical caching](../configuration/index.md#historical-caching) for a description of all available Historical cache configurations.
+
+## Enabling query caching on task executor services
+Task executor services, the Peon or the Indexer, only support **segment-level** caching. To control caching on a taske executor service, set the `useCache` and `populateCache` runtime properties. For example, to set the Peon to both use and populate the segment cache for queries:
Review comment:
```suggestion
Task executor services, the Peon or the Indexer, only support **segment-level** caching. To control caching on a task executor service, set the `useCache` and `populateCache` runtime properties. For example, to set the Peon to use and populate the segment cache for queries:
```
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,90 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cached for results.
+- `populateCache` to instruct a query to cache its results.
+
+The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example large reports or queries on very old data.
Review comment:
```suggestion
The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example, large reports or queries on very old data.
```
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,90 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cached for results.
+- `populateCache` to instruct a query to cache its results.
+
+The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example large reports or queries on very old data.
+
+To use caching, you must first enable the settings for a service in the runtime properties. Afterward, you can control which queries use the cache or populate the cache on a per-query basis within the query context.
+
+The query context settings do not override the server settings. For example, it is possible to set a query context to use the cache, but if it is not enabled at the service level, there's no cache to use.
+
+## Enabling query caching on Brokers
+Brokers support both segment-level and whole-query result level caching.
+
+To control **segment caching** on the Broker, set the `useCache` and `populateCache`runtime properties. For example, to set the Broker to both use and populate the segment cache for queries:
+```
+druid.broker.cache.useCache=true
+druid.broker.cache.populateCache=true
+```
+To control **whole-query caching** on the Broker, set the`useResultLevelCache` and `populateResultLevelCache` runtime properties. For example, to set the Broker to both use and populate the whole-query cache for queries:
+```
+druid.broker.cache.useResultLevelCache=true
+druid.broker.cache.populateResultLevelCache=true
+```
+See [Broker caching](../configuration/index.md#broker-caching) for a description of all available Broker cache configurations.
+
+## Enabling query caching on Historicals
+Historicals only support **segment-level** caching. To control caching on the Historical, set the `useCache` and `populateCache` runtime properties. For example, to set the Historical to both use and populate the segment cache for queries:
+ ```
+ druid.broker.cache.useCache=true
+ druid.broker.cache.populateCache=true
+ ```
+See [Historical caching](../configuration/index.md#historical-caching) for a description of all available Historical cache configurations.
+
+## Enabling query caching on task executor services
+Task executor services, the Peon or the Indexer, only support **segment-level** caching. To control caching on a taske executor service, set the `useCache` and `populateCache` runtime properties. For example, to set the Peon to both use and populate the segment cache for queries:
+
+```
+druid.realtime.cache.useCache=true
+druid.realtime.cache.populateCache=true
+```
+
+See [Peon caching](configuration/index.md#peon-caching) for a description of all available task exector service caching options.
Review comment:
```suggestion
See [Peon caching](configuration/index.md#peon-caching) for a description of all available task executor service caching options.
```
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,90 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cached for results.
+- `populateCache` to instruct a query to cache its results.
+
+The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example large reports or queries on very old data.
+
+To use caching, you must first enable the settings for a service in the runtime properties. Afterward, you can control which queries use the cache or populate the cache on a per-query basis within the query context.
+
+The query context settings do not override the server settings. For example, it is possible to set a query context to use the cache, but if it is not enabled at the service level, there's no cache to use.
+
+## Enabling query caching on Brokers
+Brokers support both segment-level and whole-query result level caching.
+
+To control **segment caching** on the Broker, set the `useCache` and `populateCache`runtime properties. For example, to set the Broker to both use and populate the segment cache for queries:
+```
+druid.broker.cache.useCache=true
+druid.broker.cache.populateCache=true
+```
+To control **whole-query caching** on the Broker, set the`useResultLevelCache` and `populateResultLevelCache` runtime properties. For example, to set the Broker to both use and populate the whole-query cache for queries:
+```
+druid.broker.cache.useResultLevelCache=true
+druid.broker.cache.populateResultLevelCache=true
+```
+See [Broker caching](../configuration/index.md#broker-caching) for a description of all available Broker cache configurations.
+
+## Enabling query caching on Historicals
+Historicals only support **segment-level** caching. To control caching on the Historical, set the `useCache` and `populateCache` runtime properties. For example, to set the Historical to both use and populate the segment cache for queries:
+ ```
+ druid.broker.cache.useCache=true
+ druid.broker.cache.populateCache=true
+ ```
+See [Historical caching](../configuration/index.md#historical-caching) for a description of all available Historical cache configurations.
+
+## Enabling query caching on task executor services
+Task executor services, the Peon or the Indexer, only support **segment-level** caching. To control caching on a taske executor service, set the `useCache` and `populateCache` runtime properties. For example, to set the Peon to both use and populate the segment cache for queries:
+
+```
+druid.realtime.cache.useCache=true
+druid.realtime.cache.populateCache=true
+```
+
+See [Peon caching](configuration/index.md#peon-caching) for a description of all available task exector service caching options.
+
+## Enabling caching in the query context
+After you enable cacheing for a service, set cache options for individual queries in the query [context](./query-context.md). For example, you can `POST` a Druid SQL request to the HTTP POST API and include the context as a JSON object:
Review comment:
```suggestion
After you enable caching for a service, set cache options for individual queries in the query [context](./query-context.md). For example, you can `POST` a Druid SQL request to the HTTP POST API and include the context as a JSON object:
```
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,90 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cached for results.
+- `populateCache` to instruct a query to cache its results.
+
+The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example large reports or queries on very old data.
+
+To use caching, you must first enable the settings for a service in the runtime properties. Afterward, you can control which queries use the cache or populate the cache on a per-query basis within the query context.
+
+The query context settings do not override the server settings. For example, it is possible to set a query context to use the cache, but if it is not enabled at the service level, there's no cache to use.
+
+## Enabling query caching on Brokers
+Brokers support both segment-level and whole-query result level caching.
+
+To control **segment caching** on the Broker, set the `useCache` and `populateCache`runtime properties. For example, to set the Broker to both use and populate the segment cache for queries:
+```
+druid.broker.cache.useCache=true
+druid.broker.cache.populateCache=true
+```
+To control **whole-query caching** on the Broker, set the`useResultLevelCache` and `populateResultLevelCache` runtime properties. For example, to set the Broker to both use and populate the whole-query cache for queries:
Review comment:
```suggestion
To control **whole-query caching** on the Broker, set the `useResultLevelCache` and `populateResultLevelCache` runtime properties. For example, to set the Broker to use and populate the whole-query cache for queries:
```
The phrase "to both use and populate..." occurs below in the text as well. I'd suggest removing to avoid the split infinitive... not necessarily out of strict adherence to the rule, but just in this case it seems like "both" is not doing enough work to warrant it.
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,90 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cached for results.
Review comment:
```suggestion
- `useCache` to instruct queries to use the cache for results.
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] sthetland commented on a change in pull request #10848: refactor query caching docs
Posted by GitBox <gi...@apache.org>.
sthetland commented on a change in pull request #10848:
URL: https://github.com/apache/druid/pull/10848#discussion_r569873583
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +22,61 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently-accessed data.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+When considering a caching strategy consider the following:
+- Caching enables increased concurrency on the same system, therefore leading to noticeable performance improvements for queries on Druid clusters handling throughput for concurrent, mixed workloads.
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+- If you are looking to improve response time for a single query or page load, you should ignore caching. In general, response time for a single task should meet performance objectives even when the cache is cold.
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports the following types of query result caching:
+- **Segment cache** stores _partial results_ of a query for a specific segment.
+- **Whole-query cache** stores all results for a query.
-## Using and populating cache
+To avoid returning stale results, Druid invalidates a cache the moment any underlying data changes regardless of the cache type.
-All caches have a pair of parameters that control the behavior of how individual queries interact with the cache, a 'use' cache parameter, and a 'populate' cache parameter. These settings must be enabled at the service level via [runtime properties](../configuration/index.md) to utilize cache, but can be controlled on a per query basis by setting them on the [query context](../querying/query-context.md). The 'use' parameter obviously controls if a query will utilize cached results. The 'populate' parameter controls if a query will update cached results. These are separate parameters to allow queries on uncommon data to utilize cached results without polluting the cache with results that are unlikely to be re-used by other queries, for example large reports or very old data.
+The primary form of caching in Druid is the segment cache. The segment cache stores query results on a per-segment basis. It is enabled on Historical services by default.
-## Query caching on Brokers
+During query processing, the segment cache intercepts query to bypass the data server processing threads and sends the results directly to the Broker. For queries require minimal processing in the Broker, cached queries are very quick. If work done on the Broker causes a query bottleneck, enabling caching results in little noticeable query improvement.
Review comment:
```suggestion
During query processing, the segment cache intercepts the query, so that it bypasses the data server processing threads, and sends the results directly to the Broker. For queries requiring minimal processing in the Broker, cached queries are very quick. If work done on the Broker causes a query bottleneck, enabling caching results in little noticeable query improvement.
```
Not 100% sure about my edit of the first sentence here, but it's based on my assumption that it's the query that is bypassing threads, not the segment cache, so clarifying on that assumption.
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +22,61 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently-accessed data.
Review comment:
```suggestion
You can enable caching in Apache Druid to improve query times for frequently accessed data.
```
(the old `-ly` hyphen exemption)
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,90 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
Review comment:
```suggestion
This topic covers how to configure services to populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
```
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,90 @@
+---
+id: using-caching
+title: "Using query caching"
Review comment:
just a thought: this page is now entirely config instructions, but it appears under a "Concepts" heading in the left TOC. Not sure how much of an issue that is -- there are other config instructions under that heading -- but it's more apparent now with this standalone page.. We might want to rethink that heading or page locations in the TOC, perhaps in another PR.
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,90 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cached for results.
+- `populateCache` to instruct a query to cache its results.
+
+The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example large reports or queries on very old data.
+
+To use caching, you must first enable the settings for a service in the runtime properties. Afterward, you can control which queries use the cache or populate the cache on a per-query basis within the query context.
+
+The query context settings do not override the server settings. For example, it is possible to set a query context to use the cache, but if it is not enabled at the service level, there's no cache to use.
+
+## Enabling query caching on Brokers
+Brokers support both segment-level and whole-query result level caching.
+
+To control **segment caching** on the Broker, set the `useCache` and `populateCache`runtime properties. For example, to set the Broker to both use and populate the segment cache for queries:
+```
+druid.broker.cache.useCache=true
+druid.broker.cache.populateCache=true
+```
+To control **whole-query caching** on the Broker, set the`useResultLevelCache` and `populateResultLevelCache` runtime properties. For example, to set the Broker to both use and populate the whole-query cache for queries:
+```
+druid.broker.cache.useResultLevelCache=true
+druid.broker.cache.populateResultLevelCache=true
+```
+See [Broker caching](../configuration/index.md#broker-caching) for a description of all available Broker cache configurations.
+
+## Enabling query caching on Historicals
+Historicals only support **segment-level** caching. To control caching on the Historical, set the `useCache` and `populateCache` runtime properties. For example, to set the Historical to both use and populate the segment cache for queries:
+ ```
+ druid.broker.cache.useCache=true
+ druid.broker.cache.populateCache=true
+ ```
+See [Historical caching](../configuration/index.md#historical-caching) for a description of all available Historical cache configurations.
+
+## Enabling query caching on task executor services
+Task executor services, the Peon or the Indexer, only support **segment-level** caching. To control caching on a taske executor service, set the `useCache` and `populateCache` runtime properties. For example, to set the Peon to both use and populate the segment cache for queries:
+
+```
+druid.realtime.cache.useCache=true
+druid.realtime.cache.populateCache=true
+```
+
+See [Peon caching](configuration/index.md#peon-caching) for a description of all available task exector service caching options.
+
+## Enabling caching in the query context
+After you enable cacheing for a service, set cache options for individual queries in the query [context](./query-context.md). For example, you can `POST` a Druid SQL request to the HTTP POST API and include the context as a JSON object:
+
+```
+{
+ "query" : "SELECT COUNT(*) FROM data_source WHERE foo = 'bar' AND __time > TIMESTAMP '2020-01-01 00:00:00'",
+ "context" : {
+ "useCache" : "true",
+ "populateCache" : "false"
+ }
+}
+```
+In this example `populateCahce` is `false` because the query references data that is over a year old. For more information, see [Druid SQL client APIs](./sql.html#client-apis).
+
+## Learn more
+See the following topics for more information:
+- [Query caching](./caching.md) for an overview of caching.
+- [Query context](./query-context.md)
Review comment:
For consistency, this link could use a few words of description
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +22,61 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently-accessed data.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+When considering a caching strategy consider the following:
+- Caching enables increased concurrency on the same system, therefore leading to noticeable performance improvements for queries on Druid clusters handling throughput for concurrent, mixed workloads.
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+- If you are looking to improve response time for a single query or page load, you should ignore caching. In general, response time for a single task should meet performance objectives even when the cache is cold.
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports the following types of query result caching:
+- **Segment cache** stores _partial results_ of a query for a specific segment.
+- **Whole-query cache** stores all results for a query.
-## Using and populating cache
+To avoid returning stale results, Druid invalidates a cache the moment any underlying data changes regardless of the cache type.
-All caches have a pair of parameters that control the behavior of how individual queries interact with the cache, a 'use' cache parameter, and a 'populate' cache parameter. These settings must be enabled at the service level via [runtime properties](../configuration/index.md) to utilize cache, but can be controlled on a per query basis by setting them on the [query context](../querying/query-context.md). The 'use' parameter obviously controls if a query will utilize cached results. The 'populate' parameter controls if a query will update cached results. These are separate parameters to allow queries on uncommon data to utilize cached results without polluting the cache with results that are unlikely to be re-used by other queries, for example large reports or very old data.
+The primary form of caching in Druid is the segment cache. The segment cache stores query results on a per-segment basis. It is enabled on Historical services by default.
-## Query caching on Brokers
+During query processing, the segment cache intercepts query to bypass the data server processing threads and sends the results directly to the Broker. For queries require minimal processing in the Broker, cached queries are very quick. If work done on the Broker causes a query bottleneck, enabling caching results in little noticeable query improvement.
-Brokers support both segment-level and whole-query result level caching. Segment-level caching is controlled by the
-parameters `useCache` and `populateCache`. Whole-query result level caching is controlled by the parameters
-`useResultLevelCache` and `populateResultLevelCache` and [runtime properties](../configuration/index.md)
-`druid.broker.cache.*`.
+The largest performance gains from caching tend to apply to `topN` and time series queries. The impact is less for `groupBy` queries. The same applies to queries with or without joins.
-Enabling segment-level caching on the Broker can yield faster results than if query caches were enabled on Historicals for small
-clusters. This is the recommended setup for smaller production clusters (< 5 servers). Populating segment-level caches on
-the Broker is _not_ recommended for large production clusters, since when the property `druid.broker.cache.populateCache` is
-set to `true` (and query context parameter `populateCache` is _not_ set to `false`), results from Historicals are returned
-on a per segment basis, and Historicals will not be able to do any local result merging. This impairs the ability of the
-Druid cluster to scale well.
+If you're unfamiliar with Druid architecture, review the following topics before proceeding with caching:
Review comment:
These next three links seem like they would go better at the end of the intro section, rather than here where it's already gotten into the page topic. Also, the same links are repeated at the end. I would probably just have them once, either at the end of the intro section or as they are at the end, as a more info section.
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,90 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cached for results.
+- `populateCache` to instruct a query to cache its results.
+
+The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example large reports or queries on very old data.
+
+To use caching, you must first enable the settings for a service in the runtime properties. Afterward, you can control which queries use the cache or populate the cache on a per-query basis within the query context.
+
+The query context settings do not override the server settings. For example, it is possible to set a query context to use the cache, but if it is not enabled at the service level, there's no cache to use.
+
+## Enabling query caching on Brokers
+Brokers support both segment-level and whole-query result level caching.
+
+To control **segment caching** on the Broker, set the `useCache` and `populateCache`runtime properties. For example, to set the Broker to both use and populate the segment cache for queries:
Review comment:
```suggestion
To control **segment caching** on the Broker, set the `useCache` and `populateCache`runtime properties. For example, to set the Broker to use and populate the segment cache for queries:
```
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +22,61 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently-accessed data.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+When considering a caching strategy consider the following:
+- Caching enables increased concurrency on the same system, therefore leading to noticeable performance improvements for queries on Druid clusters handling throughput for concurrent, mixed workloads.
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+- If you are looking to improve response time for a single query or page load, you should ignore caching. In general, response time for a single task should meet performance objectives even when the cache is cold.
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports the following types of query result caching:
+- **Segment cache** stores _partial results_ of a query for a specific segment.
+- **Whole-query cache** stores all results for a query.
-## Using and populating cache
+To avoid returning stale results, Druid invalidates a cache the moment any underlying data changes regardless of the cache type.
-All caches have a pair of parameters that control the behavior of how individual queries interact with the cache, a 'use' cache parameter, and a 'populate' cache parameter. These settings must be enabled at the service level via [runtime properties](../configuration/index.md) to utilize cache, but can be controlled on a per query basis by setting them on the [query context](../querying/query-context.md). The 'use' parameter obviously controls if a query will utilize cached results. The 'populate' parameter controls if a query will update cached results. These are separate parameters to allow queries on uncommon data to utilize cached results without polluting the cache with results that are unlikely to be re-used by other queries, for example large reports or very old data.
+The primary form of caching in Druid is the segment cache. The segment cache stores query results on a per-segment basis. It is enabled on Historical services by default.
-## Query caching on Brokers
+During query processing, the segment cache intercepts query to bypass the data server processing threads and sends the results directly to the Broker. For queries require minimal processing in the Broker, cached queries are very quick. If work done on the Broker causes a query bottleneck, enabling caching results in little noticeable query improvement.
-Brokers support both segment-level and whole-query result level caching. Segment-level caching is controlled by the
-parameters `useCache` and `populateCache`. Whole-query result level caching is controlled by the parameters
-`useResultLevelCache` and `populateResultLevelCache` and [runtime properties](../configuration/index.md)
-`druid.broker.cache.*`.
+The largest performance gains from caching tend to apply to `topN` and time series queries. The impact is less for `groupBy` queries. The same applies to queries with or without joins.
-Enabling segment-level caching on the Broker can yield faster results than if query caches were enabled on Historicals for small
-clusters. This is the recommended setup for smaller production clusters (< 5 servers). Populating segment-level caches on
-the Broker is _not_ recommended for large production clusters, since when the property `druid.broker.cache.populateCache` is
-set to `true` (and query context parameter `populateCache` is _not_ set to `false`), results from Historicals are returned
-on a per segment basis, and Historicals will not be able to do any local result merging. This impairs the ability of the
-Druid cluster to scale well.
+If you're unfamiliar with Druid architecture, review the following topics before proceeding with caching:
+- [Druid Design](../design/architecture.md)
+- [Segments](../design/segments.md)
-## Query caching on Historicals
+To learn how to configure and use caching see [Using query caching](./using-caching.md).
-Historicals only support segment-level caching. Segment-level caching is controlled by the query context
-parameters `useCache` and `populateCache` and [runtime properties](../configuration/index.md)
-`druid.historical.cache.*`.
+## Choosing a cache type
-Larger production clusters should enable segment-level cache population on Historicals only (not on Brokers) to avoid
-having to use Brokers to merge all query results. Enabling cache population on the Historicals instead of the Brokers
-enables the Historicals to do their own local result merging and puts less strain on the Brokers.
+When your queries include data from segments that are mutable and undergoing real-time ingestion, use a **segment cache**. In this case Druid caches query results for immutable historical segments when possible. It re-computes results for the real-time segments at query time.
-## Query caching on Ingestion Tasks
+For example, you have queries that frequently include incoming data from a Kafka or Kinesis stream alongside unchanging segments. Whole-query caching is not helpful in this scenario because the new data from real-time ingestion continually invalidates the cache. Segment caching lets Druid cache results from older immutable segments and merge them with updated data.
-Task executor processes such as the Peon or the experimental Indexer only support segment-level caching. Segment-level
-caching is controlled by the query context parameters `useCache` and `populateCache`
-and [runtime properties](../configuration/index.md) `druid.realtime.cache.*`.
+Segment caching requires Druid to merge the per-segment results for each query, even when the results are cached. If real-time ingestion invalidating the cache is not an issue for your queries, you can use **whole-query caching** to increase query efficiency. For instance, whole-query caching is a good option when you have queries that include data from a batch ingestion task that runs every few hours or once a day.
+
+## Where to enable caching
+
+**Segment cache** is available as follows:
+- On Brokers and on Historicals both for small
Review comment:
```suggestion
- On both Brokers and Historicals for small
```
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +22,61 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently-accessed data.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+When considering a caching strategy consider the following:
+- Caching enables increased concurrency on the same system, therefore leading to noticeable performance improvements for queries on Druid clusters handling throughput for concurrent, mixed workloads.
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+- If you are looking to improve response time for a single query or page load, you should ignore caching. In general, response time for a single task should meet performance objectives even when the cache is cold.
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports the following types of query result caching:
+- **Segment cache** stores _partial results_ of a query for a specific segment.
+- **Whole-query cache** stores all results for a query.
-## Using and populating cache
+To avoid returning stale results, Druid invalidates a cache the moment any underlying data changes regardless of the cache type.
-All caches have a pair of parameters that control the behavior of how individual queries interact with the cache, a 'use' cache parameter, and a 'populate' cache parameter. These settings must be enabled at the service level via [runtime properties](../configuration/index.md) to utilize cache, but can be controlled on a per query basis by setting them on the [query context](../querying/query-context.md). The 'use' parameter obviously controls if a query will utilize cached results. The 'populate' parameter controls if a query will update cached results. These are separate parameters to allow queries on uncommon data to utilize cached results without polluting the cache with results that are unlikely to be re-used by other queries, for example large reports or very old data.
+The primary form of caching in Druid is the segment cache. The segment cache stores query results on a per-segment basis. It is enabled on Historical services by default.
-## Query caching on Brokers
+During query processing, the segment cache intercepts query to bypass the data server processing threads and sends the results directly to the Broker. For queries require minimal processing in the Broker, cached queries are very quick. If work done on the Broker causes a query bottleneck, enabling caching results in little noticeable query improvement.
-Brokers support both segment-level and whole-query result level caching. Segment-level caching is controlled by the
-parameters `useCache` and `populateCache`. Whole-query result level caching is controlled by the parameters
-`useResultLevelCache` and `populateResultLevelCache` and [runtime properties](../configuration/index.md)
-`druid.broker.cache.*`.
+The largest performance gains from caching tend to apply to `topN` and time series queries. The impact is less for `groupBy` queries. The same applies to queries with or without joins.
-Enabling segment-level caching on the Broker can yield faster results than if query caches were enabled on Historicals for small
-clusters. This is the recommended setup for smaller production clusters (< 5 servers). Populating segment-level caches on
-the Broker is _not_ recommended for large production clusters, since when the property `druid.broker.cache.populateCache` is
-set to `true` (and query context parameter `populateCache` is _not_ set to `false`), results from Historicals are returned
-on a per segment basis, and Historicals will not be able to do any local result merging. This impairs the ability of the
-Druid cluster to scale well.
+If you're unfamiliar with Druid architecture, review the following topics before proceeding with caching:
+- [Druid Design](../design/architecture.md)
+- [Segments](../design/segments.md)
-## Query caching on Historicals
+To learn how to configure and use caching see [Using query caching](./using-caching.md).
-Historicals only support segment-level caching. Segment-level caching is controlled by the query context
-parameters `useCache` and `populateCache` and [runtime properties](../configuration/index.md)
-`druid.historical.cache.*`.
+## Choosing a cache type
-Larger production clusters should enable segment-level cache population on Historicals only (not on Brokers) to avoid
-having to use Brokers to merge all query results. Enabling cache population on the Historicals instead of the Brokers
-enables the Historicals to do their own local result merging and puts less strain on the Brokers.
+When your queries include data from segments that are mutable and undergoing real-time ingestion, use a **segment cache**. In this case Druid caches query results for immutable historical segments when possible. It re-computes results for the real-time segments at query time.
-## Query caching on Ingestion Tasks
+For example, you have queries that frequently include incoming data from a Kafka or Kinesis stream alongside unchanging segments. Whole-query caching is not helpful in this scenario because the new data from real-time ingestion continually invalidates the cache. Segment caching lets Druid cache results from older immutable segments and merge them with updated data.
-Task executor processes such as the Peon or the experimental Indexer only support segment-level caching. Segment-level
-caching is controlled by the query context parameters `useCache` and `populateCache`
-and [runtime properties](../configuration/index.md) `druid.realtime.cache.*`.
+Segment caching requires Druid to merge the per-segment results for each query, even when the results are cached. If real-time ingestion invalidating the cache is not an issue for your queries, you can use **whole-query caching** to increase query efficiency. For instance, whole-query caching is a good option when you have queries that include data from a batch ingestion task that runs every few hours or once a day.
+
+## Where to enable caching
+
+**Segment cache** is available as follows:
+- On Brokers and on Historicals both for small
+clusters. Use this configuration for smaller production clusters (< 5 servers).
+
+ Do not use segment caches on the Broker for large production clusters. When `druid.broker.cache.populateCache` is `true` and query context parameter `populateCache` _is not_ `false`, Historicals return results on a per-segment basis without merging results locally thus negatively impacting cluster scalability.
+
+- On Historicals only, the default. Enable segment-level cache population on Historicals only for larger production clusters to prevent Brokers having to merge all query results. When you enable cache population on Historicals instead of Brokers, the Historicals merge their own local results and put less strain on the Brokers.
Review comment:
```suggestion
- On Historicals only, the default. Enable segment-level cache population on Historicals only for larger production clusters to prevent Brokers from having to merge all query results. When you enable cache population on Historicals instead of Brokers, the Historicals merge their own local results and put less strain on the Brokers.
```
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +22,61 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently-accessed data.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+When considering a caching strategy consider the following:
+- Caching enables increased concurrency on the same system, therefore leading to noticeable performance improvements for queries on Druid clusters handling throughput for concurrent, mixed workloads.
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+- If you are looking to improve response time for a single query or page load, you should ignore caching. In general, response time for a single task should meet performance objectives even when the cache is cold.
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports the following types of query result caching:
+- **Segment cache** stores _partial results_ of a query for a specific segment.
+- **Whole-query cache** stores all results for a query.
-## Using and populating cache
+To avoid returning stale results, Druid invalidates a cache the moment any underlying data changes regardless of the cache type.
-All caches have a pair of parameters that control the behavior of how individual queries interact with the cache, a 'use' cache parameter, and a 'populate' cache parameter. These settings must be enabled at the service level via [runtime properties](../configuration/index.md) to utilize cache, but can be controlled on a per query basis by setting them on the [query context](../querying/query-context.md). The 'use' parameter obviously controls if a query will utilize cached results. The 'populate' parameter controls if a query will update cached results. These are separate parameters to allow queries on uncommon data to utilize cached results without polluting the cache with results that are unlikely to be re-used by other queries, for example large reports or very old data.
+The primary form of caching in Druid is the segment cache. The segment cache stores query results on a per-segment basis. It is enabled on Historical services by default.
-## Query caching on Brokers
+During query processing, the segment cache intercepts query to bypass the data server processing threads and sends the results directly to the Broker. For queries require minimal processing in the Broker, cached queries are very quick. If work done on the Broker causes a query bottleneck, enabling caching results in little noticeable query improvement.
-Brokers support both segment-level and whole-query result level caching. Segment-level caching is controlled by the
-parameters `useCache` and `populateCache`. Whole-query result level caching is controlled by the parameters
-`useResultLevelCache` and `populateResultLevelCache` and [runtime properties](../configuration/index.md)
-`druid.broker.cache.*`.
+The largest performance gains from caching tend to apply to `topN` and time series queries. The impact is less for `groupBy` queries. The same applies to queries with or without joins.
-Enabling segment-level caching on the Broker can yield faster results than if query caches were enabled on Historicals for small
-clusters. This is the recommended setup for smaller production clusters (< 5 servers). Populating segment-level caches on
-the Broker is _not_ recommended for large production clusters, since when the property `druid.broker.cache.populateCache` is
-set to `true` (and query context parameter `populateCache` is _not_ set to `false`), results from Historicals are returned
-on a per segment basis, and Historicals will not be able to do any local result merging. This impairs the ability of the
-Druid cluster to scale well.
+If you're unfamiliar with Druid architecture, review the following topics before proceeding with caching:
+- [Druid Design](../design/architecture.md)
+- [Segments](../design/segments.md)
-## Query caching on Historicals
+To learn how to configure and use caching see [Using query caching](./using-caching.md).
-Historicals only support segment-level caching. Segment-level caching is controlled by the query context
-parameters `useCache` and `populateCache` and [runtime properties](../configuration/index.md)
-`druid.historical.cache.*`.
+## Choosing a cache type
-Larger production clusters should enable segment-level cache population on Historicals only (not on Brokers) to avoid
-having to use Brokers to merge all query results. Enabling cache population on the Historicals instead of the Brokers
-enables the Historicals to do their own local result merging and puts less strain on the Brokers.
+When your queries include data from segments that are mutable and undergoing real-time ingestion, use a **segment cache**. In this case Druid caches query results for immutable historical segments when possible. It re-computes results for the real-time segments at query time.
-## Query caching on Ingestion Tasks
+For example, you have queries that frequently include incoming data from a Kafka or Kinesis stream alongside unchanging segments. Whole-query caching is not helpful in this scenario because the new data from real-time ingestion continually invalidates the cache. Segment caching lets Druid cache results from older immutable segments and merge them with updated data.
-Task executor processes such as the Peon or the experimental Indexer only support segment-level caching. Segment-level
-caching is controlled by the query context parameters `useCache` and `populateCache`
-and [runtime properties](../configuration/index.md) `druid.realtime.cache.*`.
+Segment caching requires Druid to merge the per-segment results for each query, even when the results are cached. If real-time ingestion invalidating the cache is not an issue for your queries, you can use **whole-query caching** to increase query efficiency. For instance, whole-query caching is a good option when you have queries that include data from a batch ingestion task that runs every few hours or once a day.
+
+## Where to enable caching
+
+**Segment cache** is available as follows:
+- On Brokers and on Historicals both for small
+clusters. Use this configuration for smaller production clusters (< 5 servers).
+
+ Do not use segment caches on the Broker for large production clusters. When `druid.broker.cache.populateCache` is `true` and query context parameter `populateCache` _is not_ `false`, Historicals return results on a per-segment basis without merging results locally thus negatively impacting cluster scalability.
+
+- On Historicals only, the default. Enable segment-level cache population on Historicals only for larger production clusters to prevent Brokers having to merge all query results. When you enable cache population on Historicals instead of Brokers, the Historicals merge their own local results and put less strain on the Brokers.
+
+- On ingestion tasks in the Peon or Indexer service only. Larger production clusters should enable segment-level cache population on task execution services only to prevent Brokers having to merge all query results. When you enable cache population on task execution services instead of Brokers, the the task execution services to merge their own local results and put less strain on the brokers.
Review comment:
```suggestion
- On ingestion tasks in the Peon or Indexer service only. Larger production clusters should enable segment-level cache population on task execution services only to prevent Brokers having to merge all query results. When you enable cache population on task execution services instead of Brokers, the task execution services merge their own local results, putting less strain on the brokers.
```
##########
File path: docs/querying/caching.md
##########
@@ -1,5 +1,5 @@
---
-id: caching
+id: using-caching
Review comment:
I think this was an unintentional change? This is the same ID value as the next file, which may be why this page doesn't appear in the sidebar TOC. (It might need to be added to sidebars.json as well)
```suggestion
id: caching
```
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,90 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cached for results.
+- `populateCache` to instruct a query to cache its results.
+
+The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example large reports or queries on very old data.
+
+To use caching, you must first enable the settings for a service in the runtime properties. Afterward, you can control which queries use the cache or populate the cache on a per-query basis within the query context.
+
+The query context settings do not override the server settings. For example, it is possible to set a query context to use the cache, but if it is not enabled at the service level, there's no cache to use.
+
+## Enabling query caching on Brokers
+Brokers support both segment-level and whole-query result level caching.
+
+To control **segment caching** on the Broker, set the `useCache` and `populateCache`runtime properties. For example, to set the Broker to both use and populate the segment cache for queries:
+```
+druid.broker.cache.useCache=true
+druid.broker.cache.populateCache=true
+```
+To control **whole-query caching** on the Broker, set the`useResultLevelCache` and `populateResultLevelCache` runtime properties. For example, to set the Broker to both use and populate the whole-query cache for queries:
+```
+druid.broker.cache.useResultLevelCache=true
+druid.broker.cache.populateResultLevelCache=true
+```
+See [Broker caching](../configuration/index.md#broker-caching) for a description of all available Broker cache configurations.
+
+## Enabling query caching on Historicals
+Historicals only support **segment-level** caching. To control caching on the Historical, set the `useCache` and `populateCache` runtime properties. For example, to set the Historical to both use and populate the segment cache for queries:
+ ```
+ druid.broker.cache.useCache=true
+ druid.broker.cache.populateCache=true
+ ```
+See [Historical caching](../configuration/index.md#historical-caching) for a description of all available Historical cache configurations.
+
+## Enabling query caching on task executor services
+Task executor services, the Peon or the Indexer, only support **segment-level** caching. To control caching on a taske executor service, set the `useCache` and `populateCache` runtime properties. For example, to set the Peon to both use and populate the segment cache for queries:
+
+```
+druid.realtime.cache.useCache=true
+druid.realtime.cache.populateCache=true
+```
+
+See [Peon caching](configuration/index.md#peon-caching) for a description of all available task exector service caching options.
+
+## Enabling caching in the query context
+After you enable cacheing for a service, set cache options for individual queries in the query [context](./query-context.md). For example, you can `POST` a Druid SQL request to the HTTP POST API and include the context as a JSON object:
+
+```
+{
+ "query" : "SELECT COUNT(*) FROM data_source WHERE foo = 'bar' AND __time > TIMESTAMP '2020-01-01 00:00:00'",
+ "context" : {
+ "useCache" : "true",
+ "populateCache" : "false"
+ }
+}
+```
+In this example `populateCahce` is `false` because the query references data that is over a year old. For more information, see [Druid SQL client APIs](./sql.html#client-apis).
Review comment:
```suggestion
In this example `populateCache` is `false` because the query references data that is over a year old. For more information, see [Druid SQL client APIs](./sql.md#client-apis).
```
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,90 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cached for results.
+- `populateCache` to instruct a query to cache its results.
+
+The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example large reports or queries on very old data.
+
+To use caching, you must first enable the settings for a service in the runtime properties. Afterward, you can control which queries use the cache or populate the cache on a per-query basis within the query context.
+
+The query context settings do not override the server settings. For example, it is possible to set a query context to use the cache, but if it is not enabled at the service level, there's no cache to use.
+
+## Enabling query caching on Brokers
+Brokers support both segment-level and whole-query result level caching.
+
+To control **segment caching** on the Broker, set the `useCache` and `populateCache`runtime properties. For example, to set the Broker to both use and populate the segment cache for queries:
+```
+druid.broker.cache.useCache=true
+druid.broker.cache.populateCache=true
+```
+To control **whole-query caching** on the Broker, set the`useResultLevelCache` and `populateResultLevelCache` runtime properties. For example, to set the Broker to both use and populate the whole-query cache for queries:
+```
+druid.broker.cache.useResultLevelCache=true
+druid.broker.cache.populateResultLevelCache=true
+```
+See [Broker caching](../configuration/index.md#broker-caching) for a description of all available Broker cache configurations.
+
+## Enabling query caching on Historicals
+Historicals only support **segment-level** caching. To control caching on the Historical, set the `useCache` and `populateCache` runtime properties. For example, to set the Historical to both use and populate the segment cache for queries:
+ ```
+ druid.broker.cache.useCache=true
+ druid.broker.cache.populateCache=true
+ ```
+See [Historical caching](../configuration/index.md#historical-caching) for a description of all available Historical cache configurations.
+
+## Enabling query caching on task executor services
+Task executor services, the Peon or the Indexer, only support **segment-level** caching. To control caching on a taske executor service, set the `useCache` and `populateCache` runtime properties. For example, to set the Peon to both use and populate the segment cache for queries:
Review comment:
```suggestion
Task executor services, the Peon or the Indexer, only support **segment-level** caching. To control caching on a task executor service, set the `useCache` and `populateCache` runtime properties. For example, to set the Peon to use and populate the segment cache for queries:
```
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,90 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cached for results.
+- `populateCache` to instruct a query to cache its results.
+
+The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example large reports or queries on very old data.
Review comment:
```suggestion
The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example, large reports or queries on very old data.
```
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,90 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cached for results.
+- `populateCache` to instruct a query to cache its results.
+
+The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example large reports or queries on very old data.
+
+To use caching, you must first enable the settings for a service in the runtime properties. Afterward, you can control which queries use the cache or populate the cache on a per-query basis within the query context.
+
+The query context settings do not override the server settings. For example, it is possible to set a query context to use the cache, but if it is not enabled at the service level, there's no cache to use.
+
+## Enabling query caching on Brokers
+Brokers support both segment-level and whole-query result level caching.
+
+To control **segment caching** on the Broker, set the `useCache` and `populateCache`runtime properties. For example, to set the Broker to both use and populate the segment cache for queries:
+```
+druid.broker.cache.useCache=true
+druid.broker.cache.populateCache=true
+```
+To control **whole-query caching** on the Broker, set the`useResultLevelCache` and `populateResultLevelCache` runtime properties. For example, to set the Broker to both use and populate the whole-query cache for queries:
+```
+druid.broker.cache.useResultLevelCache=true
+druid.broker.cache.populateResultLevelCache=true
+```
+See [Broker caching](../configuration/index.md#broker-caching) for a description of all available Broker cache configurations.
+
+## Enabling query caching on Historicals
+Historicals only support **segment-level** caching. To control caching on the Historical, set the `useCache` and `populateCache` runtime properties. For example, to set the Historical to both use and populate the segment cache for queries:
+ ```
+ druid.broker.cache.useCache=true
+ druid.broker.cache.populateCache=true
+ ```
+See [Historical caching](../configuration/index.md#historical-caching) for a description of all available Historical cache configurations.
+
+## Enabling query caching on task executor services
+Task executor services, the Peon or the Indexer, only support **segment-level** caching. To control caching on a taske executor service, set the `useCache` and `populateCache` runtime properties. For example, to set the Peon to both use and populate the segment cache for queries:
+
+```
+druid.realtime.cache.useCache=true
+druid.realtime.cache.populateCache=true
+```
+
+See [Peon caching](configuration/index.md#peon-caching) for a description of all available task exector service caching options.
Review comment:
```suggestion
See [Peon caching](configuration/index.md#peon-caching) for a description of all available task executor service caching options.
```
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,90 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cached for results.
+- `populateCache` to instruct a query to cache its results.
+
+The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example large reports or queries on very old data.
+
+To use caching, you must first enable the settings for a service in the runtime properties. Afterward, you can control which queries use the cache or populate the cache on a per-query basis within the query context.
+
+The query context settings do not override the server settings. For example, it is possible to set a query context to use the cache, but if it is not enabled at the service level, there's no cache to use.
+
+## Enabling query caching on Brokers
+Brokers support both segment-level and whole-query result level caching.
+
+To control **segment caching** on the Broker, set the `useCache` and `populateCache`runtime properties. For example, to set the Broker to both use and populate the segment cache for queries:
+```
+druid.broker.cache.useCache=true
+druid.broker.cache.populateCache=true
+```
+To control **whole-query caching** on the Broker, set the`useResultLevelCache` and `populateResultLevelCache` runtime properties. For example, to set the Broker to both use and populate the whole-query cache for queries:
+```
+druid.broker.cache.useResultLevelCache=true
+druid.broker.cache.populateResultLevelCache=true
+```
+See [Broker caching](../configuration/index.md#broker-caching) for a description of all available Broker cache configurations.
+
+## Enabling query caching on Historicals
+Historicals only support **segment-level** caching. To control caching on the Historical, set the `useCache` and `populateCache` runtime properties. For example, to set the Historical to both use and populate the segment cache for queries:
+ ```
+ druid.broker.cache.useCache=true
+ druid.broker.cache.populateCache=true
+ ```
+See [Historical caching](../configuration/index.md#historical-caching) for a description of all available Historical cache configurations.
+
+## Enabling query caching on task executor services
+Task executor services, the Peon or the Indexer, only support **segment-level** caching. To control caching on a taske executor service, set the `useCache` and `populateCache` runtime properties. For example, to set the Peon to both use and populate the segment cache for queries:
+
+```
+druid.realtime.cache.useCache=true
+druid.realtime.cache.populateCache=true
+```
+
+See [Peon caching](configuration/index.md#peon-caching) for a description of all available task exector service caching options.
+
+## Enabling caching in the query context
+After you enable cacheing for a service, set cache options for individual queries in the query [context](./query-context.md). For example, you can `POST` a Druid SQL request to the HTTP POST API and include the context as a JSON object:
Review comment:
```suggestion
After you enable caching for a service, set cache options for individual queries in the query [context](./query-context.md). For example, you can `POST` a Druid SQL request to the HTTP POST API and include the context as a JSON object:
```
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,90 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cached for results.
+- `populateCache` to instruct a query to cache its results.
+
+The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example large reports or queries on very old data.
+
+To use caching, you must first enable the settings for a service in the runtime properties. Afterward, you can control which queries use the cache or populate the cache on a per-query basis within the query context.
+
+The query context settings do not override the server settings. For example, it is possible to set a query context to use the cache, but if it is not enabled at the service level, there's no cache to use.
+
+## Enabling query caching on Brokers
+Brokers support both segment-level and whole-query result level caching.
+
+To control **segment caching** on the Broker, set the `useCache` and `populateCache`runtime properties. For example, to set the Broker to both use and populate the segment cache for queries:
+```
+druid.broker.cache.useCache=true
+druid.broker.cache.populateCache=true
+```
+To control **whole-query caching** on the Broker, set the`useResultLevelCache` and `populateResultLevelCache` runtime properties. For example, to set the Broker to both use and populate the whole-query cache for queries:
Review comment:
```suggestion
To control **whole-query caching** on the Broker, set the `useResultLevelCache` and `populateResultLevelCache` runtime properties. For example, to set the Broker to use and populate the whole-query cache for queries:
```
The phrase "to both use and populate..." occurs below in the text as well. I'd suggest removing to avoid the split infinitive... not necessarily out of strict adherence to the rule, but just in this case it seems like "both" is not doing enough work to warrant it.
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,90 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cached for results.
Review comment:
```suggestion
- `useCache` to instruct queries to use the cache for results.
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] suneet-s commented on a change in pull request #10848: refactor query caching docs
Posted by GitBox <gi...@apache.org>.
suneet-s commented on a change in pull request #10848:
URL: https://github.com/apache/druid/pull/10848#discussion_r589569175
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +23,87 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently accessed data. This topic defines the different types of caching for Druid. It describes the default caching behavior and provides guidance and examples to help you hone your caching strategy.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+If you're unfamiliar with Druid architecture, review the following topics before proceeding with caching:
+- [Druid Design](../design/architecture.md)
+- [Segments](../design/segments.md)
+- [Query execution](./query-execution)
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+For instructions to configure query caching see [Using query caching](./using-caching.md).
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports the following types of caches:
-## Using and populating cache
+- **Per-segment** caching which stores _partial results_ of a query for a specific segment. Per-segment caching is enabled on Historicals by default.
+- **Whole-query** caching which stores all results for a query.
-All caches have a pair of parameters that control the behavior of how individual queries interact with the cache, a 'use' cache parameter, and a 'populate' cache parameter. These settings must be enabled at the service level via [runtime properties](../configuration/index.md) to utilize cache, but can be controlled on a per query basis by setting them on the [query context](../querying/query-context.md). The 'use' parameter obviously controls if a query will utilize cached results. The 'populate' parameter controls if a query will update cached results. These are separate parameters to allow queries on uncommon data to utilize cached results without polluting the cache with results that are unlikely to be re-used by other queries, for example large reports or very old data.
+To avoid returning stale results, Druid invalidates the cache the moment any underlying data changes for both types of cache.
-## Query caching on Brokers
+Druid can store cache data the local JVM heap or in an external distributed key/value store. The default is a local cache based upon [Caffeine](https://github.com/ben-manes/caffeine). Maximum cache storage defaults to the minimum value of 1 GiB or the ten percent of the maximum runtime memory for the JVM with no cache expiration. See [Cache configuration](../configuration/index.md#cache-configuration) for information on how to configure cache storage.
-Brokers support both segment-level and whole-query result level caching. Segment-level caching is controlled by the
-parameters `useCache` and `populateCache`. Whole-query result level caching is controlled by the parameters
-`useResultLevelCache` and `populateResultLevelCache` and [runtime properties](../configuration/index.md)
-`druid.broker.cache.*`.
+### Per-segment caching
-Enabling segment-level caching on the Broker can yield faster results than if query caches were enabled on Historicals for small
-clusters. This is the recommended setup for smaller production clusters (< 5 servers). Populating segment-level caches on
-the Broker is _not_ recommended for large production clusters, since when the property `druid.broker.cache.populateCache` is
-set to `true` (and query context parameter `populateCache` is _not_ set to `false`), results from Historicals are returned
-on a per segment basis, and Historicals will not be able to do any local result merging. This impairs the ability of the
-Druid cluster to scale well.
+The primary form of caching in Druid is the **per-segment cache** which stores query results on a per-segment basis. It is enabled on Historical services by default.
-## Query caching on Historicals
+When your queries include data from segments that are mutable and undergoing real-time ingestion, use a segment cache. In this case Druid caches query results for immutable historical segments when possible. It re-computes results for the real-time segments at query time.
-Historicals only support segment-level caching. Segment-level caching is controlled by the query context
-parameters `useCache` and `populateCache` and [runtime properties](../configuration/index.md)
-`druid.historical.cache.*`.
+For example, you have queries that frequently include incoming data from a Kafka or Kinesis stream alongside unchanging segments. Per-segment caching lets Druid cache results from older immutable segments and merge them with updated data. Whole-query caching would not be helpful in this scenario because the new data from real-time ingestion continually invalidates the cache.
-Larger production clusters should enable segment-level cache population on Historicals only (not on Brokers) to avoid
-having to use Brokers to merge all query results. Enabling cache population on the Historicals instead of the Brokers
-enables the Historicals to do their own local result merging and puts less strain on the Brokers.
+### Whole-query caching
-## Query caching on Ingestion Tasks
+If real-time ingestion invalidating the cache is not an issue for your queries, you can use **whole-query caching** on the Broker to increase query efficiency. The Broker performs whole-query caching operations before sending fan out queries to Historicals. Therefore Druid no longer needs to merge the per-segment results on the Broker.
-Task executor processes such as the Peon or the experimental Indexer only support segment-level caching. Segment-level
-caching is controlled by the query context parameters `useCache` and `populateCache`
-and [runtime properties](../configuration/index.md) `druid.realtime.cache.*`.
+For instance, whole-query caching is a good option when you have queries that include data from a batch ingestion task that runs every few hours or once a day. Per-segment caching would be less efficient in this case because it requires Druid to merge the per-segment results for each query, even when the results are cached.
+
+## Where to enable caching
+
+**Per-segment cache** is available as follows:
+
+- On Historicals, the default. Enable segment-level cache population on Historicals for larger production clusters to prevent Brokers from having to merge all query results. When you enable cache population on Historicals instead of Brokers, the Historicals merge their own local results and put less strain on the Brokers.
+
+- On ingestion tasks in the Peon or Indexer service. Larger production clusters should enable segment-level cache population on task execution services only to prevent Brokers from having to merge all query results. When you enable cache population on task execution services instead of Brokers, the the task execution services to merge their own local results and put less strain on the Brokers.
+
+ Task executor services only support caches that store data locally. For example the `caffeine` cache. This restriction exists because the cache stores results at the level of intermediate partial segments generated by the ingestion tasks. These intermediate partial segments may not be identical across task replicas. Therefore task executor services ignore remote cache types such as `memcached`.
+
+- On Brokers for small production clusters with less than five servers.
+
+ Do not use per-segment caches on the Broker for large production clusters. When `druid.broker.cache.populateCache` is `true` and query context parameter `populateCache` _is not_ `false`, Historicals return results on a per-segment basis without merging results locally thus negatively impacting cluster scalability.
+
+**Whole-query cache** is only available on Brokers.
+
+## Performance considerations for caching
+Caching enables increased concurrency on the same system, therefore leading to noticeable performance improvements for queries on Druid clusters handling throughput for concurrent, mixed workloads.
+
+If you are looking to improve response time for a single query or page load, you should ignore caching. In general, response time for a single task should meet performance objectives even when the cache is cold.
+
+During query processing, the per-segment cache intercepts the query and sends the results directly to the Broker. This way the query bypasses the data server processing threads. For queries requiring minimal processing in the Broker, cached queries are very quick. If work done on the Broker causes a query bottleneck, enabling caching results in little noticeable query improvement.
+
+The largest performance gains from segment caching tend to apply to `topN` and time series queries. The impact is less for `groupBy` queries. The same applies to queries with or without joins.
Review comment:
> The impact is less for `groupBy` queries
I think this undersells it a little bit. There is still an impact here, it's just that in some cases the bottleneck may be in merging results on the broker. Not sure exactly how to wordsmith this, but if I read this as is it sounds like there isn't much of a gain for groupBy queries
```suggestion
The largest performance gains from segment caching tend to apply to `topN` and time series queries. For `groupBy` queries, if the bottleneck is in the merging phase on the broker, the impact is less. The same applies to queries with or without joins.
```
> The same applies to ...
I don't think I understand this sentence
##########
File path: docs/querying/caching.md
##########
@@ -22,63 +23,87 @@ title: "Query caching"
~ under the License.
-->
+You can enable caching in Apache Druid to improve query times for frequently accessed data. This topic defines the different types of caching for Druid. It describes the default caching behavior and provides guidance and examples to help you hone your caching strategy.
-Apache Druid supports query result caching at both the segment and whole-query result level. Cache data can be stored in the
-local JVM heap or in an external distributed key/value store. In all cases, the Druid cache is a query result cache.
-The only difference is whether the result is a _partial result_ for a particular segment, or the result for an entire
-query. In both cases, the cache is invalidated as soon as any underlying data changes; it will never return a stale
-result.
+If you're unfamiliar with Druid architecture, review the following topics before proceeding with caching:
+- [Druid Design](../design/architecture.md)
+- [Segments](../design/segments.md)
+- [Query execution](./query-execution)
-Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and
-undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical
-segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not
-useful in this scenario, since it would be continuously invalidated.
+For instructions to configure query caching see [Using query caching](./using-caching.md).
-Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served
-from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time
-ingestion is not an issue.
+## Cache types
+Druid supports the following types of caches:
-## Using and populating cache
+- **Per-segment** caching which stores _partial results_ of a query for a specific segment. Per-segment caching is enabled on Historicals by default.
+- **Whole-query** caching which stores all results for a query.
-All caches have a pair of parameters that control the behavior of how individual queries interact with the cache, a 'use' cache parameter, and a 'populate' cache parameter. These settings must be enabled at the service level via [runtime properties](../configuration/index.md) to utilize cache, but can be controlled on a per query basis by setting them on the [query context](../querying/query-context.md). The 'use' parameter obviously controls if a query will utilize cached results. The 'populate' parameter controls if a query will update cached results. These are separate parameters to allow queries on uncommon data to utilize cached results without polluting the cache with results that are unlikely to be re-used by other queries, for example large reports or very old data.
+To avoid returning stale results, Druid invalidates the cache the moment any underlying data changes for both types of cache.
-## Query caching on Brokers
+Druid can store cache data the local JVM heap or in an external distributed key/value store. The default is a local cache based upon [Caffeine](https://github.com/ben-manes/caffeine). Maximum cache storage defaults to the minimum value of 1 GiB or the ten percent of the maximum runtime memory for the JVM with no cache expiration. See [Cache configuration](../configuration/index.md#cache-configuration) for information on how to configure cache storage.
Review comment:
```suggestion
Druid can store cache data on the local JVM heap or in an external distributed key/value store. The default is a local cache based upon [Caffeine](https://github.com/ben-manes/caffeine). Maximum cache storage defaults to the minimum value of 1 GiB or the ten percent of the maximum runtime memory for the JVM with no cache expiration. See [Cache configuration](../configuration/index.md#cache-configuration) for information on how to configure cache storage.
```
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,91 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services to populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cache for results.
+- `populateCache` to instruct a query to cache its results.
+
+The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example, large reports or queries on very old data.
+
+To use caching, it must be enabled in the settings for at least one service in the runtime properties. By default, per-query cache is enabled on Historicals. For individual queries, you can control cache usage and population within the query context.
+
+
+## Enabling query caching on Historicals
+Historicals only support **segment-level** caching, which is enabled by default. To control caching on the Historical, set the `useCache` and `populateCache` runtime properties. For example, to set the Historical to both use and populate the segment cache for queries:
+ ```
+ druid.broker.cache.useCache=true
+ druid.broker.cache.populateCache=true
+ ```
+See [Historical caching](../configuration/index.md#historical-caching) for a description of all available Historical cache configurations.
+
+## Enabling query caching on task executor services
+Task executor services, the Peon or the Indexer, only support **segment-level** caching. To control caching on a task executor service, set the `useCache` and `populateCache` runtime properties. For example, to set the Peon to both use and populate the segment cache for queries:
+
+```
+druid.realtime.cache.useCache=true
+druid.realtime.cache.populateCache=true
+```
+
+See [Peon caching](configuration/index.md#peon-caching) for a description of all available task executor service caching options.
+
+## Enabling query caching on Brokers
+Brokers support both segment-level and whole-query result level caching.
+
+To control **segment caching** on the Broker, set the `useCache` and `populateCache`runtime properties. For example, to set the Broker to use and populate the segment cache for queries:
+```
+druid.broker.cache.useCache=true
+druid.broker.cache.populateCache=true
+```
+To control **whole-query caching** on the Broker, set the `useResultLevelCache` and `populateResultLevelCache` runtime properties. For example, to set the Broker to use and populate the whole-query cache for queries:
+```
+druid.broker.cache.useResultLevelCache=true
+druid.broker.cache.populateResultLevelCache=true
+```
+See [Broker caching](../configuration/index.md#broker-caching) for a description of all available Broker cache configurations.
+
+## Enabling caching in the query context
+As long as one service is set to populate the cache, you can set cache options for individual queries in the query [context](./query-context.md). For example, you can `POST` a Druid SQL request to the HTTP POST API and include the context as a JSON object:
Review comment:
nit:
```suggestion
As long as the service is set to populate the cache, you can set cache options for individual queries in the query [context](./query-context.md). For example, you can `POST` a Druid SQL request to the HTTP POST API and include the context as a JSON object:
```
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,91 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services to populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cache for results.
+- `populateCache` to instruct a query to cache its results.
+
+The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example, large reports or queries on very old data.
+
+To use caching, it must be enabled in the settings for at least one service in the runtime properties. By default, per-query cache is enabled on Historicals. For individual queries, you can control cache usage and population within the query context.
Review comment:
nit: When I read this, I think that if it's enabled on 1 service, it applies to all of my cluster.
```suggestion
To use caching, it must be enabled in the settings for the service where caching should be enabled in the runtime properties. By default, per-segment cache is enabled on Historicals. For individual queries, you can control cache usage and population within the query context.
```
^ it should say `per-segment`, not `per-query` (that's a little too close to whole query caching 😅 )
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,91 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services to populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
Review comment:
nit:
```suggestion
This topic covers how to configure services to populate and use the Druid query caches. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
```
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,91 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services to populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cache for results.
+- `populateCache` to instruct a query to cache its results.
+
+The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example, large reports or queries on very old data.
+
+To use caching, it must be enabled in the settings for at least one service in the runtime properties. By default, per-query cache is enabled on Historicals. For individual queries, you can control cache usage and population within the query context.
+
+
+## Enabling query caching on Historicals
+Historicals only support **segment-level** caching, which is enabled by default. To control caching on the Historical, set the `useCache` and `populateCache` runtime properties. For example, to set the Historical to both use and populate the segment cache for queries:
+ ```
+ druid.broker.cache.useCache=true
+ druid.broker.cache.populateCache=true
+ ```
+See [Historical caching](../configuration/index.md#historical-caching) for a description of all available Historical cache configurations.
+
+## Enabling query caching on task executor services
+Task executor services, the Peon or the Indexer, only support **segment-level** caching. To control caching on a task executor service, set the `useCache` and `populateCache` runtime properties. For example, to set the Peon to both use and populate the segment cache for queries:
+
+```
+druid.realtime.cache.useCache=true
+druid.realtime.cache.populateCache=true
+```
+
+See [Peon caching](configuration/index.md#peon-caching) for a description of all available task executor service caching options.
Review comment:
```suggestion
See [Peon caching](configuration/index.md#peon-caching) and [Indexer caching](configuration/index.md#indexer-caching) for a description of all available task executor service caching options.
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] techdocsmith commented on a change in pull request #10848: refactor query caching docs
Posted by GitBox <gi...@apache.org>.
techdocsmith commented on a change in pull request #10848:
URL: https://github.com/apache/druid/pull/10848#discussion_r589841724
##########
File path: docs/querying/using-caching.md
##########
@@ -0,0 +1,91 @@
+---
+id: using-caching
+title: "Using query caching"
+---
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+
+This topic covers how to configure services to populate and use the Druid query cache. For a conceptual overview and use cases, see [Query caching](./caching.md). For information on how to configure the caching mechanism, see [Cache configuration](../configuration/index.md#cache-configuration).
+
+All query caches have a pair of parameters that control the way individual queries interact with the cache:
+
+- `useCache` to instruct queries to use the cache for results.
+- `populateCache` to instruct a query to cache its results.
+
+The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example, large reports or queries on very old data.
+
+To use caching, it must be enabled in the settings for at least one service in the runtime properties. By default, per-query cache is enabled on Historicals. For individual queries, you can control cache usage and population within the query context.
Review comment:
```suggestion
To use caching, it must be enabled in the settings for the service to perform caching in the service's runtime properties. By default, per-segment cache is enabled on Historicals. For individual queries, you can control cache usage and population within the query context.
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org