问题描述
使用InfluxDb v1.8.2和influxdb-java v2.17
我的原始代码是这样的:
OkHttpClient.Builder client = new OkHttpClient.Builder()
.connectTimeout(10,TimeUnit.MINUTES)
.readTimeout(10,TimeUnit.MINUTES)
.writeTimeout(20,TimeUnit.MINUTES)
.retryOnConnectionFailure(true);
InfluxDB connection = InfluxDBFactory.connect(server,client);
connection.enableBatch(100,10,TimeUnit.MILLISECONDS); // Line A
BatchPoints batchPoints = BatchPoints.database(database).build();
// start for-loop
// build point p
batchPoints.point(p)
// end for-loop
connection.write(batchPoints);
connection.disableBatch();
connection.close();
但是this question中的响应告诉我,这不是batchPoints的“惯用”。
显然,我的代码应该更像这样:
InfluxDB connection = InfluxDBFactory.connect(server,TimeUnit.MILLISECONDS); // Line A
BatchPoints.Builder batchPointsBuilder = BatchPoints.database(database);
// start for-loop
// build point p
batchPointsBuilder.point(p)
// end for-loop
connection.write(batchPointsBuilder.build());
connection.disableBatch();
connection.close();
但是,当我这样做时,尝试写出382,479点时出现以下错误:
Exception in thread "main" org.influxdb.InfluxDBIOException: java.net.socketException: Software caused connection abort: socket write error
搜索其他人是否有此错误,将我引向了this article,用户在本质上通过执行类似我最初的操作来解决了该错误,但立即写出了每个要点(我认为这对性能不利):
connection.enableBatch(); // Line A
BatchPoints batchPoints = BatchPoints.database(database).build();
// start for-loop
// build point p
connect.write(p)
// end for-loop
connection.disableBatch();
在更现实的情况下,我可能需要写出更多的观点。当我在更实际的点使用案例中运行应用程序以写出并在将要使用的实际硬件上运行时,出现以下错误:
java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf (Arrays.java:3332)
at java.lang.AbstractStringBuilder.ensureCapacityInternal (AbstractStringBuilder.java:124)
at java.lang.AbstractStringBuilder.append (AbstractStringBuilder.java:448)
at java.lang.StringBuilder.append (StringBuilder.java:136)
at org.influxdb.dto.BatchPoints.lineProtocol (BatchPoints.java:332)
at org.influxdb.impl.InfluxDBImpl.write (InfluxDBImpl.java:455)
at com.ti.aggregator.App.main (App.java:426)
at java.lang.invoke.LambdaForm$DMH/16661067.invokeStaticInit_L_V (LambdaForm$DMH)
at java.lang.invoke.LambdaForm$MH/25601599.invoke_MT (LambdaForm$MH)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:254)
at java.lang.Thread.run (Thread.java:748)
所以我认为我以某种方式没有正确地使用batchPoints编写。我认为我所有的问题都源于此。我想我要么需要更改Line A
,要么我不知道到底是什么。
任何有关如何克服这些问题的建议将不胜感激。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)