Skip to content

Enable ClickHouse client compression on inserts #909

@alexluong

Description

@alexluong

Summary

internal/clickhouse/clickhouse.go constructs the clickhouse.Options{} without setting Compression. With this field unset, clickhouse-go v2 sends rows over the native protocol uncompressed.

For row data that's largely text/JSON (events, deliveries), enabling LZ4 typically gives a 3–5× wire-size reduction at negligible CPU cost — the standard recommendation from the clickhouse-go maintainers.

Proposed change

opts := &clickhouse.Options{
    Addr: []string{config.Addr},
    Auth: clickhouse.Auth{...},
    DialTimeout: 10 * time.Second,
    ReadTimeout: 30 * time.Second,
    Compression: &clickhouse.Compression{
        Method: clickhouse.CompressionLZ4,
    },
}

Optional: gate by a CLICKHOUSE_COMPRESSION env (none / lz4 / zstd) so it can be tuned or disabled per deployment without a rebuild.

Why LZ4

  • LZ4 is the standard pick for the CH native protocol — fast compress/decompress, low CPU, decent ratio.
  • ZSTD gets better ratio at higher CPU; worth as an opt-in for high-row-size workloads.
  • Brotli/GZIP exist in the driver but are usually outperformed by LZ4 on this kind of payload.

Acceptance

  • clickhouse.Options.Compression is set (default LZ4) in internal/clickhouse/clickhouse.go.
  • Optional env knob to override / disable.
  • Verified inserts and reads both succeed against ClickHouse Cloud and a local CH instance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions