Cassandra Best Practices

I am using Node JS with Cassandra and I am wondering what is the best way to interact. I have several modules that interact with Cassandra and I want to know if it is better

  • save one connection for all modules
  • establish a connection for each module or, if better,
  • Connect to Cassandra every time I have a request.

This web application uses Cassandra for most requests.

+4
source share
2 answers

DataStax Node.js Cassandra, , , .

var cassandra = require('cassandra-driver');
var client = new cassandra.Client({
  contactPoints: ['host1', 'host2'], 
  keyspace: 'ks1'
});
var query = 'SELECT email, last_name FROM user_profiles WHERE key=?';
//the driver will handle connection pool and failover
client.execute(query, ['guy'], function(err, result) {
  assert.ifError(err);
  console.log('User profile email ' + result.rows[0].email);
});

:

+2

, . . , , , , .

- :

no connections are available in pool
  create connection (add it back once finished using it)
connections are available in pool
  fetch connection from pool

, :

  • . , ,
  • - . , , .
  • Cassandra , . ( ), !

.

Cluster cluster = Cluster.builder().addContactPoints("localhost").build();
long start = System.currentTimeMillis();
Session session = cluster.connect();
System.out.println(String.format("Took %s ms", System.currentTimeMillis() - start));

: 490 .

+2

All Articles