3

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?

kannanrbk
  • 6,964
  • 13
  • 53
  • 94

1 Answers1

5

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.

kopiczko
  • 3,018
  • 1
  • 17
  • 24