Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Node.js + Oracle - Leave connection open or close after each request?

Node.js + Oracle - Leave connection open or close after each request?

Problem

I have a web application that uses Node.js & a connection to an Oracle Database.

Currently my architecture between Node and the DB uses one connection, that stays open. The issue is that some queries take a long time to return, thus blocking subsequent queries until the first returns.

If I open a new connection on each request this does not happen, and the subsequent queries will return before the first (long) one.

The question is what is best practice? Does each request merit a new connection to the database to be closed on callback, should I prioritize queries that I know to take significant time with their own connection, Or is a single connection correct?

Many thanks in advance for your thoughts.

Problem courtesy of: vsstage

Solution

You could use generic-pool module, which is generic resource pool to reuse expensive resources such as database connections

General idea is that you create a connection pool with certain amount of connections (10 by default). Connections are reused, they will be kept for a certain max idle time (30 seconds by default).

I use this module for Oracle database in production, and found no issues so far.

Solution courtesy of: Andrei Karpushonak

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Node.js + Oracle - Leave connection open or close after each request?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×