All Products
Search
Document Center

Time Series Database:Use the TSDBConfig class to configure a TSDB client

Last Updated:Mar 24, 2022

You can use the TSDBConfig class to configure all settings of a Lindorm Time Series Database (TSDB) client. You can call the config() method to build a TSDBConfig object. For more information about how to use TSDBConfig to configure a TSDB client, see the following sample code.

Sample code

TSDBConfig config =TSDBConfig
// Configure the endpoint of the TSDB client. example.tsdb.com specifies the domain or the IP address of the TSDB client. The value 8242 specifies the port that is used by the TSDB client. 
.address("example.tsdb.com",8242)
// tsdbuser and password specify the username and password that are used for user authentication. You can create a user for a TSDB instance on the instance details page in the TSDB console. If user authentication is disabled for the TSDB instance, you do not need to call the basicAuth() method when you create a TSDBConfig object. 
.basicAuth("tsdbuser","password")

// Specify whether the TSDBConfig object is read-only. By default, the value is false. If you set the value to true, asynchronous write operations cannot be performed. 
.readonly(false)

// Configure the size of the connection pool. By default, the value is 64. 
.httpConnectionPool(64)

// Configure the timeout period for an HTTP connection. Unit: seconds. By default, the value is 90. 
.httpConnectTimeout(90)

// Configure the duration during which an HTTP connection is alive. Unit: seconds. By default, the value is 0. The value 0 specifies that this method does not take effect and your connections are persistent connections. We recommend that you configure a proper value. In this case, after a server recovers from a failure, the TSDB client can reconnect to the server. This way, loads are balanced across servers. 
.httpConnectionLiveTime(0)

// Configure the number of I/O threads. By default, the value is 1. 
.ioThreadCount(1)

// Specify whether to allow asynchronous write operations. By default, the value is true. We recommend that you retain the default value. 
.asyncPut(true)

// Configure the size of the buffer. By default, the value is 10000. This parameter takes effect only when asynchronous write operations are allowed. 
.batchPutBufferSize(20000)

// Configure the number of consumer threads in the buffer. By default, the value is 1. This parameter takes effect only when asynchronous write operations are allowed. 
.batchPutConsumerThreadCount(2)

// Configure the number of data points that you want to submit to the TSDB client each time. By default, the value is 500. This parameter takes effect only when asynchronous write operations are allowed. 
.batchPutSize(500)

// Configure the maximum waiting time. Unit: milliseconds. By default, the value is 300. This parameter takes effect only when asynchronous write operations are allowed. 
.batchPutTimeLimit(300)

// Configure the number of write request queues. By default, the value equals the number of connection pools. This parameter takes effect only when asynchronous write operations are allowed. You can configure this parameter based on the read/write ratio. 
.putRequestLimit(100)

// Specify whether to remove the limit on the number of write request queues. We recommend that you impose the limit because out-of-memory (OOM) errors can occur if you remove the limit. This parameter takes effect only when asynchronous write operations are allowed. 
.closePutRequestLimit()

// Use the callback interface for asynchronous PUT requests. This parameter takes effect only when asynchronous write operations are allowed. 
.listenBatchPut(newBatchPutCallback(){
// The following callback function is invoked if a write operation is successful.
@Override
publicvoid response(List<Point> input,Result output){;;}
// The following callback function is invoked if a write operation fails.
@Override
publicvoid failed(String address,List<Point> input,Exception ex){;;}
})

// Configure the maximum number of data points that you want to submit per second. This parameter is used to configure traffic throttling. 
.maxTPS(50000)

.config();// Build a TSDBConfig object.