Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connection pool in OrientJS

I want to use OrientJS with Express.js. How do I configure a connection pool before any http request is made, acquire and release a connection from the pool during the request/response cycle, and finish the pool when I shutdown the app?

like image 856
André Avatar asked Jul 29 '15 12:07

André


1 Answers

I've looked a bit into OrientJS source and actually found a way to use the built-in ConnectionPool.

You don't need any generic resource pooling module (as I mentioned in my comment above). Basically, it's very straightforward. All you need to do is:

var OrientDB = require('orientjs');

var server = OrientDB({
  host: 'localhost',
  port: 2424,
  username: 'root',
  password: 'yourpassword',
  pool: {
    max: 10
  }
});

Now your server object is using the built in ConnectionPool, and max allowed connections are 10.
If you check server.transport.pool, you'll see the internal pool object.

To actually check how many connections are made (or in use), you can check the length of server.transport.pool.connections (which is an array).

Another way to watch connections' use is a simple bash command:

$ watch -n 0.1 'netstat -p tcp -an | grep 2424'

And you'll see the connections.

From this point, you can start querying right away and the connection pool will be used automatically.

like image 191
xmikex83 Avatar answered Nov 03 '22 01:11

xmikex83