mongodb-labs / mongorover

Intern project - MongoDB driver for the Lua programming language - This Repository is NOT a supported MongoDB product
Apache License 2.0
55 stars 10 forks source link

pool support #64

Open malexzx opened 7 years ago

malexzx commented 7 years ago

one nice feature - mongo pool as must have be in mongorover. it might be a simple implemented for short lived lua sessions for example. (while gc on destroy - return connection to back to pool). Does any known issues, that this idea won't work, or maybe hard to implemented on that way? I'm may be try to implement this feature (since it may be needed me in production).

ajdavis commented 7 years ago

Can you tell me more about your idea? I think the C Driver's mongoc_client_pool_t is useful only for multithreaded applications. A single-threaded application can just use one mongoc_client_t for all operations. But I don't know much about Lua so perhaps your idea is useful.

malexzx commented 7 years ago

Hello @ajdavis ! In my case short lived lua scripts is executed in multiple threads (web server with lua handle requests by lua for example). For this purpose first of all, we need init a pool by providing mongo url (may be outside lua code or by lazy technique). Then pool may be used per query execution, i.e. get client from pool for execute query then return back to pool. Another proposed use case is get pooled client and release it after gc (may be at lua state destroy). Another use case may be use this approach in coroutines (but it is more complex to implement). It requires to overlap mongo-c driver with coroutine too. That method is would allow us to send and receive data (mongo query) in asynchronous manner.

ajdavis commented 7 years ago

Sounds interesting, and it resembles how the new PHP driver does connection pooling. Let me dig up some documentation about that....

malexzx commented 7 years ago

Thank you for pointing me about PHP. http://php.net/manual/en/mongo.connecting.pools.php is said, that now pooling is not used. I'm try to investigate now why that needs.