-
Notifications
You must be signed in to change notification settings - Fork 50
Improve clickhouse table creation #154
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
Draft
Felixoid
wants to merge
3
commits into
master
Choose a base branch
from
optimized-create-clauses
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -32,41 +32,59 @@ make | |||||
|
|
||||||
| ```sql | ||||||
| CREATE TABLE graphite ( | ||||||
| Path String, | ||||||
| Value Float64, | ||||||
| Time UInt32, | ||||||
| Date Date, | ||||||
| Timestamp UInt32 | ||||||
| Path String CODEC(ZSTD(3)), -- better compression | ||||||
| Value Float64 CODEC(Gorilla, LZ4), -- better codec for Floats | ||||||
| Time UInt32 CODEC(DoubleDelta, LZ4), -- will be almost always 0 | ||||||
| Date Date CODEC(DoubleDelta, LZ4), -- will be almost always 0 | ||||||
| Timestamp UInt32 CODEC(DoubleDelta, LZ4) TTL Date + INTERVAL 1 MONTH-- will be almost always 0, good to go in 1 month | ||||||
| ) ENGINE = GraphiteMergeTree('graphite_rollup') | ||||||
| PARTITION BY toYYYYMM(Date) | ||||||
| PARTITION BY toYearWeek(Date) | ||||||
| ORDER BY (Path, Time); | ||||||
|
|
||||||
| -- optional table for faster metric search | ||||||
| CREATE TABLE graphite_index ( | ||||||
| Date Date, | ||||||
| Level UInt32, | ||||||
| Path String, | ||||||
| Version UInt32 | ||||||
| Date Date CODEC(DoubleDelta, LZ4), -- will be almost always 0 | ||||||
| Level UInt32 CODEC(DoubleDelta, LZ4), -- will be almost always 0 | ||||||
| Path String CODEC(ZSTD(3)), -- better compression | ||||||
| Version UInt32 TTL toDateTime(Version) + INTERVAL 2 DAY -- is necessary only for the current day | ||||||
Felixoid marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| ) ENGINE = ReplacingMergeTree(Version) | ||||||
| PARTITION BY toYYYYMM(Date) | ||||||
| PARTITION BY toYYYYMMDD(Date) | ||||||
| ORDER BY (Level, Path, Date); | ||||||
|
|
||||||
| -- optional table for storing Graphite tags | ||||||
| CREATE TABLE graphite_tagged ( | ||||||
| Date Date, | ||||||
| Tag1 String, | ||||||
| Path String, | ||||||
| Tags Array(String), | ||||||
| Version UInt32 | ||||||
| Date Date CODEC(DoubleDelta, LZ4), -- will be almost always 0 | ||||||
| Tag1 String CODEC(ZSTD(3)), -- better compression | ||||||
| Path String CODEC(ZSTD(3)), -- better compression | ||||||
| Tags Array(String) CODEC(ZSTD(3)), -- better compression | ||||||
| Version UInt32 TTL toDateTime(Version) + INTERVAL 2 DAY -- is necessary only for the current day | ||||||
Felixoid marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| ) ENGINE = ReplacingMergeTree(Version) | ||||||
| PARTITION BY toYYYYMM(Date) | ||||||
| PARTITION BY toYYYYMMDD(Date) | ||||||
| ORDER BY (Tag1, Path, Date); | ||||||
| ``` | ||||||
|
|
||||||
| [GraphiteMergeTree documentation](https://clickhouse.tech/docs/en/engines/table-engines/mergetree-family/graphitemergetree/) | ||||||
|
|
||||||
| You can create Replicated tables. See [ClickHouse documentation](https://clickhouse.tech/docs/en/engines/table-engines/mergetree-family/replication/) | ||||||
|
|
||||||
| 3. One should always use [graphite-ch-optimizer](https://github.com/innogames/graphite-ch-optimizer) together with carbon-clickhouse and [graphite-clickhouse](https://github.com/go-graphite/graphite-clickhouse). Without it, the rules from `graphite-rollup` configuration aren't applied automatically. | ||||||
|
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.
Suggested change
|
||||||
|
|
||||||
| ### Fine tuning the `PARTITION BY` for graphite data table | ||||||
|
|
||||||
| The current `toYearWeek` function used in the `PARTITION BY` is the rule of thumb. When `graphite-ch-optimizer` works, it launches `OPTIMIZE TABLE graphite PARTITION ID 'YYYYWW' FINAL` once per configured interval. When the partition is too big, it processes it a few or even several of times. | ||||||
|
|
||||||
| If the partition contains too many data, and optimization runs too long, it could be an option to reduce the partition size, e.g. by using `toYYYYMMDD(toStartOfInterval(Date, toIntervalDay(3)))`. | ||||||
|
|
||||||
| Here's the `clickhouse` query to play with `toStartOfInterval` | ||||||
|
|
||||||
| ```sql | ||||||
| SELECT | ||||||
| toDate(number) AS Date, | ||||||
| toYYYYMMDD(Date) AS `YMD`, | ||||||
| toYearWeek(Date) AS YW, | ||||||
| toYYYYMMDD(toStartOfInterval(Date, toIntervalDay(3))) AS `3YMD` | ||||||
| FROM system.numbers | ||||||
| LIMIT 19900, 50 | ||||||
| ``` | ||||||
|
|
||||||
| ## Configuration | ||||||
| ``` | ||||||
| $ carbon-clickhouse -help | ||||||
|
|
||||||
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.
Uh oh!
There was an error while loading. Please reload this page.