public class PoolingOptions extends Object
The driver uses connections in an asynchronous manner, meaning that multiple requests can be submitted on the same connection at the same time. Therefore only a relatively small number of connections is needed. For each host, the driver uses a connection pool that may have a variable size (it will automatically adjust to the current load).
With ProtocolVersion#V2
or below, there are at most 128 simultaneous
requests per connection, so the pool defaults to a variable size. You will
typically raise the maximum capacity by adding more connections with
setMaxRequestsPerConnection(HostDistance, int)
.
With ProtocolVersion#V3
or above, there are up to 32768 requests per
connection, and the pool defaults to a fixed size of 1. You will typically
raise the maximum capacity by allowing more simultaneous requests per connection
(setMaxRequestsPerConnection(HostDistance, int)
).
All parameters can be separately set for LOCAL
and
REMOTE
hosts (HostDistance
). For IGNORED
hosts,
no connections are created so these settings cannot be changed.
Constructor and Description |
---|
PoolingOptions() |
Modifier and Type | Method and Description |
---|---|
int |
getCoreConnectionsPerHost(HostDistance distance)
Returns the core number of connections per host.
|
int |
getHeartbeatIntervalSeconds()
Returns the heart beat interval, after which a message is sent on an idle connection to make sure it's still alive.
|
int |
getIdleTimeoutSeconds()
Returns the timeout before an idle connection is removed.
|
Executor |
getInitializationExecutor()
Returns the executor to use for connection initialization.
|
int |
getMaxConnectionsPerHost(HostDistance distance)
Returns the maximum number of connections per host.
|
int |
getMaxRequestsPerConnection(HostDistance distance)
Returns the maximum number of requests per connection.
|
int |
getMaxSimultaneousRequestsPerConnectionThreshold(HostDistance distance)
Deprecated.
this method has been renamed to
getNewConnectionThreshold(HostDistance) . This method calls the new one internally,
but you should use the new one in your code. |
int |
getMaxSimultaneousRequestsPerHostThreshold(HostDistance distance)
Deprecated.
this method has been renamed to
getMaxRequestsPerConnection(HostDistance) . This method calls the new one internally,
but you should use the new one in your code. |
int |
getMinSimultaneousRequestsPerConnectionThreshold(HostDistance distance)
Deprecated.
this option isn't used anymore with the current pool resizing algorithm.
|
int |
getNewConnectionThreshold(HostDistance distance)
Returns the threshold that triggers the creation of a new connection to a host.
|
int |
getPoolTimeoutMillis()
Returns the timeout when trying to acquire a connection from a host's pool.
|
void |
refreshConnectedHost(Host host)
Requests the driver to re-evaluate the
HostDistance for a given node. |
void |
refreshConnectedHosts()
Requests the driver to re-evaluate the
HostDistance (through the configured
LoadBalancingPolicy.distance(com.datastax.driver.core.Host) ) for every known
hosts and to drop/add connections to each hosts according to the computed distance. |
PoolingOptions |
setConnectionsPerHost(HostDistance distance,
int core,
int max)
Sets the core and maximum number of connections per host in one call.
|
PoolingOptions |
setCoreConnectionsPerHost(HostDistance distance,
int newCoreConnections)
Sets the core number of connections per host.
|
PoolingOptions |
setHeartbeatIntervalSeconds(int heartbeatIntervalSeconds)
Sets the heart beat interval, after which a message is sent on an idle connection to make sure it's still alive.
|
PoolingOptions |
setIdleTimeoutSeconds(int idleTimeoutSeconds)
Sets the timeout before an idle connection is removed.
|
PoolingOptions |
setInitializationExecutor(Executor initializationExecutor)
Sets the executor to use for connection initialization.
|
PoolingOptions |
setMaxConnectionsPerHost(HostDistance distance,
int newMaxConnections)
Sets the maximum number of connections per host.
|
PoolingOptions |
setMaxRequestsPerConnection(HostDistance distance,
int newMaxRequests)
Sets the maximum number of requests per connection.
|
PoolingOptions |
setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance distance,
int newMaxSimultaneousRequests)
Deprecated.
this method has been renamed to
setNewConnectionThreshold(HostDistance, int) . This method calls the new one
internally, but you should use the new one in your code. |
PoolingOptions |
setMaxSimultaneousRequestsPerHostThreshold(HostDistance distance,
int newMaxRequests)
Deprecated.
this method has been renamed to
setMaxRequestsPerConnection(HostDistance, int) . This method calls the new one internally,
but you should use the new one in your code. |
PoolingOptions |
setMinSimultaneousRequestsPerConnectionThreshold(HostDistance distance,
int newMinSimultaneousRequests)
Deprecated.
this option isn't used anymore with the current pool resizing algorithm.
|
PoolingOptions |
setNewConnectionThreshold(HostDistance distance,
int newValue)
Sets the threshold that triggers the creation of a new connection to a host.
|
PoolingOptions |
setPoolTimeoutMillis(int poolTimeoutMillis)
Sets the timeout when trying to acquire a connection from a host's pool.
|
public int getCoreConnectionsPerHost(HostDistance distance)
distance
- the HostDistance
for which to return this threshold.distance
.public PoolingOptions setCoreConnectionsPerHost(HostDistance distance, int newCoreConnections)
For the provided distance
, this corresponds to the number of
connections initially created and kept open to each host of that
distance.
The default value is:
ProtocolVersion#V2
or below: 2 for LOCAL
hosts and 1 for REMOTE
hosts.ProtocolVersion#V3
or above: 1 for all hosts.distance
- the HostDistance
for which to set this threshold.newCoreConnections
- the value to setPoolingOptions
.IllegalArgumentException
- if distance == HostDistance.IGNORED
,
or if newCoreConnections
is greater than the maximum value for this distance.setConnectionsPerHost(HostDistance, int, int)
public int getMaxConnectionsPerHost(HostDistance distance)
distance
- the HostDistance
for which to return this threshold.distance
.public PoolingOptions setMaxConnectionsPerHost(HostDistance distance, int newMaxConnections)
For the provided distance
, this corresponds to the maximum
number of connections that can be created per host at that distance.
The default value is:
ProtocolVersion#V2
or below: 8 for LOCAL
hosts and 2 for REMOTE
hosts.ProtocolVersion#V3
or above: 1 for all hosts.distance
- the HostDistance
for which to set this threshold.newMaxConnections
- the value to setPoolingOptions
.IllegalArgumentException
- if distance == HostDistance.IGNORED
,
or if newMaxConnections
is less than the core value for this distance.setConnectionsPerHost(HostDistance, int, int)
public PoolingOptions setConnectionsPerHost(HostDistance distance, int core, int max)
This is a convenience method that is equivalent to calling setCoreConnectionsPerHost(HostDistance, int)
and setMaxConnectionsPerHost(HostDistance, int)
.
distance
- the HostDistance
for which to set these threshold.core
- the core number of connections.max
- the max number of connections.PoolingOptions
.IllegalArgumentException
- if distance == HostDistance.IGNORED
,
or if core
> max
.public int getNewConnectionThreshold(HostDistance distance)
distance
- the HostDistance
for which to return this threshold.setNewConnectionThreshold(HostDistance, int)
public PoolingOptions setNewConnectionThreshold(HostDistance distance, int newValue)
A new connection gets created if:
getMaxConnectionsPerHost(HostDistance)
getMaxRequestsPerConnection(HostDistance)
+ getNewConnectionThreshold(HostDistance)
The default value is:
ProtocolVersion#V2
or below: 100 for all hosts.ProtocolVersion#V3
or above: 800 for LOCAL
hosts and 200 for REMOTE
hosts.distance
- the HostDistance
for which to configure this threshold.newValue
- the value to set (between 0 and 128).PoolingOptions
.IllegalArgumentException
- if distance == HostDistance.IGNORED
, or if maxSimultaneousRequests
is not in range, or if newValue
is less than the minimum value for this distance.public int getMaxRequestsPerConnection(HostDistance distance)
distance
- the HostDistance
for which to return this threshold.distance
.setMaxRequestsPerConnection(HostDistance, int)
public PoolingOptions setMaxRequestsPerConnection(HostDistance distance, int newMaxRequests)
The default value is:
ProtocolVersion#V2
or below: 128 for all hosts (there should not be any reason to change this).ProtocolVersion#V3
or above: 1024 for LOCAL
hosts and 256 for REMOTE
hosts.
These values were chosen so that the default V2 and V3 configuration generate the same load on a Cassandra cluster.
Protocol V3 can go much higher (up to 32768), so if your number of clients is low, don't hesitate to experiment with
higher values. If you have more than one connection per host, consider also adjusting
setNewConnectionThreshold(HostDistance, int)
.
distance
- the HostDistance
for which to set this threshold.newMaxRequests
- the value to set.PoolingOptions
.IllegalArgumentException
- if distance == HostDistance.IGNORED
,
or if newMaxConnections
is not within the allowed range.public int getIdleTimeoutSeconds()
public PoolingOptions setIdleTimeoutSeconds(int idleTimeoutSeconds)
The order of magnitude should be a few minutes (the default is 120 seconds). The timeout that triggers the removal has a granularity of 10 seconds.
idleTimeoutSeconds
- the new timeout in seconds.PoolingOptions
.IllegalArgumentException
- if the timeout is negative.public int getPoolTimeoutMillis()
public PoolingOptions setPoolTimeoutMillis(int poolTimeoutMillis)
If no connection is available within that time, the driver will try the next host from the query plan.
The default is 5 seconds. If this option is set to zero, the driver won't wait at all.
poolTimeoutMillis
- the new value in milliseconds.PoolingOptions
IllegalArgumentException
- if the timeout is negative.public int getHeartbeatIntervalSeconds()
public PoolingOptions setHeartbeatIntervalSeconds(int heartbeatIntervalSeconds)
This is an application-level keep-alive, provided for convenience since adjusting the TCP keep-alive might not be practical in all environments.
This option should be set higher than SocketOptions.getReadTimeoutMillis()
.
The default value for this option is 30 seconds.
heartbeatIntervalSeconds
- the new value in seconds. If set to 0, it will disable the feature.PoolingOptions
IllegalArgumentException
- if the interval is negative.public Executor getInitializationExecutor()
setInitializationExecutor(java.util.concurrent.Executor)
public PoolingOptions setInitializationExecutor(Executor initializationExecutor)
Connections are open in a completely asynchronous manner. Since initializing the transport requires separate CQL queries, the futures representing the completion of these queries are transformed and chained. This executor is where these transformations happen.
This is an advanced option, which should be rarely needed in practice. It defaults to
Guava's MoreExecutors.sameThreadExecutor()
, which results in running the transformations
on the network I/O threads; this is fine if the transformations are fast and not I/O bound
(which is the case by default).
One reason why you might want to provide a custom executor is if you use authentication with
a custom Authenticator
implementation that performs blocking
calls.
initializationExecutor
- the executor to usePoolingOptions
NullPointerException
- if the executor is nullpublic void refreshConnectedHosts()
HostDistance
(through the configured
LoadBalancingPolicy.distance(com.datastax.driver.core.Host)
) for every known
hosts and to drop/add connections to each hosts according to the computed distance.public void refreshConnectedHost(Host host)
HostDistance
for a given node.host
- the host to refresh.refreshConnectedHosts()
@Deprecated public int getMinSimultaneousRequestsPerConnectionThreshold(HostDistance distance)
@Deprecated public PoolingOptions setMinSimultaneousRequestsPerConnectionThreshold(HostDistance distance, int newMinSimultaneousRequests)
@Deprecated public int getMaxSimultaneousRequestsPerConnectionThreshold(HostDistance distance)
getNewConnectionThreshold(HostDistance)
. This method calls the new one internally,
but you should use the new one in your code.@Deprecated public PoolingOptions setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance distance, int newMaxSimultaneousRequests)
setNewConnectionThreshold(HostDistance, int)
. This method calls the new one
internally, but you should use the new one in your code.@Deprecated public int getMaxSimultaneousRequestsPerHostThreshold(HostDistance distance)
getMaxRequestsPerConnection(HostDistance)
. This method calls the new one internally,
but you should use the new one in your code.@Deprecated public PoolingOptions setMaxSimultaneousRequestsPerHostThreshold(HostDistance distance, int newMaxRequests)
setMaxRequestsPerConnection(HostDistance, int)
. This method calls the new one internally,
but you should use the new one in your code.Copyright © 2012–2015. All rights reserved.