clickhouse.rs
clickhouse.rs copied to clipboard
Where is the Pool of connections, and how to limit it.
Hi, I'm trying to migrate https://github.com/suharev7/clickhouse-rs to use yours, but I cannot find where the Pool is. I want to have some connections always established, and need to keep at least one at all times, i.e. pool_min and pool_max.
Your docs say almost nothing about it, besides that one sentence "Reuse created clients or clone them in order to reuse a connection pool". Please, care to explain it better? How does a Pool work here? Thank you.
Hi, this library uses hyper
's HTTP pool. You can create a client on your own using hyper::client::Builder and pass it to clickhouse::Client::with_http_client
. It should be noted in docs, I agree and will close the issue after adding it.
Hyper opens a new connection if all existing is already busy and keeps them alive at least pool_idle_timeout
. This library uses 2s
by default because a default setting in CH for inactive HTTP connections is 3s
.
However, I believe the hyper's pool doesn't provide any pool_min
and pool_max
settings, only pool_max_idle_per_host, which specify how many connections with no active requests can live.
pool_max
can be implemented on your side by using a semaphore. It's more flexible than restricting a connection pool because allows restricting only specific types of requests, e.g. SELECT
s, but not INSERT
s or something more specific depending on your tasks.
need to keep at least one at all times
Why do you need that?
I see, thanks. I've never used hyper myself, so I'm not familiar with how it manages Pools. I'll try to take a look sometime.
I wanted pool_min and pool_max just because suharev7's provides them, and I've grown accustomed to using them:
pool_min - Lower bound of opened connections for Pool (defaults to 10).
pool_max - Upper bound of opened connections for Pool (defaults to 20).
That makes it simple to limit the number of CH connections, while still having some always available. And yes, I do agree a Semaphore would be more flexible, although the less new code I have to write to port my system, the sooner I could have it done...
Anyway, I like very much your query with .bind() support and the typed .fetch_all(), very cool features! But it seems I won't be able to migrate any time soon, until I can make sense of the hyper Pools, and develop this min/max limiter...
It should be noted in docs, I agree and will close the issue after adding it.
I'm also interested. Code example would be super nice.