SocketTimeout with opened connection in MongoDB

后端 未结 2 983
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-15 08:37

I\'ve a Java application that performs some aggregations on MongoDB, but sometimes it just hangs and throw a SocketTimeout exception. After the Exception the app will run ju

2条回答
  •  忘掉有多难
    2020-12-15 09:30

    If you experience socket errors between clients and servers or between members of a sharded cluster or replica set that do not have other reasonable causes, check the TCP keepalive value (for example, the tcp_keepalive_time value on Linux systems). A common keepalive period is 7200 seconds (2 hours); however, different distributions and macOS may have different settings.

    For MongoDB, you will have better results with shorter keepalive periods, on the order of 120 seconds (two minutes).

    Where you have installed mongodb you have to simply run this command on Linux

    sudo sysctl -w net.ipv4.tcp_keepalive_time=120

    Reference: Does TCP keepalive time affect MongoDB Deployments?

提交回复
热议问题