2

Currently working with Mongodb using the node.js (Native MongoDB) driver, I know it is possible to set the pooled connection count but regardless the same behaviour is observed.

The code in question:

(function init(){
    db.connect("mongodb://localhost/test",function(err, database){

    });
})();

This is the log from the server:

Thu Dec 06 20:19:32 [initandlisten] connection accepted from 127.0.0.1:58663 #6
(1 connection now open)
Thu Dec 06 20:19:32 [initandlisten] connection accepted from 127.0.0.1:58664 #7
(2 connections now open)
Thu Dec 06 20:19:32 [initandlisten] connection accepted from 127.0.0.1:58665 #8
(3 connections now open)
Thu Dec 06 20:19:32 [initandlisten] connection accepted from 127.0.0.1:58666 #9
(4 connections now open)
Thu Dec 06 20:19:32 [initandlisten] connection accepted from 127.0.0.1:58667 #10
 (5 connections now open)
Thu Dec 06 20:19:36 [conn9] end connection 127.0.0.1:58666 (4 connections now op
en)
Thu Dec 06 20:19:36 [conn10] end connection 127.0.0.1:58667 (4 connections now o
pen)
Thu Dec 06 20:19:36 [conn8] end connection 127.0.0.1:58665 (4 connections now op
en)
Thu Dec 06 20:19:36 [conn6] end connection 127.0.0.1:58663 (4 connections now op
en)
Thu Dec 06 20:19:36 [conn7] end connection 127.0.0.1:58664 (4 connections now op
en)

The connections are apparently closing yet the current open connections count doesn't decrement even though the connections are correctly incrementing. Intended behaviour?

PS. Please don't answer with use a nodejs wrapper for mongodb.

1
  • 1
    I'm not able to reproduce this behavior with that code. Whether I kill the process or put a database.close(); call in the callback the connection count goes back down to 0. Commented Dec 6, 2012 at 18:52

1 Answer 1

1

It's problem with MongoDB counter. Database is working asynchronously on closing all your connections (multiple close signals) and it happens so fast that it cannot keep up with updating counter. After browsing MongoDB source code you can see that message output is nowhere near counter update.

Below similar output however with up to 1ms precision which illustrates problem IMO a bit better.

Mon Dec  2 17:42:09.059 [conn675] end connection 127.0.0.1:65198 (9 connections now open)
Mon Dec  2 17:42:09.059 [conn676] end connection 127.0.0.1:65199 (8 connections now open)
Mon Dec  2 17:42:09.059 [conn677] end connection 127.0.0.1:65200 (8 connections now open)
Mon Dec  2 17:42:09.059 [conn678] end connection 127.0.0.1:65201 (7 connections now open)
Mon Dec  2 17:42:09.059 [conn679] end connection 127.0.0.1:65202 (6 connections now open)
Mon Dec  2 17:42:09.059 [conn680] end connection 127.0.0.1:65203 (5 connections now open)
Mon Dec  2 17:42:09.059 [conn681] end connection 127.0.0.1:65204 (4 connections now open)
Mon Dec  2 17:42:09.059 [conn682] end connection 127.0.0.1:65205 (3 connections now open)
Mon Dec  2 17:42:09.059 [conn683] end connection 127.0.0.1:65206 (2 connections now open)
Mon Dec  2 17:42:09.059 [conn684] end connection 127.0.0.1:65207 (2 connections now open)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.