ashleydavis / mongodb-rest

REST Server for MongoDB (using node.js)
GNU Lesser General Public License v3.0
75 stars 34 forks source link

Mongo connection pooling #3

Closed rcarmich closed 9 years ago

rcarmich commented 9 years ago

When I hit this server with 3-4 thousand POST requests in a 5-10 second period, mongodb-rest starts failing with "Db open error: failed to connect to [localhost:27017]".

My initial guess was that it wasn't doing connection pooling and that seems confirmed by a quick look at the source code. See https://groups.google.com/forum/#!msg/node-mongodb-native/mSGnnuG8C1o/Hiaqvdu1bWoJ which states you should only do MongoClient.connect once per app.

I'll fork and try to fix sometime next week. I don't know if that will fix my problem but I suspect it will.

ashleydavis commented 9 years ago

Thanks for taking a look, will be great to see what you come up with. There is a bunch of jasmine integration tests you run under jasmine-node to make sure it still works!

rcarmich commented 9 years ago

Just threw something together that seems to work. It passes all the existing tests and fixes my issue - also is significantly faster. But let me know what you think.