InfluxDBIOException: java.net.SocketTimeoutException: 超时
InfluxDBIOException: java.net.SocketTimeoutException: timeout
我正在使用 Influx Db java 包装器并每 5 秒在 influx 数据库中添加数据,保留政策为 30 天。
当我尝试通过发送多个请求来查询数据时,出现超时异常。
一旦我清除了数据库数据,就会正确收到响应。
org.influxdb.InfluxDBIOException: java.net.SocketTimeoutException: timeout
at org.influxdb.impl.InfluxDBImpl.execute(InfluxDBImpl.java:587)
at org.influxdb.impl.InfluxDBImpl.query(InfluxDBImpl.java:425)
**at services.SampleService.getTotalCount(SampleService.kt:45)**
at sun.reflect.GeneratedMethodAccessor83.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at ninja.params.ControllerMethodInvoker.invoke(ControllerMethodInvoker.java:76)
at ninja.FilterChainEnd.next(FilterChainEnd.java:45)
at filters.PermissionFilter.filter(PermissionFilter.kt:30)
at ninja.FilterChainImpl.next(FilterChainImpl.java:36)
at filters.JwtFilter.filter(JwtFilter.kt:40)
at ninja.FilterChainImpl.next(FilterChainImpl.java:36)
at filters.CorsFilter.filter(CorsFilter.kt:10)
at ninja.FilterChainImpl.next(FilterChainImpl.java:36)
at ninja.NinjaDefault.onRouteRequest(NinjaDefault.java:102)
at ninja.servlet.NinjaServletDispatcher.service(NinjaServletDispatcher.java:86)
at com.google.inject.servlet.ServletDefinition.doServiceImpl(ServletDefinition.java:286)
at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:276)
at com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:181)
at com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:91)
at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:85)
at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:120)
at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:135)
at ninja.servlet.NinjaServletFilter.doFilter(NinjaServletFilter.java:106)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1759)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:582)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1180)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:512)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1112)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)
at org.eclipse.jetty.server.Server.handle(Server.java:534)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:320)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:283)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:110)
at org.eclipse.jetty.io.SelectChannelEndPoint.run(SelectChannelEndPoint.java:93)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.executeProduceConsume(ExecuteProduceConsume.java:303)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:148)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:136)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:671)
at org.eclipse.jetty.util.thread.QueuedThreadPool.run(QueuedThreadPool.java:589)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.SocketTimeoutException: timeout
at okio.Okio.newTimeoutException(Okio.java:232)
at okio.AsyncTimeout.exit(AsyncTimeout.java:285)
at okio.AsyncTimeout.read(AsyncTimeout.java:241)
at okio.RealBufferedSource.request(RealBufferedSource.java:68)
at okio.RealBufferedSource.require(RealBufferedSource.java:61)
at okio.RealBufferedSource.readHexadecimalUnsignedLong(RealBufferedSource.java:304)
at okhttp3.internal.http.Http1xStream$ChunkedSource.readChunkSize(Http1xStream.java:441)
at okhttp3.internal.http.Http1xStream$ChunkedSource.read(Http1xStream.java:422)
at okio.RealBufferedSource.read(RealBufferedSource.java:47)
at okio.RealBufferedSource.request(RealBufferedSource.java:68)
at okio.RealBufferedSource.require(RealBufferedSource.java:61)
at okio.GzipSource.consumeHeader(GzipSource.java:114)
at okio.GzipSource.read(GzipSource.java:73)
at okio.RealBufferedSource.read(RealBufferedSource.java:47)
at okio.ForwardingSource.read(ForwardingSource.java:35)
at retrofit2.OkHttpCall$ExceptionCatchingRequestBody.read(OkHttpCall.java:279)
at okio.RealBufferedSource.request(RealBufferedSource.java:68)
at okio.RealBufferedSource.rangeEquals(RealBufferedSource.java:418)
at okio.RealBufferedSource.rangeEquals(RealBufferedSource.java:402)
at retrofit2.converter.moshi.MoshiResponseBodyConverter.convert(MoshiResponseBodyConverter.java:39)
at retrofit2.converter.moshi.MoshiResponseBodyConverter.convert(MoshiResponseBodyConverter.java:25)
at retrofit2.ServiceMethod.toResponse(ServiceMethod.java:117)
at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:211)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:174)
at org.influxdb.impl.InfluxDBImpl.execute(InfluxDBImpl.java:579)
... 46 more
Caused by: java.net.SocketException: Socket closed
at java.net.SocketInputStream.read(SocketInputStream.java:204)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at okio.Okio.read(Okio.java:140)
at okio.AsyncTimeout.read(AsyncTimeout.java:237)
异常原因指向这一行
val results = influxDB.query(q)
val q = Query(
"select sum(firstCount) as totalFirstCount, sum(secondCount) as totalSecondCount" +
" ,sum(thirdCount) as totalThirdCount, sum(fourthCount) as totalFourthCount " +
"from counters where time > now() - "1h" group by field1 , field2",
"dbname")
所有字段值都是 Long 类型,值类似于 2721976000。
以下是上述查询的解释语句的响应。
EXPRESSION: sum(firstCount::integer)
NUMBER OF SHARDS: 123
NUMBER OF SERIES: 26568
CACHED VALUES: 105408
NUMBER OF FILES: 16200
NUMBER OF BLOCKS: 16200
SIZE OF BLOCKS: 76693173
EXPRESSION: sum(secondCount::integer)
NUMBER OF SHARDS: 123
NUMBER OF SERIES: 26568
CACHED VALUES: 105408
NUMBER OF FILES: 16200
NUMBER OF BLOCKS: 16200
SIZE OF BLOCKS: 86133364
EXPRESSION: sum(thirdCount::integer)
NUMBER OF SHARDS: 123
NUMBER OF SERIES: 26568
CACHED VALUES: 105408
NUMBER OF FILES: 16200
NUMBER OF BLOCKS: 16200
SIZE OF BLOCKS: 61967770
EXPRESSION: sum(fourthCount::integer)
NUMBER OF SHARDS: 123
NUMBER OF SERIES: 26568
CACHED VALUES: 105408
NUMBER OF FILES: 16200
NUMBER OF BLOCKS: 16200
SIZE OF BLOCKS: 61967754
我找不到解决异常的方法,在 java 控制台日志中正确接收到响应。任何有关查看查询优化或异常原因的指示都会有所帮助。
我更改了 OKHttpClient 的默认超时,并且在特定持续时间内没有抛出异常。之前错过了,因为我传递了不同的 DB 实例。
val client = OkHttpClient.Builder()
.connectTimeout(1, TimeUnit.MINUTES)
.readTimeout(1, TimeUnit.MINUTES)
.writeTimeout(1, TimeUnit.MINUTES)
.retryOnConnectionFailure(true)
val influxConnection = InfluxDBFactory.connect("http://localhost:8086", client)
我将@Nirmal 的回答翻译成 java
OkHttpClient.Builder client = new OkHttpClient.Builder()
.connectTimeout(1, TimeUnit.MINUTES)
.readTimeout(1, TimeUnit.MINUTES)
.writeTimeout(1, TimeUnit.MINUTES)
.retryOnConnectionFailure(true);
InfluxDB influxdb = InfluxDBFactory.connect(influxUrl, client);
新客户端的更简单方法(我测试 6.0):
您可以添加到 url ?readTimeout=1m&connectTimeout=1m&writeTimeout=30s
默认为 10 秒。请参阅 com.influxdb.client.InfluxDBClientFactory#create(java.lang.String, char[], java.lang.String)
的 JavaDoc
我正在使用 Influx Db java 包装器并每 5 秒在 influx 数据库中添加数据,保留政策为 30 天。
当我尝试通过发送多个请求来查询数据时,出现超时异常。 一旦我清除了数据库数据,就会正确收到响应。
org.influxdb.InfluxDBIOException: java.net.SocketTimeoutException: timeout
at org.influxdb.impl.InfluxDBImpl.execute(InfluxDBImpl.java:587)
at org.influxdb.impl.InfluxDBImpl.query(InfluxDBImpl.java:425)
**at services.SampleService.getTotalCount(SampleService.kt:45)**
at sun.reflect.GeneratedMethodAccessor83.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at ninja.params.ControllerMethodInvoker.invoke(ControllerMethodInvoker.java:76)
at ninja.FilterChainEnd.next(FilterChainEnd.java:45)
at filters.PermissionFilter.filter(PermissionFilter.kt:30)
at ninja.FilterChainImpl.next(FilterChainImpl.java:36)
at filters.JwtFilter.filter(JwtFilter.kt:40)
at ninja.FilterChainImpl.next(FilterChainImpl.java:36)
at filters.CorsFilter.filter(CorsFilter.kt:10)
at ninja.FilterChainImpl.next(FilterChainImpl.java:36)
at ninja.NinjaDefault.onRouteRequest(NinjaDefault.java:102)
at ninja.servlet.NinjaServletDispatcher.service(NinjaServletDispatcher.java:86)
at com.google.inject.servlet.ServletDefinition.doServiceImpl(ServletDefinition.java:286)
at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:276)
at com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:181)
at com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:91)
at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:85)
at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:120)
at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:135)
at ninja.servlet.NinjaServletFilter.doFilter(NinjaServletFilter.java:106)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1759)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:582)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1180)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:512)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1112)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)
at org.eclipse.jetty.server.Server.handle(Server.java:534)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:320)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:283)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:110)
at org.eclipse.jetty.io.SelectChannelEndPoint.run(SelectChannelEndPoint.java:93)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.executeProduceConsume(ExecuteProduceConsume.java:303)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:148)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:136)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:671)
at org.eclipse.jetty.util.thread.QueuedThreadPool.run(QueuedThreadPool.java:589)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.SocketTimeoutException: timeout
at okio.Okio.newTimeoutException(Okio.java:232)
at okio.AsyncTimeout.exit(AsyncTimeout.java:285)
at okio.AsyncTimeout.read(AsyncTimeout.java:241)
at okio.RealBufferedSource.request(RealBufferedSource.java:68)
at okio.RealBufferedSource.require(RealBufferedSource.java:61)
at okio.RealBufferedSource.readHexadecimalUnsignedLong(RealBufferedSource.java:304)
at okhttp3.internal.http.Http1xStream$ChunkedSource.readChunkSize(Http1xStream.java:441)
at okhttp3.internal.http.Http1xStream$ChunkedSource.read(Http1xStream.java:422)
at okio.RealBufferedSource.read(RealBufferedSource.java:47)
at okio.RealBufferedSource.request(RealBufferedSource.java:68)
at okio.RealBufferedSource.require(RealBufferedSource.java:61)
at okio.GzipSource.consumeHeader(GzipSource.java:114)
at okio.GzipSource.read(GzipSource.java:73)
at okio.RealBufferedSource.read(RealBufferedSource.java:47)
at okio.ForwardingSource.read(ForwardingSource.java:35)
at retrofit2.OkHttpCall$ExceptionCatchingRequestBody.read(OkHttpCall.java:279)
at okio.RealBufferedSource.request(RealBufferedSource.java:68)
at okio.RealBufferedSource.rangeEquals(RealBufferedSource.java:418)
at okio.RealBufferedSource.rangeEquals(RealBufferedSource.java:402)
at retrofit2.converter.moshi.MoshiResponseBodyConverter.convert(MoshiResponseBodyConverter.java:39)
at retrofit2.converter.moshi.MoshiResponseBodyConverter.convert(MoshiResponseBodyConverter.java:25)
at retrofit2.ServiceMethod.toResponse(ServiceMethod.java:117)
at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:211)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:174)
at org.influxdb.impl.InfluxDBImpl.execute(InfluxDBImpl.java:579)
... 46 more
Caused by: java.net.SocketException: Socket closed
at java.net.SocketInputStream.read(SocketInputStream.java:204)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at okio.Okio.read(Okio.java:140)
at okio.AsyncTimeout.read(AsyncTimeout.java:237)
异常原因指向这一行
val results = influxDB.query(q)
val q = Query(
"select sum(firstCount) as totalFirstCount, sum(secondCount) as totalSecondCount" +
" ,sum(thirdCount) as totalThirdCount, sum(fourthCount) as totalFourthCount " +
"from counters where time > now() - "1h" group by field1 , field2",
"dbname")
所有字段值都是 Long 类型,值类似于 2721976000。
以下是上述查询的解释语句的响应。
EXPRESSION: sum(firstCount::integer)
NUMBER OF SHARDS: 123
NUMBER OF SERIES: 26568
CACHED VALUES: 105408
NUMBER OF FILES: 16200
NUMBER OF BLOCKS: 16200
SIZE OF BLOCKS: 76693173
EXPRESSION: sum(secondCount::integer)
NUMBER OF SHARDS: 123
NUMBER OF SERIES: 26568
CACHED VALUES: 105408
NUMBER OF FILES: 16200
NUMBER OF BLOCKS: 16200
SIZE OF BLOCKS: 86133364
EXPRESSION: sum(thirdCount::integer)
NUMBER OF SHARDS: 123
NUMBER OF SERIES: 26568
CACHED VALUES: 105408
NUMBER OF FILES: 16200
NUMBER OF BLOCKS: 16200
SIZE OF BLOCKS: 61967770
EXPRESSION: sum(fourthCount::integer)
NUMBER OF SHARDS: 123
NUMBER OF SERIES: 26568
CACHED VALUES: 105408
NUMBER OF FILES: 16200
NUMBER OF BLOCKS: 16200
SIZE OF BLOCKS: 61967754
我找不到解决异常的方法,在 java 控制台日志中正确接收到响应。任何有关查看查询优化或异常原因的指示都会有所帮助。
我更改了 OKHttpClient 的默认超时,并且在特定持续时间内没有抛出异常。之前错过了,因为我传递了不同的 DB 实例。
val client = OkHttpClient.Builder()
.connectTimeout(1, TimeUnit.MINUTES)
.readTimeout(1, TimeUnit.MINUTES)
.writeTimeout(1, TimeUnit.MINUTES)
.retryOnConnectionFailure(true)
val influxConnection = InfluxDBFactory.connect("http://localhost:8086", client)
我将@Nirmal 的回答翻译成 java
OkHttpClient.Builder client = new OkHttpClient.Builder()
.connectTimeout(1, TimeUnit.MINUTES)
.readTimeout(1, TimeUnit.MINUTES)
.writeTimeout(1, TimeUnit.MINUTES)
.retryOnConnectionFailure(true);
InfluxDB influxdb = InfluxDBFactory.connect(influxUrl, client);
新客户端的更简单方法(我测试 6.0):
您可以添加到 url ?readTimeout=1m&connectTimeout=1m&writeTimeout=30s
默认为 10 秒。请参阅 com.influxdb.client.InfluxDBClientFactory#create(java.lang.String, char[], java.lang.String)