我正在使用java来写入influxDB。
假设influxDB实例与数据库连接。下面是我的代码。
influxDB.enableBatch(500, 100, TimeUnit.MICROSECONDS);
while (true) {
try {
Point point = Point.measurement("cpu").addField("idle", (Math.random()*1000)).build();
influxDB.write(dbName, "default", point);
} catch (RuntimeException e) {
System.out.println(e.getMessage());
}
}通过使用这个逻辑,我每秒只能写入300条记录,这比我们预期的要少得多。每秒2000次写入就足够了。想知道我应该优化什么参数吗?
发布于 2016-10-02 01:13:31
influxDB.enableBatch(500, 100, TimeUnit.MICROSECONDS);意味着你每500个点或者至少每100毫秒刷新一次。既然你说你每秒写300个点,我假设你不会在一秒内生成更多的点来写influxdb。
我认为你“减慢”创建你的点的部分是Math.random()。因此,尝试使用一个固定值,并检查您是否在一秒内获得更多的分数。
您正在尝试做的性能测试的一个很好的来源是在influxdb-java github上。下面是取自PerformanceTests.java的测试,它与您正在进行的测试几乎相同:
@Test(threadPoolSize = 10, enabled = false)
public void writeSinglePointPerformance() throws InterruptedException {
String dbName = "write_" + System.currentTimeMillis();
this.influxDB.createDatabase(dbName);
this.influxDB.enableBatch(2000, 100, TimeUnit.MILLISECONDS);
String rp = TestUtils.defaultRetentionPolicy(this.influxDB.version());
Stopwatch watch = Stopwatch.createStarted();
for (int j = 0; j < SINGLE_POINT_COUNT; j++) {
Point point = Point.measurement("cpu")
.addField("idle", (double) j)
.addField("user", 2.0 * j)
.addField("system", 3.0 * j).build();
this.influxDB.write(dbName, rp, point);
}
this.influxDB.disableBatch();
System.out.println("Single Point Write for " + SINGLE_POINT_COUNT + " writes of Points took:" + watch);
this.influxDB.deleteDatabase(dbName);
}https://stackoverflow.com/questions/39735566
复制相似问题