Pros/cons to connecting directly to database vs. first to server?

#1

Per the docs (http://orientdb.com/docs/last/OrientJS-Database.html), it’s possible to use the ODatabase class to connect to the database without first establishing a server connection. What, if anything, are the pros or cons of one method over the other?

#2

Hi Eric,

i have just started to read/learn about graph db-ODB especially , therefore please don’t take my answer as 100% correct.

As far as i can understand we should open a connection to DB if we need to consume DB API and to the server in order to consume the server API.
It looks like a separation of concerns or scopes.

Overall, i am seeing this option as an improvement of the js client.
The “old” way: server connection & db connection -> means 2 open connections ( just checked out with console: list connections) -> 2 processes.
The new way only one PID.

Best regards,

#3

Hi @eric24,

yes @cocopapagal, it is correct. ODatabase was the first attempt in 2.2.x of removing the need of server connection which didn’t make much sense as the entry point for the client

In the new APIs of OrientJS there is no concept anymore
You just create a client and sessions with a database.

https://orientdb.com/docs/3.0.x/orientjs/OrientJS.html

#4

Makes sense. There is some inconsistency in the docs, so I wanted to confirm that this is the correct/preferred way to connect and create a session pool (using promises):

let client = await OrientDBClient.connect({
  host: '...',
  port: 2424,
  pool: {max: 10}
});

let pool = await client.sessions({
  name: '...',
  username: '...',
  password: '...'
});
#5

Yes you create a pool of sessions that you can use in your application with acquire/release

#6

OK, to be clear, it’s:

let session = pool.acquire();
// (do work with the session)
session.close();

Right? I’m not seeing a “release” function in OrientJS.

#7

@eric24

yes sorry session.close if the session is pooled, it will be returned to the pool instead of closed

Thanks

#8

@wolf4ood: One more question about this. In my original example:

let client = await OrientDBClient.connect({
  host: '...',
  port: 2424,
  pool: {max: 10}
});

let pool = await client.sessions({
  name: '...',
  username: '...',
  password: '...'
});

I supply a pool property in the config for the client connection, but no pool in the config for the pool sessions. I saw something recently that leads me to understand that the pool property has different purposes in each of these two places, but I could not find anything in the documentation on this. Can you explain the purpose and recommendations for pool in both configs?

#9

Hi @eric24

yes it has different purpose. The one on the client is the pool of sockets available to the driver.

The second is the number of session max opened for that specific pool with a database and credentials.
Sessions are multiplexed to the sockets.

Depending on the load but 20 should be fine for sessions.

#10

@wolf4ood: OK. Can you explain the relationship between these? If you say 20 should be fine for sessions, what is the corresponding recommendation for sockets? Why would you have fewer (or more) sockets than sessions, for example?

#11

Hi @eric24

sessions can send messages over any sockets available from the pool.
Depends on the use case, sockets can be fewer that sessions. More does not make much sense.
For example if you have 1 session and 20 sockets you are not going to scale since the server lock on the single session. That’s why you need multiple sessions for parallel requests.
A balanced configuration should be fine 20/20

In more advanced use case for example you may want to have access to multiple databases from OrientJS. In that use case you can configure a base socket pool and multiple pools of sessions that will use the same socket for not wasting to much resources.

Let me know if this helps

Thanks

#12

Hi @wolf4ood
Yes, that makes sense. That was my impression, but it’s always good to hear from someone closer to the code!
Thanks

1 Like