gpt4 book ai didi

java - InfluxDBIOException : java.net.SocketTimeoutException:超时

转载 作者:行者123 更新时间:2023-12-02 02:05:18 24 4
gpt4 key购买 nike

我正在使用 Influx Db java 包装器,并每 5 秒在 influx db 中添加一次数据,保留策略为 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$2.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$2.run(QueuedThreadPool.java:589)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.SocketTimeoutException: timeout
at okio.Okio$4.newTimeoutException(Okio.java:232)
at okio.AsyncTimeout.exit(AsyncTimeout.java:285)
at okio.AsyncTimeout$2.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$1.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$2.read(Okio.java:140)
at okio.AsyncTimeout$2.read(AsyncTimeout.java:237)

异常原因指向这一行val 结果 = 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")

所有字段值都是长类型,并且具有类似于 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 的默认超时,并且在特定持续时间内没有抛出异常。之前错过了它,因为我传递了另一个数据库实例。

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)

关于java - InfluxDBIOException : java.net.SocketTimeoutException:超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50922473/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com