You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
config := nebula.GetDefaultConf()
config.MaxConnPoolSize = 200
config.MinConnPoolSize = 200
config.TimeOut = 1 * time.Second
config.IdleTime = 1 * time.Second
var err error
NebulaConnectionPool, err = nebula.NewConnectionPool(hostList, config, nebula.DefaultLogger{})
//300 goroutines to run() concurrently
wg := sync.WaitGroup{}
for i := 0; i < 300; i++ {
wg.Add(1)
go func(){
session, err := NebulaConnectionPool.GetSession(username, password)
if err != nil {
return nil, err
}
nebulaSession.Execute(`some query`)
//program crashed here
}()
}
wg.Wait()
I set TimeOut and IdleTime 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 and config.IdleTime = 1 * time.Second are not works
OS: Linux local-ubuntu3 5.15.0-113-generic
Version: 3.8.0
The text was updated successfully, but these errors were encountered:
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 worksThe text was updated successfully, but these errors were encountered: