Skip to content

Commit 854d70e

Browse files
committed
Improve clickhouse table creation
1 parent 828edbd commit 854d70e

File tree

1 file changed

+35
-16
lines changed

1 file changed

+35
-16
lines changed

README.md

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,41 +32,60 @@ make
3232

3333
```sql
3434
CREATE TABLE graphite (
35-
Path String,
36-
Value Float64,
37-
Time UInt32,
38-
Date Date,
39-
Timestamp UInt32
35+
Path String CODEC(ZSTD(3)), -- better compression
36+
Value Float64 CODEC(Gorilla, LZ4), -- better codec for Floats
37+
Time UInt32 CODEC(DoubleDelta, LZ4), -- will be almost always 0
38+
Date Date CODEC(DoubleDelta, LZ4), -- will be almost always 0
39+
Timestamp UInt32 CODEC(DoubleDelta, LZ4) -- will be almost always 0
4040
) ENGINE = GraphiteMergeTree('graphite_rollup')
41-
PARTITION BY toYYYYMM(Date)
41+
PARTITION BY toYearWeek(Date)
4242
ORDER BY (Path, Time);
4343

4444
-- optional table for faster metric search
4545
CREATE TABLE graphite_index (
46-
Date Date,
47-
Level UInt32,
48-
Path String,
49-
Version UInt32
46+
Date Date CODEC(DoubleDelta, LZ4), -- will be almost always 0
47+
Level UInt32 CODEC(DoubleDelta, LZ4), -- will be almost always 0
48+
Path String CODEC(ZSTD(3)), -- better compression
49+
Version UInt32 TTL toDateTime(Version) + INTERVAL 2 DAY -- is necessary only for the current day
5050
) ENGINE = ReplacingMergeTree(Version)
51-
PARTITION BY toYYYYMM(Date)
51+
PARTITION BY toYearWeek(Date)
5252
ORDER BY (Level, Path, Date);
5353

5454
-- optional table for storing Graphite tags
5555
CREATE TABLE graphite_tagged (
56-
Date Date,
57-
Tag1 String,
58-
Path String,
56+
Date Date CODEC(DoubleDelta, LZ4), -- will be almost always 0
57+
Tag1 String CODEC(ZSTD(3)), -- better compression
58+
Path String CODEC(ZSTD(3)), -- better compression
5959
Tags Array(String),
60-
Version UInt32
60+
Version UInt32 TTL toDateTime(Version) + INTERVAL 2 DAY -- is necessary only for the current day
6161
) ENGINE = ReplacingMergeTree(Version)
62-
PARTITION BY toYYYYMM(Date)
62+
PARTITION BY toYearWeek(Date)
6363
ORDER BY (Tag1, Path, Date);
6464
```
6565

6666
[GraphiteMergeTree documentation](https://clickhouse.tech/docs/en/engines/table-engines/mergetree-family/graphitemergetree/)
6767

6868
You can create Replicated tables. See [ClickHouse documentation](https://clickhouse.tech/docs/en/engines/table-engines/mergetree-family/replication/)
6969

70+
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.
71+
72+
### Fine tuning the `PARTITION BY` for graphite data table
73+
74+
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.
75+
76+
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)))`.
77+
78+
Here's the `clickhouse` query to play with `toStartOfInterval`
79+
80+
```sql
81+
SELECT
82+
toDate(number) AS Date,
83+
toYearWeek(Date) AS YW,
84+
toYYYYMMDD(toStartOfInterval(Date, toIntervalDay(3))) AS `3YMD`
85+
FROM system.numbers
86+
LIMIT 19900, 50
87+
```
88+
7089
## Configuration
7190
```
7291
$ carbon-clickhouse -help

0 commit comments

Comments
 (0)