-
Notifications
You must be signed in to change notification settings - Fork 27
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
Request for Connection Pooling Feature when creating several clients. #278
Comments
There is already an internal pool of TCP connections (sockets), which is utilized when KeepAlive is enabled (and it is enabled by default). The number of active sockets is 10 by default, and an already open socket will be reused until it idles for too long, and then it is considered expired and removed from the pool. Related docs: https://clickhouse.com/docs/en/integrations/language-clients/javascript#connection-pool-nodejs-only + https://clickhouse.com/docs/en/integrations/language-clients/javascript#keep-alive-configuration-nodejs-only However, currently, the credentials are tied to the client instance, and the authentication header is immutable internally (the relevant method source is here). Considering the description of your use case, you would like to override the user credentials for each request. Is this correct? |
yes, that is correct. theres other usecases that will benefit from being able to set the agent, like if we want to customize the |
As I mentioned before, internal TCP connection pooling is already there. Due to possible complications with socket management, I'd prefer not to allow overriding the agent defined in the Node.js base connection. Regarding |
why did you implement pooling instead of relying on the one that ships with the |
Re: the user credentials override.
So, just to double check: if we add export interface BaseQueryParams {
// <...>
/** When defined, it will override the username from the {@link BaseClickHouseClientConfigOptions.username} setting.
* @default undefined */
username?: string
/** When defined, it will override the password from the {@link BaseClickHouseClientConfigOptions.password} setting.
* @default undefined */
password?: string
}
So, if |
yes |
Added in 1.1.0. |
thanks @slvrtrn! i'd still like to know why the lib needs to implement connection pooling ontop of the nodejs built-in one. i have use-cases in which i'd like to set the http agent, which will decouple the tcp connection from a client and its settings. most http based nodejs packages expose the http |
It doesn't; it's just the HTTP(s) agent that handles the pooling. The client adds a few things on top of that, such as gracefully shutting down the idling keep-alive sockets since it does not work well out of the box in Node.js. You can have a look at the node_base_connection.ts sources and the overrides in the https connection implementation.
If you have a specific option in mind (like that lookup handler you mentioned earlier), please feel free to open a feature request.
After the internal discussion about this, we still think that providing an option to override the agent itself will cause us more issues in the long run. CC @mshustov |
Thanks for the reply @slvrtrn btw the current implementation of what im trying to say is that it might be worth giving up on this and instead allow users to se the |
also it seems like a combination of
can achieve the same behaviour for timeouts like you wanted docs |
As we had a few other requests regarding this, custom HTTP(s) agent is now supported as of 1.2.0; see also the relevant docs with examples. |
Thanks!!! This is very helpful |
Hey,
We are using the Clickhouse node package to create queries from an app to our DB.
We have many users who frequently query the database, Each user has a unique Clickhouse user, requiring the creation of a new client object for each query. This results in significant TCP connection overhead.
We would love the option to have a connection pool to prevent the TCP overhead associated with creating new client objects. For example, adding the option to send an agent to the client, similar to Axios, to get the connection from a pool instead of creating a new TCP connection. This would allow us to reuse existing connections, optimizing performance and reducing latency.
Thank you very much for looking into this request, looking forward to hearing back from you.
Best regards,
Yosef, TripleWhale.
The text was updated successfully, but these errors were encountered: