InfluxDB Docs

Optimize writes to InfluxDB

Use these tips to optimize performance and system overhead when writing data to InfluxDB.

Telegraf, InfluxDB scrapers, and many InfluxDB client libraries employ these optimizations by default.


Batch writes

Write data in batches to Minimize network overhead when writing data to InfluxDB.

The optimal batch size is 5000 lines of line protocol.

Sort tags by key

Before writing data points to InfluxDB, sort tags by key in lexicographic order. Verify sort results match results from the Go bytes.Compare function.

# Line protocol example with unsorted tags
measurement,tagC=therefore,tagE=am,tagA=i,tagD=i,tagB=think fieldKey=fieldValue 1562020262

# Optimized line protocol example with tags sorted by key
measurement,tagA=i,tagB=think,tagC=therefore,tagD=i,tagE=am fieldKey=fieldValue 1562020262

Use the coarsest time precision possible

InfluxDB lets you write data in nanosecond precision, however if data isn’t collected in nanoseconds, there is no need to write at that precision. Using the coarsest precision possible for timestamps can result in significant compression improvements.

Specify timestamp precision when writing to InfluxDB.

Synchronize hosts with NTP

Use the Network Time Protocol (NTP) to synchronize time between hosts. If a timestamp isn’t included in line protocol, InfluxDB uses its host’s local time (in UTC) to assign timestamps to each point. If a host’s clocks isn’t synchronized with NTP, timestamps may be inaccurate.