ngbatis icon indicating copy to clipboard operation
ngbatis copied to clipboard

query failure, got `java.net.SocketException: Connection reset`

Open zhangxs0110 opened this issue 1 year ago • 9 comments

1684891842410 经常出现这个问题,这是什么原因啊

zhangxs0110 avatar May 24 '23 01:05 zhangxs0110

关于连接数的配置是怎么样的,可以适当加点最小连接数试试

CorvusYe avatar May 24 '23 01:05 CorvusYe

image 越是接口频繁调用时,越容易出现这个问题

zhangxs0110 avatar May 24 '23 01:05 zhangxs0110

最小连接是 0 的时候,会频繁获取连接跟释放连接,整体会不稳定一些, 可以修改下这个参数 min-conns-size,我自己是用 2,可以根据项目情况做适当调整,建议大于1

CorvusYe avatar May 24 '23 02:05 CorvusYe

好的,我试试

zhangxs0110 avatar May 24 '23 02:05 zhangxs0110

还是会出现这个错误。 image

image image 我感觉和这个LocalSession有关系

zhangxs0110 avatar May 26 '23 02:05 zhangxs0110

LocalSession的引入最早也是为了解决reset的问题。 默认的定时检查时间还是有点长,可以把这两个时间调小,试试每20分钟检查一次

nebula.ngbatis.session-life-length nebula.ngbatis.check-fixed-rate

CorvusYe avatar May 26 '23 04:05 CorvusYe

image 越是接口频繁调用时,越容易出现这个问题

下午我用JMeter试一下,如果是这个情况,那就不是上一条所说的太久没用连接失活的问题

CorvusYe avatar May 26 '23 04:05 CorvusYe

好的,感谢~

zhangxs0110 avatar May 26 '23 09:05 zhangxs0110

默认配置

nebula:
  ngbatis:
    # space name needs to be informed through annotations(@Space) or xml(space="test")
    # default false(false: Session pool map will not be initialized)
    use-session-pool: false
  hosts: 127.0.0.1:19669
  username: root
  password: nebula
  space: test
  pool-config:
    min-conns-size: 0
    max-conns-size: 10
    timeout: 6000
    idle-time: 0
    interval-idle: -1
    wait-time: 6000
    min-cluster-health-rate: 1.0
    enable-ssl: false

到这里,已经初步可以判断错误的产生不像是高频的访问

  • 第二次测试(18:13:19)
    • image
    • 报错信息: image

保持连接过久,从而导致的释放失败,或许才是原因所在。

  • 第三次测试(18:25:08)
    • image

经过小于上次中断时间的等待之后进行的测试三,基本确定在10分钟以内,连接还是健康的,但具体时间不能确定。

修改配置,并重启服务器

nebula:
  ngbatis:
    session-life-length: 300000
    check-fixed-rate: 300000
    # space name needs to be informed through annotations(@Space) or xml(space="test")
    # default false(false: Session pool map will not be initialized)
    use-session-pool: false
  hosts: 127.0.0.1:19669
  username: root
  password: nebula
  space: test
  pool-config:
    min-conns-size: 0
    max-conns-size: 10
    timeout: 6000
    idle-time: 0
    interval-idle: -1
    wait-time: 6000
    min-cluster-health-rate: 1.0
    enable-ssl: false
  • 测试1 (19:29:31)
    • image
  • 测试2 (20:22:45)
    • image

image

这边虽然重连设置的是 5分钟,但因为检查频率是5分钟,开始检查时,距连接创建的时间很接近5分钟,但还没到,所以整体的连接释放时间将近 10 分钟。

可以看出在不启用 sessionPool 的情况下,通过这个配置,并没有发生请求失败的问题,并且可以看到测试2的过程中,又启用了一次重连检查。从而有效维持了连接的健康状态。规避了 失活后不能释放长久占用连接池 的问题。

CorvusYe avatar May 26 '23 12:05 CorvusYe