-
Notifications
You must be signed in to change notification settings - Fork 423
fix: change metrics PK for better memory usage #2545
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
Changes from 1 commit
093544b
b55c111
ff6690f
39060a7
060c03c
a394f9c
4e5a5f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,16 +9,16 @@ CREATE TABLE IF NOT EXISTS ${DATABASE}.otel_metrics_gauge | |
| `ScopeDroppedAttrCount` UInt32 CODEC(ZSTD(1)), | ||
| `ScopeSchemaUrl` String CODEC(ZSTD(1)), | ||
| `ServiceName` LowCardinality(String) CODEC(ZSTD(1)), | ||
| `MetricName` String CODEC(ZSTD(1)), | ||
| `MetricName` LowCardinality(String) CODEC(ZSTD(1)), | ||
| `MetricDescription` String CODEC(ZSTD(1)), | ||
| `MetricUnit` String CODEC(ZSTD(1)), | ||
| `Attributes` Map(LowCardinality(String), String) CODEC(ZSTD(1)), | ||
| `StartTimeUnix` DateTime64(9) CODEC(Delta(8), ZSTD(1)), | ||
| `TimeUnix` DateTime64(9) CODEC(Delta(8), ZSTD(1)), | ||
| `StartTimeUnix` DateTime CODEC(Delta(8), ZSTD(1)), | ||
| `TimeUnix` DateTime CODEC(Delta(8), ZSTD(1)), | ||
|
greptile-apps[bot] marked this conversation as resolved.
Outdated
knudtty marked this conversation as resolved.
Outdated
|
||
| `Value` Float64 CODEC(ZSTD(1)), | ||
| `Flags` UInt32 CODEC(ZSTD(1)), | ||
| `Exemplars.FilteredAttributes` Array(Map(LowCardinality(String), String)) CODEC(ZSTD(1)), | ||
| `Exemplars.TimeUnix` Array(DateTime64(9)) CODEC(ZSTD(1)), | ||
| `Exemplars.TimeUnix` Array(DateTime) CODEC(ZSTD(1)), | ||
|
Comment on lines
-16
to
+21
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. Second precision is an appropriate default and reduces the storage unit from 8 bytes -> 4 bytes |
||
| `Exemplars.Value` Array(Float64) CODEC(ZSTD(1)), | ||
| `Exemplars.SpanId` Array(String) CODEC(ZSTD(1)), | ||
| `Exemplars.TraceId` Array(String) CODEC(ZSTD(1)), | ||
|
|
@@ -27,11 +27,12 @@ CREATE TABLE IF NOT EXISTS ${DATABASE}.otel_metrics_gauge | |
| INDEX idx_scope_attr_key mapKeys(ScopeAttributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_scope_attr_value mapValues(ScopeAttributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_attr_key mapKeys(Attributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_attr_value mapValues(Attributes) TYPE bloom_filter(0.01) GRANULARITY 1 | ||
| INDEX idx_attr_value mapValues(Attributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_time_minmax TimeUnix TYPE minmax GRANULARITY 1 | ||
|
Comment on lines
-30
to
+31
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.
|
||
| ) | ||
| ENGINE = MergeTree | ||
| PARTITION BY toDate(TimeUnix) | ||
| ORDER BY (ServiceName, MetricName, Attributes, toUnixTimestamp64Nano(TimeUnix)) | ||
| ORDER BY (ServiceName, MetricName, toStartOfHour(TimeUnix), cityHash64(Attributes), TimeUnix) | ||
|
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. Time bucketing before the high cardinality Attributes column groups data more efficiently speeding up I/O for queries due to less overall ranges and is very efficient in PK memory
Comment on lines
-34
to
+35
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. Hashing the Attributes column massively reduces PK memory 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. why is that? Is it because some attribute key or values are too long?
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. Yes, both the length of keys or values as well as the number in a single entry. Additionally, ClickHouse does well with known sized parameters, like the 64 bit hash value 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. Got it and thanks. |
||
| TTL toDateTime(TimeUnix) + ${TABLES_TTL} | ||
| SETTINGS ttl_only_drop_parts = 1; | ||
|
|
||
|
|
@@ -50,12 +51,12 @@ CREATE TABLE IF NOT EXISTS ${DATABASE}.otel_metrics_sum | |
| `MetricDescription` String CODEC(ZSTD(1)), | ||
| `MetricUnit` String CODEC(ZSTD(1)), | ||
| `Attributes` Map(LowCardinality(String), String) CODEC(ZSTD(1)), | ||
| `StartTimeUnix` DateTime64(9) CODEC(Delta(8), ZSTD(1)), | ||
| `TimeUnix` DateTime64(9) CODEC(Delta(8), ZSTD(1)), | ||
| `StartTimeUnix` DateTime CODEC(Delta(8), ZSTD(1)), | ||
| `TimeUnix` DateTime CODEC(Delta(8), ZSTD(1)), | ||
| `Value` Float64 CODEC(ZSTD(1)), | ||
| `Flags` UInt32 CODEC(ZSTD(1)), | ||
| `Exemplars.FilteredAttributes` Array(Map(LowCardinality(String), String)) CODEC(ZSTD(1)), | ||
| `Exemplars.TimeUnix` Array(DateTime64(9)) CODEC(ZSTD(1)), | ||
| `Exemplars.TimeUnix` Array(DateTime) CODEC(ZSTD(1)), | ||
| `Exemplars.Value` Array(Float64) CODEC(ZSTD(1)), | ||
| `Exemplars.SpanId` Array(String) CODEC(ZSTD(1)), | ||
| `Exemplars.TraceId` Array(String) CODEC(ZSTD(1)), | ||
|
|
@@ -66,11 +67,12 @@ CREATE TABLE IF NOT EXISTS ${DATABASE}.otel_metrics_sum | |
| INDEX idx_scope_attr_key mapKeys(ScopeAttributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_scope_attr_value mapValues(ScopeAttributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_attr_key mapKeys(Attributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_attr_value mapValues(Attributes) TYPE bloom_filter(0.01) GRANULARITY 1 | ||
| INDEX idx_attr_value mapValues(Attributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_time_minmax TimeUnix TYPE minmax GRANULARITY 1 | ||
| ) | ||
| ENGINE = MergeTree | ||
| PARTITION BY toDate(TimeUnix) | ||
| ORDER BY (ServiceName, MetricName, Attributes, toUnixTimestamp64Nano(TimeUnix)) | ||
| ORDER BY (ServiceName, MetricName, toStartOfHour(TimeUnix), cityHash64(Attributes), TimeUnix) | ||
| TTL toDateTime(TimeUnix) + ${TABLES_TTL} | ||
| SETTINGS ttl_only_drop_parts = 1; | ||
| -- +goose StatementEnd | ||
|
|
@@ -90,14 +92,14 @@ CREATE TABLE IF NOT EXISTS ${DATABASE}.otel_metrics_histogram | |
| `MetricDescription` String CODEC(ZSTD(1)), | ||
| `MetricUnit` String CODEC(ZSTD(1)), | ||
| `Attributes` Map(LowCardinality(String), String) CODEC(ZSTD(1)), | ||
| `StartTimeUnix` DateTime64(9) CODEC(Delta(8), ZSTD(1)), | ||
| `TimeUnix` DateTime64(9) CODEC(Delta(8), ZSTD(1)), | ||
| `StartTimeUnix` DateTime CODEC(Delta(8), ZSTD(1)), | ||
| `TimeUnix` DateTime CODEC(Delta(8), ZSTD(1)), | ||
| `Count` UInt64 CODEC(Delta(8), ZSTD(1)), | ||
| `Sum` Float64 CODEC(ZSTD(1)), | ||
| `BucketCounts` Array(UInt64) CODEC(ZSTD(1)), | ||
| `ExplicitBounds` Array(Float64) CODEC(ZSTD(1)), | ||
| `Exemplars.FilteredAttributes` Array(Map(LowCardinality(String), String)) CODEC(ZSTD(1)), | ||
| `Exemplars.TimeUnix` Array(DateTime64(9)) CODEC(ZSTD(1)), | ||
| `Exemplars.TimeUnix` Array(DateTime) CODEC(ZSTD(1)), | ||
| `Exemplars.Value` Array(Float64) CODEC(ZSTD(1)), | ||
| `Exemplars.SpanId` Array(String) CODEC(ZSTD(1)), | ||
| `Exemplars.TraceId` Array(String) CODEC(ZSTD(1)), | ||
|
|
@@ -110,11 +112,12 @@ CREATE TABLE IF NOT EXISTS ${DATABASE}.otel_metrics_histogram | |
| INDEX idx_scope_attr_key mapKeys(ScopeAttributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_scope_attr_value mapValues(ScopeAttributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_attr_key mapKeys(Attributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_attr_value mapValues(Attributes) TYPE bloom_filter(0.01) GRANULARITY 1 | ||
| INDEX idx_attr_value mapValues(Attributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_time_minmax TimeUnix TYPE minmax GRANULARITY 1 | ||
| ) | ||
| ENGINE = MergeTree | ||
| PARTITION BY toDate(TimeUnix) | ||
| ORDER BY (ServiceName, MetricName, Attributes, toUnixTimestamp64Nano(TimeUnix)) | ||
| ORDER BY (ServiceName, MetricName, toStartOfHour(TimeUnix), cityHash64(Attributes), TimeUnix) | ||
| TTL toDateTime(TimeUnix) + ${TABLES_TTL} | ||
| SETTINGS ttl_only_drop_parts = 1; | ||
| -- +goose StatementEnd | ||
|
|
@@ -134,8 +137,8 @@ CREATE TABLE IF NOT EXISTS ${DATABASE}.otel_metrics_exponential_histogram | |
| `MetricDescription` String CODEC(ZSTD(1)), | ||
| `MetricUnit` String CODEC(ZSTD(1)), | ||
| `Attributes` Map(LowCardinality(String), String) CODEC(ZSTD(1)), | ||
| `StartTimeUnix` DateTime64(9) CODEC(Delta(8), ZSTD(1)), | ||
| `TimeUnix` DateTime64(9) CODEC(Delta(8), ZSTD(1)), | ||
| `StartTimeUnix` DateTime CODEC(Delta(8), ZSTD(1)), | ||
| `TimeUnix` DateTime CODEC(Delta(8), ZSTD(1)), | ||
| `Count` UInt64 CODEC(Delta(8), ZSTD(1)), | ||
| `Sum` Float64 CODEC(ZSTD(1)), | ||
| `Scale` Int32 CODEC(ZSTD(1)), | ||
|
|
@@ -145,7 +148,7 @@ CREATE TABLE IF NOT EXISTS ${DATABASE}.otel_metrics_exponential_histogram | |
| `NegativeOffset` Int32 CODEC(ZSTD(1)), | ||
| `NegativeBucketCounts` Array(UInt64) CODEC(ZSTD(1)), | ||
| `Exemplars.FilteredAttributes` Array(Map(LowCardinality(String), String)) CODEC(ZSTD(1)), | ||
| `Exemplars.TimeUnix` Array(DateTime64(9)) CODEC(ZSTD(1)), | ||
| `Exemplars.TimeUnix` Array(DateTime) CODEC(ZSTD(1)), | ||
| `Exemplars.Value` Array(Float64) CODEC(ZSTD(1)), | ||
| `Exemplars.SpanId` Array(String) CODEC(ZSTD(1)), | ||
| `Exemplars.TraceId` Array(String) CODEC(ZSTD(1)), | ||
|
|
@@ -158,11 +161,12 @@ CREATE TABLE IF NOT EXISTS ${DATABASE}.otel_metrics_exponential_histogram | |
| INDEX idx_scope_attr_key mapKeys(ScopeAttributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_scope_attr_value mapValues(ScopeAttributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_attr_key mapKeys(Attributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_attr_value mapValues(Attributes) TYPE bloom_filter(0.01) GRANULARITY 1 | ||
| INDEX idx_attr_value mapValues(Attributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_time_minmax TimeUnix TYPE minmax GRANULARITY 1 | ||
| ) | ||
| ENGINE = MergeTree | ||
| PARTITION BY toDate(TimeUnix) | ||
| ORDER BY (ServiceName, MetricName, Attributes, toUnixTimestamp64Nano(TimeUnix)) | ||
| ORDER BY (ServiceName, MetricName, toStartOfHour(TimeUnix), cityHash64(Attributes), TimeUnix) | ||
| TTL toDateTime(TimeUnix) + ${TABLES_TTL} | ||
| SETTINGS ttl_only_drop_parts = 1; | ||
| -- +goose StatementEnd | ||
|
|
@@ -182,8 +186,8 @@ CREATE TABLE IF NOT EXISTS ${DATABASE}.otel_metrics_summary | |
| `MetricDescription` String CODEC(ZSTD(1)), | ||
| `MetricUnit` String CODEC(ZSTD(1)), | ||
| `Attributes` Map(LowCardinality(String), String) CODEC(ZSTD(1)), | ||
| `StartTimeUnix` DateTime64(9) CODEC(Delta(8), ZSTD(1)), | ||
| `TimeUnix` DateTime64(9) CODEC(Delta(8), ZSTD(1)), | ||
| `StartTimeUnix` DateTime CODEC(Delta(8), ZSTD(1)), | ||
| `TimeUnix` DateTime CODEC(Delta(8), ZSTD(1)), | ||
| `Count` UInt64 CODEC(Delta(8), ZSTD(1)), | ||
| `Sum` Float64 CODEC(ZSTD(1)), | ||
| `ValueAtQuantiles.Quantile` Array(Float64) CODEC(ZSTD(1)), | ||
|
|
@@ -194,11 +198,12 @@ CREATE TABLE IF NOT EXISTS ${DATABASE}.otel_metrics_summary | |
| INDEX idx_scope_attr_key mapKeys(ScopeAttributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_scope_attr_value mapValues(ScopeAttributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_attr_key mapKeys(Attributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_attr_value mapValues(Attributes) TYPE bloom_filter(0.01) GRANULARITY 1 | ||
| INDEX idx_attr_value mapValues(Attributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
| INDEX idx_time_minmax TimeUnix TYPE minmax GRANULARITY 1 | ||
| ) | ||
| ENGINE = MergeTree | ||
| PARTITION BY toDate(TimeUnix) | ||
| ORDER BY (ServiceName, MetricName, Attributes, toUnixTimestamp64Nano(TimeUnix)) | ||
| ORDER BY (ServiceName, MetricName, toStartOfHour(TimeUnix), cityHash64(Attributes), TimeUnix) | ||
| TTL toDateTime(TimeUnix) + ${TABLES_TTL} | ||
| SETTINGS ttl_only_drop_parts = 1; | ||
| -- +goose StatementEnd | ||
|
|
||
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.
Changing to
LowCardinalityreduces PK memory usage by 2-3xThere 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.
Seems to be a good change. I wonder why not apply it to the
MetricNameto all other metrics tables?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.
Good callout. That was a mistake.
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.
Glad it was addressed. thanks.