Apache Druid
  • Imply Documentation

›Concepts

Getting started

  • Introduction to Apache Druid
  • Quickstart
  • Docker
  • Single server deployment
  • Clustered deployment

Tutorials

  • Loading files natively
  • Load from Apache Kafka
  • Load from Apache Hadoop
  • Querying data
  • Roll-up
  • Configuring data retention
  • Updating existing data
  • Compacting segments
  • Deleting data
  • Writing an ingestion spec
  • Transforming input data
  • Kerberized HDFS deep storage

Design

  • Design
  • Segments
  • Processes and servers
  • Deep storage
  • Metadata storage
  • ZooKeeper

Ingestion

  • Ingestion
  • Data formats
  • Schema design tips
  • Data management
  • Stream ingestion

    • Apache Kafka
    • Amazon Kinesis
    • Tranquility

    Batch ingestion

    • Native batch
    • Hadoop-based
  • Task reference
  • Troubleshooting FAQ

Querying

  • Druid SQL
  • Native queries
  • Query execution
  • Concepts

    • Datasources
    • Joins
    • Lookups
    • Multi-value dimensions
    • Multitenancy
    • Query caching
    • Context parameters

    Native query types

    • Timeseries
    • TopN
    • GroupBy
    • Scan
    • Search
    • TimeBoundary
    • SegmentMetadata
    • DatasourceMetadata

    Native query components

    • Filters
    • Granularities
    • Dimensions
    • Aggregations
    • Post-aggregations
    • Expressions
    • Having filters (groupBy)
    • Sorting and limiting (groupBy)
    • Sorting (topN)
    • String comparators
    • Virtual columns
    • Spatial filters

Configuration

  • Configuration reference
  • Extensions
  • Logging

Operations

  • Web console
  • Getting started with Apache Druid
  • Basic cluster tuning
  • API reference
  • High availability
  • Rolling updates
  • Retaining or automatically dropping data
  • Metrics
  • Alerts
  • Working with different versions of Apache Hadoop
  • HTTP compression
  • TLS support
  • Password providers
  • dump-segment tool
  • reset-cluster tool
  • insert-segment-to-db tool
  • pull-deps tool
  • Misc

    • Legacy Management UIs
    • Deep storage migration
    • Export Metadata Tool
    • Metadata Migration
    • Segment Size Optimization
    • Content for build.sbt

Development

  • Developing on Druid
  • Creating extensions
  • JavaScript functionality
  • Build from source
  • Versioning
  • Experimental features

Misc

  • Papers

Hidden

  • Apache Druid vs Elasticsearch
  • Apache Druid vs. Key/Value Stores (HBase/Cassandra/OpenTSDB)
  • Apache Druid vs Kudu
  • Apache Druid vs Redshift
  • Apache Druid vs Spark
  • Apache Druid vs SQL-on-Hadoop
  • Authentication and Authorization
  • Broker
  • Coordinator Process
  • Historical Process
  • Indexer Process
  • Indexing Service
  • MiddleManager Process
  • Overlord Process
  • Router Process
  • Peons
  • Approximate Histogram aggregators
  • Apache Avro
  • Microsoft Azure
  • Bloom Filter
  • DataSketches extension
  • DataSketches HLL Sketch module
  • DataSketches Quantiles Sketch module
  • DataSketches Theta Sketch module
  • DataSketches Tuple Sketch module
  • Basic Security
  • Kerberos
  • Cached Lookup Module
  • Apache Ranger Security
  • Google Cloud Storage
  • HDFS
  • Apache Kafka Lookups
  • Globally Cached Lookups
  • MySQL Metadata Store
  • ORC Extension
  • Druid pac4j based Security extension
  • Apache Parquet Extension
  • PostgreSQL Metadata Store
  • Protobuf
  • S3-compatible
  • Simple SSLContext Provider Module
  • Stats aggregator
  • Test Stats Aggregators
  • Ambari Metrics Emitter
  • Apache Cassandra
  • Rackspace Cloud Files
  • DistinctCount Aggregator
  • Graphite Emitter
  • InfluxDB Line Protocol Parser
  • InfluxDB Emitter
  • Kafka Emitter
  • Materialized View
  • Moment Sketches for Approximate Quantiles module
  • Moving Average Query
  • OpenTSDB Emitter
  • Druid Redis Cache
  • Microsoft SQLServer
  • StatsD Emitter
  • T-Digest Quantiles Sketch module
  • Thrift
  • Timestamp Min/Max aggregators
  • GCE Extensions
  • Aliyun OSS
  • Cardinality/HyperUnique aggregators
  • Select
  • Realtime Process
Edit

Query caching

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.

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.

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.

Using and populating cache

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 to utilize cache, but can be controlled on a per query basis by setting them on the query context. 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.

Query caching on Brokers

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 druid.broker.cache.*.

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.

Query caching on Historicals

Historicals only support segment-level caching. Segment-level caching is controlled by the query context parameters useCache and populateCache and runtime properties druid.historical.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.

Query caching on Ingestion Tasks

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 druid.realtime.cache.*.

Larger production clusters should enable segment-level cache population on task execution processes only (not on Brokers) to avoid having to use Brokers to merge all query results. Enabling cache population on the task execution processes instead of the Brokers enables the task execution processes to do their own local result merging and puts less strain on the Brokers.

Note that the task executor processes only support caches that keep their data locally, such as 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 will not necessarily be identical across task replicas, so remote cache types such as memcached will be ignored by task executor processes.

← MultitenancyContext parameters →
  • Using and populating cache
  • Query caching on Brokers
  • Query caching on Historicals
  • Query caching on Ingestion Tasks

Technology · Use Cases · Powered by Druid · Docs · Community · Download · FAQ

 ·  ·  · 
Copyright © 2019 Apache Software Foundation.
Except where otherwise noted, licensed under CC BY-SA 4.0.
Apache Druid, Druid, and the Druid logo are either registered trademarks or trademarks of The Apache Software Foundation in the United States and other countries.