Iridium icon indicating copy to clipboard operation
Iridium copied to clipboard

Question: Managing connections in Iridium

Open mas-dude opened this issue 7 years ago • 4 comments

What is the best way to manage connections when using Iridium with Express? Should I be opening a single connection on app start and then use that for the life of the application or should I be creating a connection per request?

I have been following this sample which uses Iridium and creates a connection per repository operation but contradicts this advice.

Just wanting to make sure if there is anything in Iridium that might be doing something different.

mas-dude avatar Sep 28 '17 04:09 mas-dude

Hi @mas-dude, you should ideally be holding open a connection for the duration of your application's life cycle since the underlying MongoDB driver manages connection reuse and pooling automatically.

With inversify, you would probably be best off injecting a connected Iridium instance singleton into your repositories. This also avoids the startup cost of building your models and improves V8's ability to optimise bytecode for your specific models.

notheotherben avatar Sep 28 '17 11:09 notheotherben

Thanks @SPARTAN563. That is very helpful.

mas-dude avatar Sep 28 '17 21:09 mas-dude

I had this exact same question. Might be worth addressing directly in the documentation.

CatGuardian avatar Jan 01 '18 23:01 CatGuardian

I've forked the example repository in question that you were referring to as a sample, I've updated its dependencies and added socket.io injection. I will update it to implement this best practice, as i've done so with our closed source professional projects.

Kaffiend avatar Mar 24 '18 05:03 Kaffiend