wle8300
wle8300

Reputation: 2749

Is it necessary to close database connections?

[using the JavaScript driver]

I've seen on several of the rethinkdb example projects that connections are closed at the end of each query (e.g., conn.close())

While I understand the pedagogical reasons to include that in the tutorials, is it actually performant to manually close connections? I am under the impression that the connection will automatically close once it is out-of-scope

Upvotes: 0

Views: 128

Answers (1)

Shawnbam
Shawnbam

Reputation: 39

You should not leave connections open..

You should:

1) Open connections as late as possible

2) Close connections as soon as possible

The connection itself is returned to the connection pool. Connections are a limited and relatively expensive resource. Any new connection you establish that has exactly the same connection string will be able to reuse the connection from the pool.

Upvotes: 1

Related Questions