TSDBConfig.Builder

Updated at:
Copy as MD

Configures the TSDB Java client. Call methods to set the connection address, tune async write behavior, and configure HTTP options, then call .config() to build a TSDBConfig object.

Class: com.aliyun.hitsdb.client.TSDBConfig.Builder Extends: java.lang.Object Enclosing class: TSDBConfig

public static class TSDBConfig.Builder extends Object

Quick start

TSDBConfig config = new TSDBConfig.Builder("127.0.0.1", 4242)
    .batchPutSize(500)
    .batchPutTimeLimit(300)
    .httpConnectionPool(10)
    .basicAuth("tsdb-user", "tsdb-password")
    .config();

Constructors

SignatureDescription
Builder(String host, int port)Creates a TSDBConfig.Builder using the IP address and port of TSDB.
Builder(TSDBNetAddress... netAddresses)Creates a TSDBConfig.Builder using one or more TSDBNetAddress objects.

Core settings

These are the parameters most integrations need to configure.

MethodDescriptionDefault
asyncPut(boolean asyncPut)Specifies whether to enable asynchronous writes. Keep the default true for better throughput.true
batchPutSize(int batchPutSize)The number of data points submitted per batch. Async only.500
batchPutTimeLimit(int batchPutTimeLimit)The timeout for each asynchronous write, in milliseconds. Async only.300 ms
batchPutBufferSize(int batchPutBufferSize)The maximum number of requests in the buffer queue. Async only.10,000
batchPutConsumerThreadCount(int batchPutConsumerThreadCount)The number of consumer threads processing the buffer queue. Async only.1
basicAuth(String tsdbUser, String basicPwd)Sets the TSDB username and password for authentication. Requires TSDB SDK V0.2.7+ and TSDB V2.5.13+.—
httpConnectionPool(int connectionPool)The size of the HTTP connection pool.—
config()Builds and returns the TSDBConfig object.—

Advanced settings

Use these to tune connection lifecycle, I/O threading, write queues, and read-only mode.

MethodDescriptionDefault
httpConnectTimeout(int httpConnectTimeout)The timeout for each HTTP request, in seconds.90 s
httpConnectionLiveTime(int httpConnectionLiveTime)How long a connection stays alive before the client reestablishes it, in seconds. 0 means persistent connections. See the note below.0 s
httpKeepaliveTime(int httpKeepaliveTime)The duration of each HTTP persistent connection.—
httpCompress(boolean httpCompress)Specifies whether to enable HTTP compression.—
openHttpCompress()Enables HTTP compression.—
ioThreadCount(int ioThreadCount)The number of I/O threads.1
maxTPS(int maxTPS)The maximum transactions per second (TPS) for the client.No limit
putRequestLimit(int limit)The number of write request queues. Defaults to the connection pool size. Async only.Connection pool size
closePutRequestLimit()Removes the limit on write request queues. Disabling this limit risks out-of-memory (OOM) errors. Async only.—
closeBackpressure()——
batchPutRetryCount(int batchPutRetryCount)——
listenBatchPut(AbstractBatchPutCallback<?> cb)Registers a callback for async batch write results. Async only.—
deduplicationEnable()Deduplicates data points within each batch before submission. Async only. See the note below.—
readonly()Enables read-only mode and disables async writes.—
readonly(boolean readonly)Specifies whether to enable read-only mode. Passing true disables async writes.false

Usage notes

httpConnectionLiveTime and load balancing

The default value 0 makes all connections persistent. In production environments, persistent connections can cause load imbalance across TSDB nodes:

  • If a node fails, connections are rerouted to healthy nodes.

  • When the failed node recovers, persistent connections do not return to it.

  • The recovered node receives no traffic until clients initiate new connections.

Set httpConnectionLiveTime to a non-zero value so the client periodically reestablishes connections and distributes load evenly across all nodes.

deduplicationEnable and multi-value data points

deduplicationEnable() considers two data points duplicate when they share the same metric, tag key-value pairs, fields, and timestamp.

For multi-value data points, deduplication is accurate to the field level. If only one field in a MultiFieldPoint object meets the deduplication criteria, only that field's data points are deduplicated — the rest of the MultiFieldPoint is unaffected.

Inherited methods

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait