1

I'm developing an application using Node.js and Sails.

I'm going to run like: 20 instances of the same app at the same time, and all of them will use a Local MongoDB to store model data.

My problem started like this: Only the first 7 or 8 launched apps was starting, others were failing because they couldn't connect to the database.

Ok, I went though some searching, and saw that I had to increase the number of connections, but what made me thing something was wrong, is that: Each app launched, is creating about 35 connections!

So, when launching 6 or 8 apps, they were taking about 250 connections!!!

That seems to much, since only one connection per app is enough (I think). Is this 'normal', or is it some problem in Sails Waterline core?

Ivan Seidel
  • 2,394
  • 5
  • 32
  • 49
  • You should only open one connection from Node.js to MongoDB per application. http://stackoverflow.com/a/15688610/446681 – Hector Correa Mar 22 '14 at 21:31
  • @HectorCorrea That's not my problem right now... I can manage to run 6 or 7 apps at the same time without a problem, but since each app is creating about 35 connections, I cannot manage to put more apps on the same machine. The question here, is why is Waterline sails-mongo creating 35 connections for only ONE adapter... – Ivan Seidel Mar 22 '14 at 21:35
  • Also, the 20 instances will be running in a separate Thread... it's parallel tasks, not one app with multiple connections. @HectorCorrea – Ivan Seidel Mar 22 '14 at 21:40
  • Not sure how useful this reference is but looking at the [code](https://github.com/balderdashy/sails-mongo/blob/master/lib/adapter.js#L52-L62) I see that a `default` pool size should be 1. However on a clean startup with just one model defined I see 5 connections being created. – Neil Lunn Mar 23 '14 at 01:32
  • @NeilLunn That's correct. I have 6 models, so, each one of them is creating 5 connections, giving a total of 30 connections PER app. I will have 23 apps, giving a total of 690 connections, where it could only be 23... Am I with the right tought? – Ivan Seidel Mar 23 '14 at 01:35
  • I'm having the same problem. Did you find any solutions? Is it normal? – Fogia May 22 '14 at 12:49

1 Answers1

0

Any solution on this issue?

I have the same issue ( load balanced instances connecting to mongo ) without using sails...

Another issue is that due to "zero downtime deploy" i clone the cluster and then change the DNS so temporarily having double amount of connections.

So on my case i'm also listening to SIGINT and SIGQUIT and closing the connections before the app terminates, so then hopefully "keep alive" connections will die together with the app.

There is tons of people with similar problems around, but i failed to find a spot-on solution /=

kroe
  • 1,116
  • 3
  • 11
  • 23
  • Forget Sails. Start using Geddy (http://geddyjs.org/). That solved (all) of my problems... – Ivan Seidel Jan 13 '15 at 15:46
  • I fixed that long time ago.. But for a "workaround", I guess that I just increased the number of accepted connection in Mongo. However, not the best solution, solved my problems... – Ivan Seidel Jan 13 '15 at 18:02