i have briefly read the code of mongo-c-dirver 1.1.0 and mongo-c-driver. i have found that in function mongoc-client_pool_push there is a strategydifferent.
in 1.1.0:
void
mongoc_client_pool_push (mongoc_client_pool_t *pool,
mongoc_client_t *client)
{
ENTRY;
bson_return_if_fail(pool);
bson_return_if_fail(client);
/*
* TODO: Shutdown old client connections.
*/
/*
* TODO: We should try to make a client healthy again if it
* is unhealthy since this is typically where a thread
* is done with its work.
*/
mongoc_mutex_lock(&pool->mutex);
_mongoc_queue_push_head(&pool->queue, client);
mongoc_cond_signal(&pool->cond);
mongoc_mutex_unlock(&pool->mutex);
EXIT;
}
in mongoc-1.3.5
void
mongoc_client_pool_push (mongoc_client_pool_t *pool,
mongoc_client_t *client)
{
ENTRY;
BSON_ASSERT (pool);
BSON_ASSERT (client);
mongoc_mutex_lock(&pool->mutex);
if (pool->size > pool->min_pool_size) {
mongoc_client_t *old_client;
old_client = (mongoc_client_t *)_mongoc_queue_pop_head (&pool->queue);
if (old_client) {
mongoc_client_destroy (old_client);
pool->size--;
}
}
mongoc_mutex_unlock(&pool->mutex);
mongoc_mutex_lock (&pool->mutex);
_mongoc_queue_push_tail (&pool->queue, client);
mongoc_cond_signal(&pool->cond);
mongoc_mutex_unlock(&pool->mutex);
EXIT;
}
in a multi-thread scene, when i push a client back it will destroy the oldest client(min_pool_size is 0 default). And it can not be estimated that when to new a client(think 2 threads, it may run simultaneously or one by one to do mongo op), which may cause some efficiency problem.
I wander may this change is neccessary?
thanks!