Search:

Search all manuals
Search this manual
Manual
Couchbase Client Library: Java 1.1
Community Wiki and Resources
Download Client Library
JavaDoc
Couchbase Developer Guide 2.0
Couchbase Server Manual 2.0
Java Client Library
SDK Forum
Wiki: Java Client Library
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
3 Using the APIs
Chapter Sections
Chapters

3.3. Setting runtime Parameters for the CouchbaseConnectionFactoryBuilder

A final approach to creating the connection is using the CouchbaseConnectionFactoryBuilder and CouchbaseConnectionFactory classes.

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 CouchbaseClient object.

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.

cfb.setOpTimeout(10000);

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

ParameterDescriptionDefault valueWhen to Override the default value
opTimeoutTime in millisecs for an operation to Timeout2500 millisecs.You can set this value higher when there is heavy network traffic and timeouts happen frequently.
timeoutExceptionThresholdNumber of operations to timeout before the node is deemed down998You can set this value lower to deem a node is down earlier.
readBufSizeRead Buffer Size16384You can set this value higher or lower to optimize the reads.
opQueueMaxBlockTimeThe 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.
shouldOptimizeOptimize behavior for the networkFalseYou 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.
maxReconnectDelayMaximum number of milliseconds to wait between reconnect attempts.30000 millisecs.You can set this value lower when there is intermittent and frequent connection failures.
MinReconnectIntervalA default minimum reconnect interval in millisecs.1100This 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.
obsPollIntervalWait for the specified interval before the Observe operation polls the nodes.400Set 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.
obsPollMaxThe maximum times to poll the master and replica(s) to meet the desired durability requirements.10You could set this value higher if the Observe operations do not complete after the normal polling.