Another attempt at Ch#303
Draft
ruslandoga wants to merge 13 commits intomasterfrom
Draft
Conversation
ruslandoga
commented
Apr 8, 2026
| %{ | ||
| "zstd once" => fn input -> :zstd.compress(input) end, | ||
| "zstd stream" => fn input -> Compress.zstd_stream(input) end, | ||
| "nimble_lz4 once" => fn input -> NimbleLZ4.compress(input) end |
Collaborator
Author
There was a problem hiding this comment.
At first I thought about streaming compression each time we Ch.Buffer.add_row but it seems to be slower than doing it once in the end. And it complicates the API.
Results
Operating System: macOS
CPU Information: Apple M2
Number of Available Cores: 8
Available memory: 8 GB
Elixir 1.19.5
Erlang 28.3
JIT enabled: true
Benchmark suite executing with the following configuration:
warmup: 2 s
time: 5 s
memory time: 0 ns
reduction time: 0 ns
parallel: 1
inputs: 1 rows, 100,000 rows, 1000 rows
Estimated total run time: 1 min 3 s
Excluding outliers: false
Benchmarking nimble_lz4 once with input 1 rows ...
Benchmarking nimble_lz4 once with input 100,000 rows ...
Benchmarking nimble_lz4 once with input 1000 rows ...
Benchmarking zstd once with input 1 rows ...
Benchmarking zstd once with input 100,000 rows ...
Benchmarking zstd once with input 1000 rows ...
Benchmarking zstd stream with input 1 rows ...
Benchmarking zstd stream with input 100,000 rows ...
Benchmarking zstd stream with input 1000 rows ...
Calculating statistics...
Formatting results...
##### With input 1 rows #####
Name ips average deviation median 99th %
nimble_lz4 once 409.21 K 2.44 μs ±323.54% 2.33 μs 3.04 μs
zstd once 378.85 K 2.64 μs ±625.79% 2.21 μs 7.08 μs
zstd stream 10.25 K 97.54 μs ±357.19% 83.13 μs 203.34 μs
Comparison:
nimble_lz4 once 409.21 K
zstd once 378.85 K - 1.08x slower +0.196 μs
zstd stream 10.25 K - 39.91x slower +95.09 μs
##### With input 100,000 rows #####
Name ips average deviation median 99th %
nimble_lz4 once 76.57 13.06 ms ±3.87% 13.02 ms 13.38 ms
zstd once 72.66 13.76 ms ±3.34% 13.72 ms 14.45 ms
zstd stream 14.45 69.20 ms ±8.87% 65.38 ms 81.65 ms
Comparison:
nimble_lz4 once 76.57
zstd once 72.66 - 1.05x slower +0.70 ms
zstd stream 14.45 - 5.30x slower +56.14 ms
##### With input 1000 rows #####
Name ips average deviation median 99th %
nimble_lz4 once 7.84 K 127.53 μs ±4.95% 126.25 μs 147.81 μs
zstd once 7.46 K 134.09 μs ±2.88% 133.58 μs 148.21 μs
zstd stream 1.91 K 524.74 μs ±16.48% 534.88 μs 809.10 μs
Comparison:
nimble_lz4 once 7.84 K
zstd once 7.46 K - 1.05x slower +6.55 μs
zstd stream 1.91 K - 4.11x slower +397.20 μs
fb7362a to
43658f9
Compare
1d6d85e to
41a201d
Compare
ruslandoga
commented
Apr 13, 2026
| @@ -0,0 +1,203 @@ | |||
| defmodule Ch.HTTP do | |||
Collaborator
Author
There was a problem hiding this comment.
Or rather it can be %Ch.Request{}.
req = Ch.Request.new(statement: ..., params: ..., headers: headers, etc.)
[{"x-clickhouse-format", "RowBinaryWithNamesAndTypes"} | _] = Ch.Request.headers(req)
"/?" <> _ = Ch.Request.path(req)
^statement = Ch.Request.body(req) # idk
Contributor
|
Just in case you haven't seen, Finch also has an HTTP1 connection pool that you could potentially copy things from 🙂 |
ruslandoga
commented
Apr 19, 2026
| Returns `{:ok, query_result}` on success or `{:error, query_error}` on failure. | ||
| """ | ||
| @spec query(NimblePool.pool(), query_statement, query_params, [query_option]) :: | ||
| {:ok, query_result} | {:error, query_error} |
Collaborator
Author
There was a problem hiding this comment.
Suggested change
| {:ok, query_result} | {:error, query_error} | |
| :ok | {:ok, query_result} | {:error, query_error} |
ruslandoga
commented
Apr 19, 2026
| @spec query!(NimblePool.pool(), query_statement, query_params, [query_option]) :: query_result | ||
| def query!(pool, statement, params \\ %{}, options \\ []) do | ||
| case query(pool, statement, params, options) do | ||
| {:ok, result} -> result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TODOs:
Stream.resource/3Three layers:
Ch.Buffer-- data structure for accumulating rows for INSERT as RowBinaryCh.HTTP-- stateless helpers forMint.HTTP1with some ClickHouse specificsCh.Pool-- NimblePool (at first) ofMint.HTTP1s