forked from apache/druid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Caffeine cache extension (apache#3028)
* Initial commit of caffeine cache * Address code comments * Move and fixup README.md a bit * Improve caffeine readme information * Cleanup caffeine pom * Address review comments * Bump caffeine to 2.3.1 * Bump druid version to 0.9.2-SNAPSHOT * Make test not fail randomly. See ben-manes/caffeine#93 (comment) for an explanation * Fix distribution and documentation * Add caffeine to extensions.md * Fix links in extensions.md * Lexicographic
- Loading branch information
Showing
12 changed files
with
1,080 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
docs/content/development/extensions-core/caffeine-cache.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
layout: doc_page | ||
--- | ||
|
||
Druid Caffeine Cache | ||
-------------------- | ||
|
||
A highly performant local cache implementation for Druid based on [Caffeine](https://github.com/ben-manes/caffeine). Requires a JRE8u60 or higher | ||
|
||
# Configuration | ||
Below are the configuration options known to this module: | ||
|
||
|`runtime.properties`|Description|Default| | ||
|--------------------|-----------|-------| | ||
|`druid.cache.sizeInBytes`|The maximum size of the cache in bytes on heap.|None (unlimited)| | ||
|`druid.cache.expireAfter`|The time (in ms) after an access for which a cache entry may be expired|None (no time limit)| | ||
|`druid.cache.cacheExecutorFactory`|The executor factory to use for Caffeine maintenance. One of `COMMON_FJP`, `SINGLE_THREAD`, or `SAME_THREAD`|ForkJoinPool common pool (`COMMON_FJP`)| | ||
|`druid.cache.evictOnClose`|If a close of a namespace (ex: removing a segment from a node) should cause an eager eviction of associated cache values|`false`| | ||
|
||
## `druid.cache.cacheExecutorFactory` | ||
|
||
Here are the possible values for `druid.cache.cacheExecutorFactory`, which controls how maintenance tasks are run | ||
|
||
* `COMMON_FJP` (default) use the common ForkJoinPool. Do NOT use this option unless you are running 8u60 or higher | ||
* `SINGLE_THREAD` Use a single-threaded executor | ||
* `SAME_THREAD` Cache maintenance is done eagerly | ||
|
||
# Enabling | ||
|
||
To enable the caffeine cache, include this module on the loadList and set `druid.cache.type` to `caffeine` in your properties. | ||
|
||
# Metrics | ||
In addition to the normal cache metrics, the caffeine cache implementation also reports the following in both `total` and `delta` | ||
|
||
|Metric|Description|Normal value| | ||
|------|-----------|------------| | ||
|`query/cache/caffeine/*/requests`|Count of hits or misses|hit + miss| | ||
|`query/cache/caffeine/*/loadTime`|Length of time caffeine spends loading new values (unused feature)|0| | ||
|`query/cache/caffeine/*/evictionBytes`|Size in bytes that have been evicted from the cache|Varies, should tune cache `sizeInBytes` so that `sizeInBytes`/`evictionBytes` is approximately the rate of cache churn you desire| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
~ Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
~ or more contributor license agreements. See the NOTICE file | ||
~ distributed with this work for additional information | ||
~ regarding copyright ownership. Metamarkets 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. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>io.druid.extensions</groupId> | ||
<artifactId>druid-caffeine-cache</artifactId> | ||
<name>druid-caffeine-cache</name> | ||
<description>Local cache implementation for Druid using Caffeine https://github.com/ben-manes/caffeine as the underlying implementation</description> | ||
|
||
<parent> | ||
<groupId>io.druid</groupId> | ||
<artifactId>druid</artifactId> | ||
<version>0.9.2-SNAPSHOT</version> | ||
<relativePath>../../pom.xml</relativePath> | ||
</parent> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.druid</groupId> | ||
<artifactId>druid-api</artifactId> | ||
<scope>provided</scope> | ||
<version>${project.parent.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.druid</groupId> | ||
<artifactId>druid-server</artifactId> | ||
<version>${project.parent.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.ben-manes.caffeine</groupId> | ||
<artifactId>caffeine</artifactId> | ||
<version>2.3.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>net.jpountz.lz4</groupId> | ||
<artifactId>lz4</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- Tests --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
58 changes: 58 additions & 0 deletions
58
extensions-core/caffeine-cache/src/main/java/io/druid/client/cache/CacheExecutorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. Metamarkets 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. | ||
*/ | ||
|
||
package io.druid.client.cache; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import io.druid.concurrent.Execs; | ||
import java.util.concurrent.Executor; | ||
import java.util.concurrent.ForkJoinPool; | ||
|
||
public enum CacheExecutorFactory | ||
{ | ||
COMMON_FJP { | ||
@Override | ||
public Executor createExecutor() | ||
{ | ||
return ForkJoinPool.commonPool(); | ||
} | ||
}, | ||
SINGLE_THREAD { | ||
@Override | ||
public Executor createExecutor() | ||
{ | ||
return Execs.singleThreaded("CaffeineWorker-%s"); | ||
} | ||
}, | ||
SAME_THREAD { | ||
@Override | ||
public Executor createExecutor() | ||
{ | ||
return Runnable::run; | ||
} | ||
}; | ||
|
||
public abstract Executor createExecutor(); | ||
|
||
@JsonCreator | ||
public static CacheExecutorFactory from(String str) | ||
{ | ||
return Enum.valueOf(CacheExecutorFactory.class, str.toUpperCase()); | ||
} | ||
} |
Oops, something went wrong.