vesoft-inc / nebula-python

Client API of Nebula Graph in Python
194 stars 76 forks source link

Add session pool #229

Closed Aiee closed 1 year ago

Aiee commented 1 year ago

Why we need a session pool

The purpose of adding the session pool is to solve the problem caused by improperly using the connection pool. For example, a common case is that the user generates a new session, executes a query, and releases the session in a loop, like:

// Wrong usage of the connection pool
for(int i=0; i<100; i++) {
  // get new session
  // execute query
  // release session
}

This will cause huge traffic in the meta service and may crash the service.

Usage

See example/SessinPoolExample.py for a more detailed example.

The usage of the connection pool remains unchanged.

Limitation

There are some limitations:

  1. There MUST be an existing space in the DB before initializing the session pool.
  2. Each session pool is corresponding to a single USER and a single Space. This is to ensure that the user's access control is consistent. i.g. The same user may have different access privileges in different spaces. If you need to run queries in different spaces, you may have multiple session pools.
  3. Every time when sessinPool.execute() is called, the session will execute the query in the space set in the session pool config.
  4. Commands that alter passwords or drop users should NOT be executed via session pool.