Reputation: 7144
We are using gocql
(https://github.com/gocql/gocql) driver to connect to Cassandra from our golang server. For every http request, we are creating a new session and inserting rows into cassandra. We feel it is very much resource intensive to create a session for every request.
Typical Code
func NewSession() (*gocql.Session, error) {
config := NewClusterConfig()
if config == nil {
return nil, &CassandraError{"Oops! Cluster initialization failed."}
}
return config.CreateSession()
}
Is there any way to pool the connections in gocql
or any other cassandra drivers for golang?
Upvotes: 3
Views: 3418
Reputation: 3058
You don't need a pool. Create a global Session
. From https://godoc.org/github.com/gocql/gocql#Session:
It's safe for concurrent use by multiple goroutines and a typical usage scenario is to have one global session object to interact with the whole Cassandra cluster.
Upvotes: 5