Skip to content

CDRIVER-4663 Eagerly create minPoolSize connections #1520

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

Closed
wants to merge 3 commits into from

Conversation

kkloberdanz
Copy link
Contributor

No description provided.

This adds a new public function to the libmongoc API.

mongoc_client_pool_warmup "warms up" aka eagerly connects the specified
number of clients in a client pool to the MongoDB servers in the pool's
topology.

This function is thread safe and blocks until the pool contains
'num_to_warmup' clients.
Copy link
Collaborator

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am concerned about the generic usefulness of the warmup API. I see this as being primarily motivated by Genny's need to benchmark the server. I expect that is not typical use of the C driver.

Rust has precedent for a client warmup method (mongodb/mongo-rust-driver#932). Though it may not be an apples-to-apples comparison. The Rust driver implements CMAP, which limits the rate of connection creation with maxConnecting. The C driver does not limit the rate of connection creation.

I recommend implementing a pool::warmup in the C++ driver only to limit the new API. This may be a convenience for general users, but I prefer limiting API additions until there is more of a known need. Here is a suggested implementation:
https://github.com/mongodb/mongo-cxx-driver/compare/master...kevinAlbs:mongo-cxx-driver:CDRIVER-4663?expand=1

bson_t *ping_command = BCON_NEW ("ping", BCON_INT32 (1));
size_t num_servers = 0;
mongoc_server_description_t **descriptions =
mongoc_client_get_server_descriptions (client, &num_servers);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest sending a ping to one server before calling mongoc_client_get_server_descriptions.

mongoc_client_get_server_descriptions does not connect to a server. If server monitoring has not yet returned, I expect it will return the initial set of server descriptions from the URI.

Example: if the URI is mongodb://localhost:27017,localhost:27018, but there are three nodes in the replica set, mongoc_client_get_server_descriptions may only return the two servers in the URI (if monitoring has not yet occurred). Once a hello response is processed from the two known servers, the third server will be added to the topology description.

This is applied in the suggested C++ implementation.

@kevinAlbs
Copy link
Collaborator

No longer needed. See CDRIVER-4663.

@kevinAlbs kevinAlbs closed this Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants