0

What is the recommended way to manage OrientDB connections in Express.js or any web application for that matter? Connection per request? Would be using the oriento Node.js driver

9me
  • 1,078
  • 10
  • 36
Samuel Goldenbaum
  • 18,391
  • 17
  • 66
  • 104

1 Answers1

0

If you are using Oriento, you can try connection pooling, as per PR #7 you can set it like this:

var server = Oriento({
  user: 'root',
  password: 'foo',
  pool: {
    max: 10 // use a maximum of 10 sockets in the pool
  }
});

Please bear in mind that at some point connection pooling config was hidden from Oriento's README due to issues with thread safety [...] in orientdb (reference). You may want to clear that before using it.

Dário
  • 2,002
  • 1
  • 18
  • 28
  • Thanks for the reply Dario. I am interested to see when the connection should be opened and closed. Should we be opening a connection per request and closing it at the end of the request? – Samuel Goldenbaum May 29 '15 at 11:23
  • Well, opening a connection per request could exhaust the maximum number of OrientDB connections (50 by default, I believe) so I don't recommend that. I recommend either using a single connection or a pool (mind the caveat I mentioned earlier) which should be setup before receiving requests. Oriento will reconnect by itself if the existing connection fails. Closing and opening connections may also introduce an overhead. – Dário May 29 '15 at 12:15
  • Normal web practice would be to open a connection, preferably a transaction, at the start of the request and then commit/close at the end of the request so connections are released. Going to run some tests... – Samuel Goldenbaum May 30 '15 at 15:54
  • I'm not sure what "Normal web practice" is, I guess that will depend on the source you quote. Using a connection pool is very common to reduce the overhead of connecting and disconnecting to the DB. For example, sequelize, a popular SQL ORM suggests a pool with 5 connections in its [getting started docs](http://docs.sequelizejs.com/en/latest/docs/getting-started/). Every time a query is issued one of those connections will be used and then released for other queries to use, without the need of establishing new connections. – Dário May 30 '15 at 19:01