Client Settings

    • Developer Preview
      +
      The ClusterOptions struct enables you to configure Rust SDK options for bootstrapping, reliability, and performance.

      Almost all configuration for the SDK can be specified through the ClusterOptions which are passed to the Cluster::connect call in the SDK. In addition to this, some of these options can also be specified through the connection string.

      Most of the Cluster Options are grouped into categories. For example, TLS options are configured using an instance of the TlsOptions struct, accessed via the ClusterOptions instance’s tls_options() getter.

      Configuring TLS options
      ClusterOptions::new(Authenticator::PasswordAuthenticator(
          PasswordAuthenticator::new("username".to_string(), "password".to_string()),
      ))
      .tls_options(TlsOptions::new());

      General Options

      These options specify the general configuration options for the client.

      Name: Authenticator

      Options Method: ClusterOptions constructor parameter

      Set this to the authenticator you wish to use to authenticate with the server. Possible options which are included in the SDK include the PasswordAuthenticator and CertificateAuthenticator.

      Compression Options

      The client can compress documents before sending them to Couchbase Server.

      Name: Enabling Compression

      Options Method: compression_mode(CompressionMode)

      Connection String Parameter: N/A

      Default: CompressionMode::Enabled { min_size: 32, min_ratio: 0.83 }

      If set to CompressionMode::Disabled, the client will never compress documents, regardless of their size or compressibility. If set to CompressionMode::Enabled, the client may compress documents before they are sent to Couchbase Server.

      Name: Document Minimum Size

      Options Method: compression_mode(CompressionMode::Enabled { min_size, .. })

      Default: 32

      Size in bytes. Documents smaller than this size are never compressed.

      Name: Document Minimum Compressibility

      Options Method: compression_mode(CompressionMode::Enabled { .., min_ratio })

      Default: 0.83

      A floating point value between 0 and 1. Specifies how "compressible" a document must be in order for the compressed form to be sent to the server.

      Increasing the value allows compression to be used with less-compressible documents.

      If the compressed document size divided by the uncompressed document size is greater than this value, then the uncompressed version of the document will be sent to Couchbase Server instead of the compressed version.

      For example, with a min_ratio of 0.83, compression will only be used if the size of the compressed document is less than 83% of the uncompressed document size.

      TLS Options

      By default, the client will connect to (self-managed) Couchbase Server using an unencrypted connection. If you are using the Enterprise Edition of self-managed Couchbase Server, it’s possible to secure the connection using TLS.

      Unless you use the couchbases:// connection string scheme, none of the other security settings in this section have any effect. If you are using Capella, secure connection is the only option.
      Name: TLS Certificates

      Options Method: TlsOptions::add_ca_certificate / TlsOptions::add_ca_certificates

      Connection String Parameter: N/A

      Default: N/A

      Specifies certificates to trust as Certificate Authorities when establishing secure connections. One or more CA certificates can be added depending on the TLS backend in use (rustls or native-tls) specified using Cargo features.

      With the rustls backend, certificates are provided as CertificateDer<'static>. With the native-tls backend, certificates are provided as tokio_native_tls::native_tls::Certificate.

      Name: Dangerously Accept Invalid Certificates

      Options Method: TlsOptions::danger_accept_invalid_certs(bool)

      Connection String Parameter: N/A

      Default: false

      If set to true, the client will accept self-signed or otherwise invalid server certificates. This option should only be used for testing and development, never in production.

      Name: Dangerously Accept Invalid Hostnames

      Options Method: TlsOptions::danger_accept_invalid_hostnames(bool) (only available with the native-tls backend)

      Connection String Parameter: N/A

      Default: false

      If set to true, the client will not validate that the server certificate’s hostname matches the endpoint being connected to. This option should only be used for testing and development, never in production.

      TCP Options

      These options control TCP-level behavior for the client.

      Name: TCP Keep-Alive Time

      Options Method: ClusterOptions::tcp_keep_alive_time(Duration)

      Connection String Parameter: tcp_keep_alive_time=<duration>

      Default: 60s

      Specifies the duration for TCP keep-alive messages. If set, the client will send keep-alive messages at the given interval to maintain the connection to the server.

      Poller Options

      These options control the behavior of the SDK’s internal event pollers.

      Name: Configuration Poll Interval

      Options Method: PollerOptions::config_poll_interval(Duration)

      Connection String Parameter: config_poll_interval=<duration>

      Default: 2.5s

      The interval at which the client fetches cluster topology information in order to proactively detect changes.

      HTTP Options

      These options control the behavior of HTTP requests made by the SDK.

      Name: Max Idle Connections per Host

      Options Method: HttpOptions::max_idle_connections_per_host(usize)

      Connection String Parameter: max_idle_http_connections_per_host=<value>

      Default: None

      The upper bound on the number of HTTP connections per host.

      Name: Idle Connection Timeout

      Options Method: HttpOptions::idle_connection_timeout(Duration)

      Connection String Parameter: idle_http_connection_timeout=<duration>

      Default: None

      The length of time an HTTP connection may remain idle before it is closed and removed from the pool. Durations longer than 1 second are not recommended, since Couchbase Server aggressively drops idle connections.

      Key-Value (KV) Options

      These options control the behavior of key-value operations.

      Name: Enable Mutation Tokens

      Options Method: KvOptions::enable_mutation_tokens(bool)

      Connection String Parameter: enable_mutation_tokens=<true|false>

      Default: true

      Mutation tokens allow enhanced durability requirements as well as advanced SQL++ querying capabilities. Set this to false if you do not require these features and wish to avoid the associated overhead.

      Name: Enable Server Durations

      Options Method: KvOptions::enable_server_durations(bool)

      Connection String Parameter: enable_server_durations=<true|false>

      Default: true

      If true, the client will capture the server-side duration of KV operations in the response.

      Name: Number of Connections

      Options Method: KvOptions::num_connections(usize)

      Connection String Parameter: num_kv_connections=<value>

      Default: 1

      The number of actual endpoints (sockets) to open per node in the cluster against the Key/Value service. By default, for every node in the cluster one socket is opened where all traffic is pushed through. That way the SDK implicitly benefits from network batching characteristics when the workload increases. If you suspect based on profiling and benchmarking that the socket is saturated you can think about slightly increasing it to have more "parallel pipelines". This might be especially helpful if you need to push large documents through it. The recommendation is keeping it at 1 unless there is other evidence.

      Name: Connect Timeout

      Options Method: KvOptions::connect_timeout(Duration)

      Connection String Parameter: kv_connect_timeout=<duration>

      Default: 10s

      The 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: Connect Throttle Timeout

      Options Method: KvOptions::connect_throttle_timeout(Duration)

      Connection String Parameter: N/A

      Default: 5s

      The throttle timeout defines the minimum interval between consecutive connection attempts after a connection error.

      Orphan Reporter Options

      These options control reporting of orphaned operations.

      Name: Enabled

      Options Method: OrphanReporterOptions::enabled(bool)

      Connection String Parameter: N/A

      Default: true

      Enable or disable orphan reporting.

      Name: Reporter Interval

      Options Method: OrphanReporterOptions::reporter_interval(Duration)

      Connection String Parameter: N/A

      Default: 10s

      Specifies how often orphaned operations are reported.

      Name: Sample Size

      Options Method: OrphanReporterOptions::sample_size(usize)

      Connection String Parameter: N/A

      Default: 10

      Specifies the number of orphaned operations to report in each report interval.