【问题标题】:Populating a Materialized View in ClickHouse exceeds Memory limit在 ClickHouse 中填充物化视图超出内存限制
【发布时间】:2019-12-25 12:42:22
【问题描述】:

我正在尝试在使用 ReplicatedMergeTree 引擎的表上使用 ReplicatedAggregatingMergeTree 引擎创建物化视图。

几百万行后,我得到DB::Exception: Memory limit (for query) exceeded。有没有办法解决这个问题?

CREATE MATERIALIZED VIEW IF NOT EXISTS shared.aggregated_calls_1h
ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/{shard}/shared/aggregated_calls_1h', '{replica}')
PARTITION BY toRelativeDayNum(retained_until_date)
ORDER BY (
  client_id,
  t,
  is_synthetic,
    source_application_ids,
    source_service_id,
    source_endpoint_id,
    destination_application_ids,
    destination_service_id,
    destination_endpoint_id,
    boundary_application_ids,
    process_snapshot_id,
    docker_snapshot_id,
    host_snapshot_id,
    cluster_snapshot_id,
    http_status
)
SETTINGS index_granularity = 8192
POPULATE
AS
SELECT
  client_id,
  toUInt64(floor(t / (60000 * 60)) * (60000 *60)) AS t,
  date,
  toDate(retained_until_timestamp / 1000) retained_until_date,
  is_synthetic,
    source_application_ids,
    source_service_id,
    source_endpoint_id,
  destination_application_ids,
    destination_service_id,
  destination_endpoint_id,
    boundary_application_ids,
    http_status,
    process_snapshot_id,
    docker_snapshot_id,
    host_snapshot_id,
    cluster_snapshot_id,
  any(destination_endpoint) AS destination_endpoint,
  any(destination_endpoint_type) AS destination_endpoint_type,
  groupUniqArrayArrayState(destination_technologies) AS destination_technologies_state,
  minState(ingestion_time) AS min_ingestion_time_state,
  sumState(batchCount) AS sum_call_count_state,
  sumState(errorCount) AS sum_error_count_state,
  sumState(duration) AS sum_duration_state,
  minState(toUInt64(ceil(duration/batchCount))) AS min_duration_state,
  maxState(toUInt64(ceil(duration/batchCount))) AS max_duration_state,
    quantileTimingWeightedState(0.25)(toUInt64(ceil(duration/batchCount)), batchCount) AS latency_p25_state,
    quantileTimingWeightedState(0.50)(toUInt64(ceil(duration/batchCount)), batchCount) AS latency_p50_state,
    quantileTimingWeightedState(0.75)(toUInt64(ceil(duration/batchCount)), batchCount) AS latency_p75_state,
    quantileTimingWeightedState(0.90)(toUInt64(ceil(duration/batchCount)), batchCount) AS latency_p90_state,
    quantileTimingWeightedState(0.95)(toUInt64(ceil(duration/batchCount)), batchCount) AS latency_p95_state,
    quantileTimingWeightedState(0.98)(toUInt64(ceil(duration/batchCount)), batchCount) AS latency_p98_state,
    quantileTimingWeightedState(0.99)(toUInt64(ceil(duration/batchCount)), batchCount) AS latency_p99_state,
    quantileTimingWeightedState(0.25)(toUInt64(ceil(duration/batchCount)/100), batchCount) AS latency_p25_large_state,
    quantileTimingWeightedState(0.50)(toUInt64(ceil(duration/batchCount)/100), batchCount) AS latency_p50_large_state,
    quantileTimingWeightedState(0.75)(toUInt64(ceil(duration/batchCount)/100), batchCount) AS latency_p75_large_state,
    quantileTimingWeightedState(0.90)(toUInt64(ceil(duration/batchCount)/100), batchCount) AS latency_p90_large_state,
    quantileTimingWeightedState(0.95)(toUInt64(ceil(duration/batchCount)/100), batchCount) AS latency_p95_large_state,
    quantileTimingWeightedState(0.98)(toUInt64(ceil(duration/batchCount)/100), batchCount) AS latency_p98_large_state,
    quantileTimingWeightedState(0.99)(toUInt64(ceil(duration/batchCount)/100), batchCount) AS latency_p99_large_state,
    sumState(minSelfTime) AS sum_min_self_time_state
FROM shared.calls_v2
WHERE sample_type != 'user_selected'
GROUP BY
  client_id,
    t,
    date,
    retained_until_date,
    is_synthetic,
    source_application_ids,
    source_service_id,
    source_endpoint_id,
    destination_application_ids,
    destination_service_id,
    destination_endpoint_id,
    boundary_application_ids,
    process_snapshot_id,
    docker_snapshot_id,
    host_snapshot_id,
    cluster_snapshot_id,
    http_status
HAVING destination_endpoint_type != 'INTERNAL'

【问题讨论】:

    标签: clickhouse


    【解决方案1】:

    您可以尝试使用clickhouse-client--max_memory_usage 选项来增加限制。

    --max_memory_usage arg "处理单个查询的最大内存使用量。零表示无限制。"

    https://clickhouse.yandex/docs/en/operations/settings/query_complexity/#settings_max_memory_usage

    或者不是填充,而是手动将数据复制到表中

    INSERT INTO .inner.shared.aggregated_calls_1h
    SELECT 
      client_id,
      toUInt64(floor(t / (60000 * 60)) * (60000 *60)) AS t,
      ...
    

    【讨论】:

    • 我已经尝试手动复制数据,没有帮助,我想避免逐个复制。
    • 我将 --max_memory_usage 从 10GB 增加到 40GB,没有运气。随着查询的进行,它只会吃掉所有东西。
    • 似乎它需要的内存比你有的多。 IMO 唯一的方法是手动复制它。为什么它没有帮助?
    • 我不认为“你的整个表需要适应 RAM”是一种可行的方法,尤其是对于 ClickHouse 的目标受众而言。
    • 这并不意味着您的表必须适合 RAM。但是 CH 在复制时所做的操作必须这样做。
    猜你喜欢
    • 2018-12-28
    • 2021-01-09
    • 2022-10-30
    • 1970-01-01
    • 2021-12-06
    • 2018-11-01
    • 2018-03-30
    • 2021-07-24
    • 2021-10-09
    相关资源
    最近更新 更多