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. This means that the driver only needs to maintain a relatively small number of connections to each Cassandra host. These options allow the driver to control how many connections are kept exactly.
For each host, the driver keeps a core pool of connections open at all
times determined by calling (getCoreConnectionsPerHost(com.datastax.driver.core.HostDistance)
).
If the use of those connections reaches a configurable threshold
(getMaxSimultaneousRequestsPerConnectionThreshold(com.datastax.driver.core.HostDistance)
),
more connections are created up to the configurable maximum number of
connections (getMaxConnectionsPerHost(com.datastax.driver.core.HostDistance)
). When the pool exceeds
the maximum number of connections, connections in excess are
reclaimed if the use of opened connections drops below the
configured threshold (getMinSimultaneousRequestsPerConnectionThreshold(com.datastax.driver.core.HostDistance)
).
Each of these parameters can be separately set for LOCAL
and
REMOTE
hosts (HostDistance
). For IGNORED
hosts,
the default for all those settings is 0 and 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 |
getMaxConnectionsPerHost(HostDistance distance)
Returns the maximum number of connections per host.
|
int |
getMaxSimultaneousRequestsPerConnectionThreshold(HostDistance distance)
Returns the number of simultaneous requests on all connections to an host after
which more connections are created.
|
int |
getMinSimultaneousRequestsPerConnectionThreshold(HostDistance distance)
Returns the number of simultaneous requests on a connection below which
connections in excess are reclaimed.
|
PoolingOptions |
setCoreConnectionsPerHost(HostDistance distance,
int coreConnections)
Sets the core number of connections per host.
|
PoolingOptions |
setMaxConnectionsPerHost(HostDistance distance,
int maxConnections)
Sets the maximum number of connections per host.
|
PoolingOptions |
setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance distance,
int maxSimultaneousRequests)
Sets number of simultaneous requests on all connections to an host after
which more connections are created.
|
PoolingOptions |
setMinSimultaneousRequestsPerConnectionThreshold(HostDistance distance,
int minSimultaneousRequests)
Sets the number of simultaneous requests on a connection below which
connections in excess are reclaimed.
|
public int getMinSimultaneousRequestsPerConnectionThreshold(HostDistance distance)
If an opened connection to an host at distance distance
handles less than this number of simultaneous requests and there is
more than getCoreConnectionsPerHost(com.datastax.driver.core.HostDistance)
connections open to this
host, the connection is closed.
The default value for this option is 25 for LOCAL
and
REMOTE
hosts.
distance
- the HostDistance
for which to return this threshold.public PoolingOptions setMinSimultaneousRequestsPerConnectionThreshold(HostDistance distance, int minSimultaneousRequests)
distance
- the HostDistance
for which to configure this threshold.minSimultaneousRequests
- the value to set.PoolingOptions
.IllegalArgumentException
- if distance == HostDistance.IGNORED
.public int getMaxSimultaneousRequestsPerConnectionThreshold(HostDistance distance)
If all the connections opened to an host at distance distance
connection are handling more than this number of
simultaneous requests and there is less than
getMaxConnectionsPerHost(com.datastax.driver.core.HostDistance)
connections open to this host, a
new connection is open.
Note that a given connection cannot handle more than 128 simultaneous requests (protocol limitation).
The default value for this option is 100 for LOCAL
and
REMOTE
hosts.
distance
- the HostDistance
for which to return this threshold.public PoolingOptions setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance distance, int maxSimultaneousRequests)
distance
- the HostDistance
for which to configure this threshold.maxSimultaneousRequests
- the value to set.PoolingOptions
.IllegalArgumentException
- if distance == HostDistance.IGNORED
.public int getCoreConnectionsPerHost(HostDistance distance)
For the provided distance
, this correspond to the number of
connections initially created and kept open to each host of that
distance.
distance
- the HostDistance
for which to return this threshold.distance
.public PoolingOptions setCoreConnectionsPerHost(HostDistance distance, int coreConnections)
distance
- the HostDistance
for which to set this threshold.coreConnections
- the value to setPoolingOptions
.IllegalArgumentException
- if distance == HostDistance.IGNORED
.public int getMaxConnectionsPerHost(HostDistance distance)
For the provided distance
, this correspond to the maximum
number of connections that can be created per host at that distance.
distance
- the HostDistance
for which to return this threshold.distance
.public PoolingOptions setMaxConnectionsPerHost(HostDistance distance, int maxConnections)
distance
- the HostDistance
for which to set this threshold.maxConnections
- the value to setPoolingOptions
.IllegalArgumentException
- if distance == HostDistance.IGNORED
.Copyright © 2014. All Rights Reserved.