I'm trying to write a website in Perl with Mason. I setup a server with the following: - Apache with mod_perl with Mason - CGI::Session for managing session - MongoDB for database.
My concern is, each time I connect to my MongoDB database, the connection stays alive until I restart httpd service. Thus, if the maximum connection is reached, I can't open anymore connections.
Does anyone have a way to:
- either close the connection (which might not be a good idea) ?
- either have a global pool of db connections knowing the architecture ?
The MongoDB driver keeps the connection alive as long as your
MongoClient
instance exists. In an environment likemod_perl
, the Perl interpreter is a persistent process and global variables will hang around until they are destroyed.If you don't want the connections to be persistent, create a
MongoClient
object with a scope that will end when the HTTP request cycle is complete. The connections will be closed when the objects are garbage-collected.If you update your question with more details about how you're creating your client objects I can provide a more detailed answer.