Skip to content
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

Support Connection Pooling #25

Open
eric-fong opened this issue Mar 31, 2020 · 3 comments
Open

Support Connection Pooling #25

eric-fong opened this issue Mar 31, 2020 · 3 comments

Comments

@eric-fong
Copy link

Could this library support Connection Pooling?

http://mongoc.org/libmongoc/current/connection-pooling.html#connection-pooling
http://mongoc.org/libmongoc/current/mongoc_client_pool_t.html

mongoc_client_pool_t
mongoc_client_pool_pop
mongoc_client_pool_push
mongoc_client_pool_set_error_api

The following method may be also needed for gc?
mongoc_client_pool_destroy (pool);
mongoc_uri_destroy (uri);

mongoc_cleanup ();

Here is the other mongoc binding driver in ffi, for your reference.
https://github.com/lloydzhou/luajit-mongo/blob/master/mongo.lua


Thanks.

@neoxic
Copy link
Owner

neoxic commented Apr 3, 2020

Thanks for your feature request!

I guess it's worth thinking about. The only issue would be that it's not possible to call mongoc_cleanup() reliably from Lua.

It's indeed possible to call some sort of a "library destructor", but it would be incorrect to make a call to mongoc_cleanup() in it because there's no guarantee that some other Lua instance (or even a totally unrelated instance) in a separate thread is not using Mongo C Driver. To the contrary, multiple calls to mongoc_init() are perfectly fine.

Without a call to mongoc_cleanup(), a process will be left with some sort of a worker thread running in the background. Tools like Valgrind will show leaks for such a process at the very least. There may be other minor side effects I guess.

@eric-fong
Copy link
Author

Thanks for your reply.
I would like to use client_pool in a nginx luajit module.
Currently, mongoc_cleanup() is not implemented, but the resource should be released when the worker thread exist. And so that client_pool should be released when worker exist, right?

It seem not a problem when using nginx luajit VM, am I correct?

@neoxic
Copy link
Owner

neoxic commented Apr 7, 2020

I assume you're talking about OpenResty.

First of all, there's not much sense in using Mongo C Driver (and lua-mongo as a result) in Nginx for one simple reason - it does not have an asynchronous API which means it will block a worker process on each I/O operation. In other words, the absence of an async API defies the whole purpose of Nginx's asynchronous I/O engine.

Not calling mongo_cleanup() doesn't seem to cause any real problems for most cases except when debugging is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants