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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With