A final approach to creating the connection is using the
It's possible to ovverride some of the default paramters that are
defined in the
CouchbaseConnectionFactoryBuilder for a variety
of reasons and customize the connection for the session depending
on expected load on the server and potential network traffic.
For example, in the following program snippet, we instatiate a new
CouchbaseConnectionFactoryBuilder and use the
setOpTimeout method to change the default value
to 10000ms (or 10 secs).
We subsequently use the
buildCouchbaseConnection specifying the bucket
name, password and an username (which is not being used any more)
to get a
CouchbaseConnectionFactory object. We
then create a
List<URI> baseURIs = new ArrayList<URI>(); baseURIs.add(base); CouchbaseConnectionFactoryBuilder cfb = new CouchbaseConnectionFactoryBuilder(); // Ovveride default values on CouchbaseConnectionFactoryBuilder // For example - wait up to 10 seconds for an operation to succeed cfb.setOpTimeout(10000); CouchbaseConnectionFactory cf = cfb.buildCouchbaseConnection(baseURIs, "default", "", ""); client = new CouchbaseClient((CouchbaseConnectionFactory) cf);
For example, the following code snippet will set the OpTimeOut value to 10000 secs. before creating the connection as we saw in the code above.
These parameters can be set at runtime by setting a property on the command line (such as -DopTimeout=1000) or via properties in a file cbclient.properties in that order of precedence.
The following parameters can be set as summarized in the table below. We provide the parameter name, a brief description, the default value and why the particular parameter might need to be modified.
Table 3.1. Parameters that can be set via CouchbaseConnectionFactoryBuilder
|Parameter||Description||Default value||When to Override the default value|
|Time in millisecs for an operation to Timeout||2500 millisecs.||You can set this value higher when there is heavy network traffic and timeouts happen frequently.|
|Number of operations to timeout before the node is deemed down||998||You can set this value lower to deem a node is down earlier.|
|Read Buffer Size||16384||You can set this value higher or lower to optimize the reads.|
|The maximum time to block waiting for op queue operations to complete, in milliseconds.||10000 millisecs.||The default has been set with the expectation that most requests are interactive and waiting for more than a few seconds is thus more undesirable than failing the request. However, this value could be lowered for operations not to block for this time.|
|Optimize behavior for the network||False||You can set this value to be true if the performance should be optimized for the network as in cases where there are some known issues with the network that may be causing adverse effects on applications.|
|Maximum number of milliseconds to wait between reconnect attempts.||30000 millisecs.||You can set this value lower when there is intermittent and frequent connection failures.|
|A default minimum reconnect interval in millisecs.||1100||This means that if a reconnect is needed, it won't try to reconnect more frequently than default value. The internal connections take up to 500ms per request. You can set this to higher to try reconnecting less frequently.|
|Wait for the specified interval before the Observe operation polls the nodes.||400||Set this higher or lower depending on whether the polling needs to happen less or more frequently depending on the tolerance limits for the Observe operation as compared to other operations.|
|The maximum times to poll the master and replica(s) to meet the desired durability requirements.||10||You could set this value higher if the Observe operations do not complete after the normal polling.|