InfluxDB写入操作在24小时/一天后自动停止工作

时间:2016-10-13 18:11:38

标签: java sockets socket.io influxdb

我使用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

1 个答案:

答案 0 :(得分: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);
}