Open TangMonk opened 2 months ago
When checking implementation of ConnectionPool, we can state that the parameters of TimeOut, IdleTime was intended to customize the behaviour of the connection made by client and server, it has nothing to do with session created with function call: NebulaConnectionPool.GetSession(username, password)
over connection (which is done with a call to function NebulaConnectionPool.GetSession(username, password)
.
How to release the session which was created over connection (through NebulaConnectionPool).
// Create connection pool
NebulaConnectionPool, _ = nebula.NewConnectionPool(hostList, config, nebula.DefaultLogger{})
// acquire new session over connection pool
session, err := NebulaConnectionPool.GetSession(username, password)
if err != nil {
return nil, err
}
//TODO execute queries over session.Execute("ngql query")
// Release session and return connection back to connection pool
defer session.Release()
BONUS: If you want the session release process being done by client SDK internally, you may consider using the SessionPool with SessionPoolConf instead ConnectionPool
// SessionPool is a pool that manages sessions internally.
//
// Usage:
// Construct
// sessionPool = newSessionPool(conf)
//
// Initialize
// sessionPool.init()
//
// Execute query
// result = sessionPool.execute("query")
//
// Release:
// sessionPool.close()
//
// Notice that all queries will be executed in the default space specified in the pool config.
// SessionPoolConf is the configs of a session pool
// Note that the space name is bound to the session pool for its lifetime
type SessionPoolConf struct {
.......
// Basic pool configs
// Socket timeout and Socket connection timeout, unit: seconds
timeOut time.Duration
// The idleTime of the connection, unit: seconds
// If connection's idle time is longer than idleTime, it will be delete
// 0 value means the connection will not expire
idleTime time.Duration
........
}
I set
TimeOut
andIdleTime
to 1 sec, and run nebula sessions into 300 goroutines, the program will crash somethings, And thoes session are always keep in default 8 hours,config.TimeOut = 1 * time.Second
andconfig.IdleTime = 1 * time.Second
are not works