I have an webservice API allowing client to insert into Cassandra. I read the document on the page of datastax (http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/Session.html) stating that we should keep the session and cluster object till the end of the application. I was wondering should I call session.close() and cluster.close() after each web API call or I just keep the session until I shutdown web server?
相关问题
- What version of Java does Cassandra 3 require
- Filter from Cassandra table by RDD values
- cassandra: can you query against a collection fiel
- How to understand the 'Flexible schema' in
- NoHostAvailableException With Cassandra & DataStax
相关文章
- Cassandra Read a negative frame size
- How does cassandra split keyspace data when multip
- How does Cassandra scale horizontally ?
- NoSQL Injection? (PHP->phpcassa->Cassandra)
- Executing CQL through Shell Script?
- Spark and Cassandra Java Application Exception Pro
- How to access the local data of a Cassandra node
- how to connect cassandra from local to EC2 instanc
I would advise against creating a
Session
each time you receive a request. Each time you create aSession
viaCluster.connect
the java-driver will create a connection pool to a number of Hosts to your Cassandra Cluster.For example, using default settings, if you have 8 cassandra nodes in a single datacenter, with the 2.0.9 version of the driver it will create 8 pooled connections to each Host (this will change to 2 in the next version). This would create 64 connections each time you create a
Session
.It would be more preferable to have a shared
Session
that your web server can use. The driver can manage multiple requests per connection (default 128 per connection by default in 2.0.x), so no need to worry about contention in sharing a singleSession
object.