Best Practices¶
This document aims to provide best practices for using the TSDB API, covering key scenarios such as query scale, query method, resource isolation, and logic optimization. By following the recommended solutions below, you can effectively improve query performance, avoid operational risks, and ensure business stability.
Query Scale¶
To ensure the response efficiency of the query interface, it is recommended to comply with the following scale limits:
Query Type |
Upper Limit of (Number of Devices × Number of Measuring Points) |
Upper Limit of pageSize |
Upper Limit of Total Data Volume |
Time Range Limit (Second-Level Data) |
Time Range Limit (Minute-Level Data) |
---|---|---|---|---|---|
Regular Single Query |
≤ 50 |
≤ 1k |
≤ 1W |
≤ 1 天 |
≤ 7 天 |
Large-model Query |
≤ 10 |
≤ 1k |
≤ 1W |
≤ 1 天 |
≤ 7 天 |
Note
A “large-model query” refers to a scenario where the number of measuring points of a single type (e.g., AI, PI, GENERIC) among the measuring points corresponding to the model exceeds 1,000.
The number of concurrent queries is recommended to be controlled by setting parameters.
QPS needs to be evaluated independently based on actual business scenarios.
Reverse Query¶
The performance of TSDB for reverse queries is greatly affected by the time range—the larger the range, the lower the performance. It is recommended to control the time range of reverse queries within 1 day and use a sliding window mechanism to implement rolling queries.
SA Isolation Strategy¶
For new business scenarios, if any of the following situations exist, it is recommended to create an independent SA for separate control and monitoring:
The business query data volume is large.
The expected business query performance is unclear.
Query Logic Optimization¶
Periodic Pull Scenario: For periodic data pulling, it is recommended to avoid pulling redundant data to reduce performance loss.
Optimization Example: If a service runs on a 5-minute cycle and needs to query data from the past 30-minute window for prediction, it should only pull the “new data from the past 5 minutes” each time, and then splice it with the “historical data from the previous 25 minutes” stored in the local cache.
Multi-Device Query Scenario: For batch queries of multiple devices, if a device has no data that meets expectations returned within the target time range, it is recommended to filter out this device first and then adjust the query time range for the remaining devices to avoid unnecessary query overhead.