【问题标题】:InfluxDB write operation stops working automatically after 24 hour/one dayInfluxDB 写操作在 24 小时/一天后自动停止工作
【发布时间】:2016-10-13 18:11:37
【问题描述】:

我正在使用 Java 写入 InfluxDB,我正在做的是使用无限循环将点写入 DB,如下所示。

while (true) {

    for (int i = 0; i < 100000; i++) {

    list.add("cpu,atag=test" + i + " idle=100,usertime=10,system=1");

    }

            influxDB.write(dbName, "autogen", InfluxDB.ConsistencyLevel.ALL, list);
            list.clear();
            logger.info("WritePoints for " + 1 + " writes of " + 100000 + " Points took:" + watch);
    }

我继续运行该程序较长时间以检查并查看磁盘压缩和磁盘写入速度的情况,但在 24 小时或 1 天后,我收到“超时”异常,如下所示。

我怎样才能在几天内继续运行相同的程序。我可以捕获异常并再次创建连接,但是还有其他方法吗?

Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: retrofit.RetrofitError: timeout
    at retrofit.RetrofitError.networkError(RetrofitError.java:27)
    at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:395)
    at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:240)
    at org.influxdb.impl.$Proxy0.writePoints(Unknown Source)
    at org.influxdb.impl.InfluxDBImpl.write(InfluxDBImpl.java:159)
    at org.influxdb.impl.InfluxDBImpl.write(InfluxDBImpl.java:171)
    at net.company.influx.InfluxDBBatchWriter.doParse(InfluxDBBatchWriter.java:61)
    at net.company.influx.InfluxDBBatchWriter.main(InfluxDBBatchWriter.java:25)
    ... 5 more
Caused by: java.net.SocketTimeoutException: timeout
    at okio.Okio$3.newTimeoutException(Okio.java:207)
    at okio.AsyncTimeout.exit(AsyncTimeout.java:261)
    at okio.AsyncTimeout$2.read(AsyncTimeout.java:215)
    at okio.RealBufferedSource.indexOf(RealBufferedSource.java:306)
    at okio.RealBufferedSource.indexOf(RealBufferedSource.java:300)
    at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:196)
    at com.squareup.okhttp.internal.http.Http1xStream.readResponse(Http1xStream.java:186)
    at com.squareup.okhttp.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:127)
    at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:737)
    at com.squareup.okhttp.internal.http.HttpEngine.access$200(HttpEngine.java:87)
    at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:722)
    at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:576)
    at com.squareup.okhttp.Call.getResponse(Call.java:287)
    at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:243)
    at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:205)
    at com.squareup.okhttp.Call.execute(Call.java:80)
    at retrofit.client.OkClient.execute(OkClient.java:53)
    at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:326)
    ... 11 more
Caused by: java.net.SocketException: Socket closed
    at java.net.SocketInputStream.read(SocketInputStream.java:190)
    at java.net.SocketInputStream.read(SocketInputStream.java:122)
    at okio.Okio$2.read(Okio.java:139)
    at okio.AsyncTimeout$2.read(AsyncTimeout.java:211)
    ... 26 more

【问题讨论】:

  • 你使用的是什么版本的 InfluxDB?
  • 版本为 v1.0.2。
  • 看起来您正在编写 100k 点的批次,这绝对是次优的。尝试将批量大小降低到 5-10k,看看问题是否仍然存在。
  • @MichaelDesa 如何将批量大小降低到 5-10k ?谢谢。

标签: java sockets socket.io influxdb


【解决方案1】:

InfluxDB 在批量非常大的情况下表现不佳。尝试将您的测试修改为类似

int n = 0;
int numSeries = 100000;
int batchSize = 5000;

while (true) {

  for (int i = 0; i < batchSize; i++) {
    n = (n + 1) % numSeries
    list.add("cpu,atag=test" + n + " idle=100,usertime=10,system=1");
  }

  influxDB.write(dbName, "autogen", InfluxDB.ConsistencyLevel.ALL, list);
  list.clear();
  logger.info("WritePoints for " + 1 + " writes of " + 5000 + " Points took:" + watch);
}

【讨论】:

    猜你喜欢
    • 2014-11-15
    • 1970-01-01
    • 2020-09-26
    • 2023-02-11
    • 2021-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-09
    相关资源
    最近更新 更多