|
32 | 32 |
|
33 | 33 | ```sql
|
34 | 34 | 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 |
40 | 40 | ) ENGINE = GraphiteMergeTree('graphite_rollup')
|
41 |
| -PARTITION BY toYYYYMM(Date) |
| 41 | +PARTITION BY toYearWeek(Date) |
42 | 42 | ORDER BY (Path, Time);
|
43 | 43 |
|
44 | 44 | -- optional table for faster metric search
|
45 | 45 | 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 |
50 | 50 | ) ENGINE = ReplacingMergeTree(Version)
|
51 |
| -PARTITION BY toYYYYMM(Date) |
| 51 | +PARTITION BY toYearWeek(Date) |
52 | 52 | ORDER BY (Level, Path, Date);
|
53 | 53 |
|
54 | 54 | -- optional table for storing Graphite tags
|
55 | 55 | 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 |
59 | 59 | Tags Array(String),
|
60 |
| - Version UInt32 |
| 60 | + Version UInt32 TTL toDateTime(Version) + INTERVAL 2 DAY -- is necessary only for the current day |
61 | 61 | ) ENGINE = ReplacingMergeTree(Version)
|
62 |
| -PARTITION BY toYYYYMM(Date) |
| 62 | +PARTITION BY toYearWeek(Date) |
63 | 63 | ORDER BY (Tag1, Path, Date);
|
64 | 64 | ```
|
65 | 65 |
|
66 | 66 | [GraphiteMergeTree documentation](https://clickhouse.tech/docs/en/engines/table-engines/mergetree-family/graphitemergetree/)
|
67 | 67 |
|
68 | 68 | You can create Replicated tables. See [ClickHouse documentation](https://clickhouse.tech/docs/en/engines/table-engines/mergetree-family/replication/)
|
69 | 69 |
|
| 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 | + |
70 | 89 | ## Configuration
|
71 | 90 | ```
|
72 | 91 | $ carbon-clickhouse -help
|
|
0 commit comments