Client Settings
- reference
The ClusterOptions class enables you to configure Python SDK options for bootstrapping, timeouts, reliability, and performance.
Client settings are provided to the Cluster via the ClusterOptions class or keyword arguments with ClusterOptions being preferred. While all settings can be passed to the Cluster
as keyword arguments, when using ClusterOptions, some options are grouped into other option classes, namely ClusterTimeoutOptions, ClusterTracingOptions and TransactionConfig.
Once it is passed in to the Cluster constructor or Cluster.connect, its settings are fixed.
# Create a cluster using the custom client settings.
cluster = Cluster.connect(connectionString, ClusterOptions(
PasswordAuthenticator(username, password), option1=xxx, option2=yyy...))
# [Your code to interact with the cluster]
Cluster Options
The following sections cover all possible cluster options and explain their usage and default values. They are categorized into groups for security, I/O, timeout, compression, tracing, transactions, and general options.
Security Options
By default the client will connect to Couchbase Server using an unencrypted connection. If you are using the Enterprise Edition, it’s possible to secure the connection using TLS. For connecting to Couchbase Capella — our fully hosted cloud service — TLS is a prerequisite.
- Name: Enable Secure Connections
-
Options Class:
ClusterOptionsParameter:
enable_tls: Optional[bool]Default:
FalseSet this to
Trueto encrypt all communication between the client and server using TLS. This feature requires the Enterprise Edition of Couchbase Server 3.0 or later. If TLS is enabled you must also specify the trusted certificates by providing thecert_pathwhen using thePasswordAuthenticatoror providing the client certificate and key when using theCertificateAuthenticator. Please see the Managing Connections section for more details on how to set it up properly. - Name: TLS Verify Mode
-
Options Class:
ClusterOptionsParameter:
tls_verify: Optional[Union[TLSVerifyMode, str]]Default:
TLSVerifyMode.PEERSet this to
TLSVerifyMode.NONEto disable certificate verification.
The Python 3.x SDK allowed for ssl=no_verify to be passed in as part of the connection string. While this is still permitted in the 4.x SDK, the preferred method would be to pass in tls_verify=TLSVerifyMode.NONE in the ClusterOptions.
|
- Name: TLS Certificate Location
-
Options Class:
ClusterOptionsParameter:
trust_store_path: Optional[str]Default:
NonePath to a file containing a single X.509 certificate to trust as a Certificate Authority when establishing secure connections.
I/O Options
- Name: DNS SRV Enabled
-
Options Class:
ClusterOptionsParameter:
enable_dns_srv: Optional[bool]Default:
TrueGets the bootstrap node list from a DNS SRV record. See the Connection Management section for more information on how to use it properly.
- Name: Use IP Protocol
-
Options Class:
ClusterOptionsParameter:
use_ip_protocol: Optional[Union[IpProtocol, str]]Default:
IpProtocol.AnySet to IpProtocol.ForceIPv4 to force client to use IPv4. Set to IpProtocol.ForceIPv6 to force client to use IPv6.
- Name: Mutation Tokens Enabled
-
Options Class:
ClusterOptionsParameter:
enable_mutation_tokens: Optional[bool]Default:
TrueMutation tokens allow enhanced durability requirements as well as advanced SQL++ (formerly N1QL) querying capabilities. Set this to
Falseif you do not require these features and wish to avoid the associated overhead. - Name: Network Resolution
-
Options Class:
ClusterOptionsParameter:
network: Optional[str]Default:
autoThe network value should be one of auto,default, orexternal(lower case).Each node in the Couchbase Server cluster might have multiple addresses associated with it. For example, a node might have one address that should be used when connecting from inside the same virtual network environment where the server is running, and a second address for connecting from outside the server’s network environment.
By default the client will use a simple matching heuristic to determine which set of addresses to use (it will select the set of addresses that contains a seed node’s host and port).
If you wish to override the heuristic, you can set this value to
defaultif the client is running in the same network as the server, orexternalif the client is running in a different network. - Name: Socket Keepalive
-
Options Class:
ClusterOptionsParameter:
enable_tcp_keep_alive: Optional[bool]Default:
TrueIf enabled, the client periodically sends a TCP keepalive to the server to prevent firewalls and other network equipment from dropping idle TCP connections.
- Name: Socket Keepalive Interval
-
Options Class:
ClusterOptionsParameter:
tcp_keep_alive_interval: Optional[timedelta]Default:
NoneThis setting only propagates to the OS on Linux when the epoll transport is used. On all other platforms, the OS-configured time is used (and you need to tune it there if you want to override the default interval). - Name: Max HTTP Endpoints per Service per Node
-
Options Class:
ClusterOptionsParameter:
max_http_connections: Optional[int]Default:
NoneEach service (except the Key/Value service) has a separate dynamically sized pool of HTTP connections for issuing requests. This setting puts an upper bound on the number of HTTP connections in each pool.
- Name: Idle HTTP Connection Timeout
-
Options Class:
ClusterTimeoutOptionsParameter:
idle_http_connection_timeout: Optional[timedelta]Default:
NoneThe length of time an HTTP connection may remain idle before it is closed and removed from the pool. Durations longer than 50 seconds are not recommended, since some services have a 1 minute server side idle timeout.
- Name: Config Poll Interval
-
Options Class:
ClusterOptionsParameter:
config_poll_interval: Optional[timedelta]Default:
NoneThe interval at which the client fetches cluster topology information in order to proactively detect changes.
- Name: Config Poll Floor
-
Options Class:
ClusterOptionsParameter:
config_poll_floor: Optional[timedelta]Default:
NoneThe interval at which the client fetches cluster topology information in order to proactively detect changes.
Timeout Options
The default timeout values are suitable for most environments, and should be adjusted only after profiling the expected latencies in your deployment environment. If you get a timeout exception, it may be a symptom of another issue; increasing the timeout duration is sometimes not the best long-term solution.
Most timeouts can be overridden on a per-operation basis (for example, by passing a custom options block to a "get" or "query" method). The values set here are used as the defaults when no per-operation timeout is specified.
Timeout settings are configured using an instance of ClusterTimeoutOptions or passed in as keyword arguments.
timeout_options=ClusterTimeoutOptions(kv_timeout=timedelta(seconds=5), query_timeout=timedelta(seconds=10))
options=ClusterOptions(PasswordAuthenticator('username', 'password'), timeout_options=timeout_options)
cluster.connect('couchbase://host',options)
- Name: Bootstrap Timeout
-
Options Class:
ClusterTimeoutOptionsParameter:
bootstrap_timeout: Optional[timedelta]Default:
NoneBootstrap timeout.
- Name: Connect Timeout
-
Options Class:
ClusterTimeoutOptionsParameter:
connect_timeout: Optional[timedelta]Default:
NoneThe connect timeout is used when a Bucket is opened and if not overridden by a custom timeout. If you feel the urge to change this value to something higher, there is a good chance that your network is not properly set up. Connecting to the server should in practice not take longer than a second on a reasonably fast network.
- Name: Resolve Timeout
-
Options Class:
ClusterTimeoutOptionsParameter:
resolve_timeout: Optional[timedelta]Default:
NoneResolve timeout.
- Name: Key-Value Timeout
-
Options Class:
ClusterTimeoutOptionsParameter:
kv_timeout: Optional[timedelta]Default:
NoneThe Key/Value default timeout is used on operations which are performed on a specific key if not overridden by a custom timeout. This includes all commands like get(), get_from_replica() and all mutation commands, but does not include operations that are performed with enhanced durability requirements.
- Name: Key-Value Durable Timeout
-
Options Class:
ClusterTimeoutOptionsParameter:
kv_durable_timeout: Optional[timedelta]Default:
NoneKey/Value operations with enhanced durability requirements may take longer to complete, so they have a separate default timeout.
Do not set this above 65s, which is the maximum possible
SyncWritetimeout on the Server side.The kv_durable_timeoutproperty is not part of the stable API and may change or be removed at any time. - Name: View Timeout
-
Options Class:
ClusterTimeoutOptionsParameter:
views_timeout: Optional[timedelta]Default:
NoneThe View timeout is used on view operations if not overridden by a custom timeout. Note that it is set to such a high timeout compared to key/value since it can affect hundreds or thousands of rows. Also, if there is a node failure during the request the internal cluster timeout is set to 60 seconds.
- Name: Query Timeout
-
Options Class:
ClusterTimeoutOptionsParameter:
query_timeout: Optional[timedelta]Default:
NoneThe Query timeout is used on all SQL++ query operations if not overridden by a custom timeout. Note that it is set to such a high timeout compared to key/value since it can affect hundreds or thousands of rows.
- Name: Analytics Timeout
-
Options Class:
ClusterTimeoutOptionsParameter:
analytics_timeout: Optional[timedelta]Default:
NoneThe Analytics timeout is used on all Analytics query operations if not overridden by a custom timeout. Note that it is set to such a high timeout compared to key/value since it can affect hundreds or thousands of rows.
- Name: Search Timeout
-
Options Class:
ClusterTimeoutOptionsParameter:
search_timeout: Optional[timedelta]Default:
NoneThe Search timeout is used on all FTS operations if not overridden by a custom timeout. Note that it is set to such a high timeout compared to key/value since it can affect hundreds or thousands of rows.
- Name: Management Timeout
-
Options Class:
ClusterTimeoutOptionsParameter:
management_timeout: Optional[timedelta]Default:
NoneThe management timeout is used on all cluster management APIs (BucketManager, UserManager, CollectionManager, QueryIndexManager, etc.) if not overridden by a custom timeout. The default is quite high because some operations (such as flushing a bucket, for example) might take a long time.
- Name: DNS SRV Timeout
-
Options Class:
ClusterTimeoutOptionsParameter:
dns_srv_timeout: Optional[timedelta]Default:
NoneDNS SRV timeout.
- Name: Config Idle Redial Timeout
-
Options Class:
ClusterTimeoutOptionsParameter:
config_idle_redial_timeout: Optional[timedelta]Default:
NoneConfig Idle Redial Timeout.
Compression Options
- Name: Enabling Compression
-
Options Class:
ClusterOptionsParameter:
enable_compression: Optional[bool]Default:
TrueIf enabled, the client will compress documents before they are sent to Couchbase Server.
Tracing Options
Tracing settings are configured using an instance of ClusterTracingOptions or passed in as keyword arguments.
ClusterTracingOptions instance:tracing_options=ClusterTimeoutOptions(tracing_threshold_kv=timedelta(milliseconds=5), tracing_threshold_query=timedelta(milliseconds=10))
options=ClusterOptions(PasswordAuthenticator('username', 'password'), tracing_options=tracing_options)
cluster.connect('couchbase://host',options)
- Name: Tracing Enabled
-
Options Class:
ClusterOptionsParameter:
enable_tracing: Optional[bool]Default:
TrueSet this to
Falseif you do not require tracing. - Name: Tracing Enabled
-
Options Class:
ClusterOptionsParameter:
enable_metrics: Optional[bool]Default:
TrueSet this to
Falseif you do not require metrics. - Name: Key-Value Threshold
-
Options Class:
ClusterTracingOptionsParameter:
tracing_threshold_kv: Optional[timedelta]Default:
NoneKey-Value Threshold.
- Name: View Threshold
-
Options Class:
ClusterTracingOptionsParameter:
tracing_threshold_view: Optional[timedelta]Default:
NoneView Threshold.
- Name: Query Threshold
-
Options Class:
ClusterTracingOptionsParameter:
tracing_threshold_query: Optional[timedelta]Default:
NoneQuery Threshold.
- Name: Search Threshold
-
Options Class:
ClusterTracingOptionsParameter:
tracing_threshold_search: Optional[timedelta]Default:
NoneSearch reshold.
- Name: Analytics Threshold
-
Options Class:
ClusterTracingOptionsParameter:
tracing_threshold_analytics: Optional[timedelta]Default:
NoneAnalytics Threshold.
- Name: Eventing Threshold
-
Options Class:
ClusterTracingOptionsParameter:
tracing_threshold_eventing: Optional[timedelta]Default:
NoneEventing Threshold.
- Name: Management Threshold
-
Options Class:
ClusterTracingOptionsParameter:
tracing_threshold_management: Optional[timedelta]Default:
NoneManagement Threshold.
- Name: Tracing Queue Size
-
Options Class:
ClusterTracingOptionsParameter:
tracing_threshold_queue_size: Optional[int]Default:
NoneTracing Queue Size.
- Name: Tracing Queue Flush Interval
-
Options Class:
ClusterTracingOptionsParameter:
tracing_threshold_queue_flush_interval: Optional[timedelta]Default:
NoneTracing Queue Flush Interval.
- Name: Orphaned Queue Size
-
Options Class:
ClusterTracingOptionsParameter:
tracing_orphaned_queue_size: Optional[int]Default:
NoneOrphaned Queue Size.
- Name: Orphaned Queue Flush Interval
-
Options Class:
ClusterTracingOptionsParameter:
tracing_orphaned_queue_flush_interval: Optional[timedelta]Default:
NoneOrphaned Queue Flush Interval.
- Name: Logging Meter Emit Interval
-
Options Class:
ClusterOptionsParameter:
logging_meter_emit_interval: Optional[timedelta]Default:
timedelta(minutes=10)Logging Meter Emit Interval.
Transaction Config
Tracing settings are configured using an instance of TransactionConfig.
TransactionConfig instance:transaction_config=TransactionConfig(durability=ServerDurability(DurabilityLevel.MAJORITY), kv_timeout=timedelta(seconds=10))
options=ClusterOptions(PasswordAuthenticator('username', 'password'), transaction_config=transaction_config)
cluster.connect('couchbase://host',options)
- Name: Transaction Durability Level
-
Options Class:
TransactionConfigParameter:
durability: Optional[ServerDurability]Default:
NoneTransaction Durability Level.
- Name: Transaction Cleanup Window
-
Options Class:
TransactionConfigParameter:
cleanup_window: Optional[timedelta]Default:
NoneTransaction Cleanup Window.
- Name: Transaction Key-Value Timeout
-
Options Class:
TransactionConfigParameter:
kv_timeout: Optional[timedelta]Default:
NoneTransaction Key-Value Timeout.
- Name: Transaction Expiration Time
-
Options Class:
TransactionConfigParameter:
expiration_time: Optional[timedelta]Default:
NoneTransaction Expiration Time.
- Name: Transaction Cleanup Lost Attempts
-
Options Class:
TransactionConfigParameter:
cleanup_lost_attempts: Optional[bool]Default:
NoneTransaction Cleanup Lost Attempts.
- Name: Transaction Cleanup Client Attempts
-
Options Class:
TransactionConfigParameter:
cleanup_client_attempts: Optional[bool]Default:
NoneTransaction Cleanup Client Attempts.
- Name: Transaction Custom Metadata Collection
-
Options Class:
TransactionConfigParameter:
custom_metadata_collection: Optional[Collection]Default:
NoneTransaction Custom Metadata Collection.
- Name: Transaction Query Scan Consistency
-
Options Class:
TransactionConfigParameter:
scan_consistency: Optional[QueryScanConsistency]Default:
NoneTransaction Query Scan Consistency.
General Options
- Name: Unordered Execution
-
Options Class:
ClusterOptionsParameter:
enable_unordered_execution: Optional[bool]Default:
TrueFrom Couchbase 7.0, Out-of-Order execution allows the server to concurrently handle multiple requests on the same connection, potentially improving performance for durable writes and multi-document ACID transactions. This means that tuning the number of connections (KV endpoints) is no longer necessary as a workaround where data not available in the cache is causing timeouts.
This is set to
Trueby default. Note, changing the setting will only affect Server versions 7.0 onwards. - Name: JSON Serializer
-
Options Class:
ClusterOptionsParameter:
serializer: Optional[Serializer]Default:
NoneThe JSON serializer handles the conversion between JSON and Python objects.
- Name: Transcoder
-
Options Class:
ClusterOptionsParameter:
transcoder: Optional[Transcoder]Default:
NoneThe transcoder is responsible for converting KV binary packages to and from Python objects.
The default transcoder assumes you are working with JSON documents. It uses the configured
serializerto convert between JSON and Python objects. When writing documents it sets the appropriate flags to indicate the document content is JSON.The transcoder configured here is just the default; it can be overridden on a per-operation basis.
Commonly Used Options
The defaults above have been carefully considered and in general it is not recommended to make changes without expert guidance or careful testing of the change. Some options may be commonly used together in certain envionments or to achieve certain effects.
Constrained Network Environments
Though wide area network (WAN) connections are not directly supported, some development and non-critical operations activities across a WAN are convenient. Most likely for connecting to Couchbase Capella, or Server running in your own cloud account, whilst developing from a laptop or other machine not located in the same data center. These settings are some you may want to consider adjusting:
-
Connect Timeout to 30s
-
Key-Value Timeout to 5s
-
Config Poll Interval to 10s
-
Circuit Breaker ErrorThresholdPercentage to 75
| As of SDK API 3.4 you can also use a Configuration Profile, which allows you to quickly configure your environment for common use-cases. See the Configuration Profiles section for more details. |
A program using the SDK can also use the waitUntilReady() API call to handle all connection negotiations and related errors at one place.
It may be useful to block in, for example, a basic console testing application for up to 30 seconds before proceeding in the program to perform data operations.
See the API reference for further details.
Configuration Profiles
Configuration Profiles provide predefined client settings that allow you to quickly configure an environment for common use-cases. When using a configuration profile, the current client settings are overridden with the values provided in the profile. Any property that is not specified in the profile is left unchanged.
| The Configuration Profiles feature is currently a Volatile API and may be subject to change. |
WAN Development
Cluster Option: apply_profile("wan_development")
A wan_development configuration profile can be used to modify client settings for development or high-latency environments.
This profile changes the default timeouts — which are themselves all inherited from the underlying core C++ SDK.
| Setting | Default Value | WAN Profile Value |
|---|---|---|
|
2s |
20s |
|
2.5s |
20s |
|
10s |
20s |
|
75s |
120s |
|
75s |
120s |
|
75s |
120s |
|
75s |
120s |
|
75s |
120s |
|
500ms |
20s |
|
2s |
20s |
|
10s |
120s |
|
Bootstrap Timeout
For the SDKs built upon the core C++ SDK, the bootstrap timeouts are picked up from the C++ SDK, and include the following:
|
Do not set key_value_durable_timeout above 65s, which is the maximum possible SyncWrite timeout on the Server side.