vsstage
vsstage

Reputation: 85

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

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.

Upvotes: 1

Views: 1236

Answers (1)

Andrei Karpuszonak
Andrei Karpuszonak

Reputation: 9044

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.

Upvotes: 3

Related Questions