Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IdleTime and TimeOut connection config not works #347

Open
TangMonk opened this issue Jul 12, 2024 · 1 comment
Open

IdleTime and TimeOut connection config not works #347

TangMonk opened this issue Jul 12, 2024 · 1 comment

Comments

@TangMonk
Copy link

TangMonk commented Jul 12, 2024

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
@egasimov
Copy link

egasimov commented Sep 4, 2024

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
       ........
} 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants