简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM