-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Caffeine cache extension #3028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Caffeine cache extension #3028
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
155729f
Initial commit of caffeine cache
drcrallen eca2df2
Address code comments
drcrallen e580a27
Move and fixup README.md a bit
drcrallen e9d1025
Improve caffeine readme information
drcrallen 3cd5eba
Cleanup caffeine pom
drcrallen 2d860c4
Address review comments
drcrallen c6f9606
Bump caffeine to 2.3.1
drcrallen 37e3217
Merge remote-tracking branch 'druid/master' into addCaffeineCache
drcrallen b584da9
Bump druid version to 0.9.2-SNAPSHOT
drcrallen c5869ae
Make test not fail randomly.
drcrallen d653ffc
Merge remote-tracking branch 'druid/master' into addCaffeineCache
drcrallen 64c3ea2
Fix distribution and documentation
drcrallen 6d15b72
Add caffeine to extensions.md
drcrallen c00469a
Fix links in extensions.md
drcrallen e894bfa
Lexicographic
drcrallen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. show-off.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Java8 is fun |
||
| } | ||
| }; | ||
|
|
||
| public abstract Executor createExecutor(); | ||
|
|
||
| @JsonCreator | ||
| public static CacheExecutorFactory from(String str) | ||
| { | ||
| return Enum.valueOf(CacheExecutorFactory.class, str.toUpperCase()); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please also update the extensions.md page
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed