7
votes

The documentation of the com.datastax.driver.core.Session class states that

(...) Each session maintains multiple connections to the cluster nodes (...)

However, general advice for EE environments is to leave pooling and thread management to the container.

It seems to me that the DataStax driver, which is not primarily targeted at EE environments, violates this rule. This makes me worry whether the driver can be safely used in my EE application.

2

2 Answers

5
votes

I do remember that advice. I think that's an old recommendation meant to emphasize that in most of the cases the application should not try to do extra thread management for the container (the key word here is "container"). Also messing up with threads might lead to over utilizing the resources of your server. In the days of single/dual-cores that was quite important.

Anyways, today we have:

  1. more cores
  2. more applications that use an asynchronous model

The DataStax driver allows you to configure the max thread pool sizes so you can keep things under your control.

Concluding, I think it should be pretty safe to use the driver. You can tune the thread pool according to your app needs and server(s) resources.

5
votes

The advantage of having multiple connections, regardless of environment, is that the Java client is token aware. This means it knows where the data is in the cluster, and it can therefore fire off queries to the correct node, thereby avoiding unnecessary lookups to other nodes for data that node doesn't own. Additionally, the client is aware of the cluster and its state, and it can redirect failed requests to other nodes transparently. If you only maintained one connection to a single machine, your application would fire requests off naively.