bitly/asyncmongo — pull request #45 by ceymard (2012-04-02 11:39:11+00:00)
Title: Maxconnection now just limits the concurrent connections to mongodb inst...

...ead of raising an exception when the maxconnections are reached.

As the title of the commit says, I modified ConnectionPool and Cursor so that when reaching the maxconnections, instead of raising an Exception, we just queue the requests in the connectionpool.

Whenever a connection goes back into the cache, the backlog of requests is checked, and if not empty, a (now) free connection is given to the leftmost callback in the backlog.

I did this patch because I ran into a file descriptor limit problem while using asyncmongo.

I have a system wired to RabbitMQ, that sometimes receives ~10000 messages in a few seconds, each of which triggering a request to the MongoDB server. Instead of throttling my own system, I thought it would be interesting to give asyncmongo the possibility of throttling it itself, since I doubt I will be the only one in such a case.

While I removed the raise TooManyConnections altogether, maybe if you prefer, I could add a variable to switch behaviours at will ?