【发布时间】:2023-03-15 02:01:01
【问题描述】:
我正在使用批处理写入 InfluxDB,下面是我的代码。
String dbName = "test";
influxDB.query(new Query("CREATE DATABASE " + dbName, dbName));
Stopwatch watch = Stopwatch.createStarted();
influxDB.enableBatch(2000, 100, TimeUnit.MILLISECONDS);
for (int j = 0; j < 100000; j++) {
Point point = Point.measurement("cpu")
.addField("idle", (double) j)
.addField("system", 3.0 * j).build();
influxDB.write(dbName, "autogen", point);
}
influxDB.disableBatch();
System.out.println("Write for " + 100000 + " Points took:" + watch);
}
我在这里写了 100000 点,这需要非常合理的时间来写,但是只有很少的记录被写入数据库,而不是预期的 100000 条记录。
select count(idle) from cpu 只给我“89”,我希望它是“100000”
虽然select * from cpu 给了我以下信息:
cpu
time idle system
2016-10-06T23:57:41.184Z 8 24
2016-10-06T23:57:41.185Z 196 588
2016-10-06T23:57:41.186Z 436 1308
2016-10-06T23:57:41.187Z 660 1980
2016-10-06T23:57:41.188Z 916 2748
2016-10-06T23:57:41.189Z 1278 3834
2016-10-06T23:57:41.19Z 1405 4215
2016-10-06T23:57:41.191Z 1409 4227
2016-10-06T23:57:41.192Z 1802 5406
2016-10-06T23:57:41.193Z 1999 5997
2016-10-06T23:57:41.456Z 3757 11271
2016-10-06T23:57:41.457Z 3999 11997
2016-10-06T23:57:41.858Z 4826 14478 and so on.....
这里我的问题是为什么缺少 idle 的值,例如,在 8 之后应该是 9、10、11 等等,但是这些值没有持久化,直接出现在 196 之间,然后在 436 之间丢失。知道在这种情况下如何保持循环变量“j”的所有值吗?
【问题讨论】: