【问题标题】:Efficiently loading large time series data into InfluxDB高效地将大型时间序列数据加载到 InfluxDB
【发布时间】:2021-09-07 17:37:22
【问题描述】:

我正在尝试将 1000 亿(数千列,数百万行)多维时间序列数据点从 CSV 文件加载到 InfluxDB。

我目前正在通过线路协议进行如下操作(我的代码库是 Python):

f = open(args.file, "r")
l = []
bucket_size = 100
if rows > 10000:
    bucket_size = 10
for x in tqdm(range(rows)):
    s = f.readline()[:-1].split(" ")
    v = {}
    for y in range(columns):
        v["dim" + str(y)] = float(s[y + 1])
    time = (get_datetime(s[0])[0] - datetime(1970, 1, 1)).total_seconds() * 1000000000
    time = int(time)
    body = {"measurement": "puncte", "time": time, "fields": v }
    l.append(body)
    if len(l) == bucket_size:
        while True:
            try:
                client.write_points(l)
            except influxdb.exceptions.InfluxDBServerError:
                continue
            break
        l = []
client.write_points(l)

final_time = datetime.now()
final_size = get_size()

seconds = (final_time - initial_time).total_seconds()

如上面的代码所示,我的代码正在读取数据集 CSV 文件并准备 10000 个数据点的批次,然后使用 client.write_points(l) 发送数据点。

但是,这种方法效率不高。事实上,我正在尝试加载 1000 亿个数据点,这比预期花费的时间更长,仅加载 300 万行,每行 100 列已经运行了 29 小时,还有 991 小时完成!!!

我确信有更好的方法将数据集加载到 InfluxDB。对于更快的数据加载有什么建议吗?

【问题讨论】:

    标签: influxdb influxdb-python influxdb-2 flux-influxdb influx-line-protocol


    【解决方案1】:

    尝试在多个并发线程中加载数据。这应该可以加快多 CPU 机器的速度。

    另一种选择是将 CSV 文件直接提供给时间序列数据库,而无需进行额外的转换。见this example

    【讨论】:

      猜你喜欢
      • 2018-08-05
      • 2016-03-29
      • 2020-03-11
      • 2013-11-07
      • 2020-08-11
      • 2017-02-05
      • 2015-07-01
      • 1970-01-01
      • 2021-06-05
      相关资源
      最近更新 更多