7

I'm implementing a nodejs server which is using mongodb as database and mongodb-native library to connect it.

Further, I'm using clustering to enhance the server performances. So there are two possible ways to use mongodb-native driver's connection pooling;

  1. Create a single connection pool and pass it to each child process when creating them (singleton pattern)
  2. After a child process created, creates a connection pool internally

So, my question is, what's the best methods among two of them? Or is there any other good method to do so?

gihanchanuka
  • 4,783
  • 2
  • 32
  • 32

1 Answers1

0

It depends on your application purposes. Remeber that creating a new pool it's much more expensive than reusing the same pool. Usually I would use option 1, but I repeat, it depends on your application. If all the child processes do an intensive use of db operations maybe it's better to use option 2.

MQ87
  • 1,008
  • 1
  • 13
  • 30