Mongo Update Operation is taking long time

108 Views Asked by At

I am using mongo as my database. I have a collection to store orders, each order document contains an item array, which contains more than 130 item documents, something like below:

{
  "id": "some uuid",
  "items": [
    {
      "field-1": "",
      "field-2": "",
      . . . . . . . .
      . . . . . . . .
      . . . . . . . .
      Up to 30 fields/attributes
    },
    {
      "field-1": "",
      "field-2": "",
      . . . . . . . .
      . . . . . . . .
      . . . . . . . .
      Up to 30 fields/attributes
    },
    . . . . . . . .
    . . . . . . . .
    . . . . . . . .
    Up to 150 items
    
  ]
}

Each item itself can contain 30 to 40 fields/attributes. When I update my existing order document with more than 130 items, it is timing out(Socket read timeout). And by the way, this is happening when there is good amount of load on the server, like issuing 50 update requests(with more than 130 items per order) to mongo. I am using a springboot application, which uses Java mongo driver to connect to the DB.

I saw the mongo TCP keepalive conn value, which is correct(300 seconds). I don't see any connection timeout errors but the below exception most of the times.

The current value of socketTimeout is 13 Seconds

if (socketTimeout != null) {
    socketBuilder.readTimeout(13000, TimeUnit.MILLISECONDS);
}

Is this setting really causing the below exception, does this need to be changed, if so what would be an optimized number? We are using BulkOperations to update operations.

Any help would be greatly appreciated.

GlobalExceptionHandler - Global error:
org.springframework.dao.DataAccessResourceFailureException: Timeout while receiving message; nested exception is com.mongodb.MongoSocketReadTimeoutException: Timeout while receiving message
    at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:85) ~[spring-data-mongodb-3.3.4.jar!/:3.3.4]
    at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2929) ~[spring-data-mongodb-3.3.4.jar!/:3.3.4]
    at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:562) ~[spring-data-mongodb-3.3.4.jar!/:3.3.4]
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . 

Caused by: java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method) ~[?:1.8.0_171]
    at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) ~[?:1.8.0_171]
    at java.net.SocketInputStream.read(SocketInputStream.java:171) ~[?:1.8.0_171]
    at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[?:1.8.0_171]
    at com.mongodb.internal.connection.SocketStream.read(SocketStream.java:109) ~[mongodb-driver-core-4.4.2.jar!/:?]
    at com.mongodb.internal.connection.SocketStream.read(SocketStream.java:131) ~[mongodb-driver-core-4.4.2.jar!/:?]
    at com.mongodb.internal.connection.InternalStreamConnection.receiveResponseBuffers(InternalStreamConnection.java:718) ~[mongodb-driver-core-4.4.2.ja

I saw many articles talking about tcp keep alive value on the mongo, but it looks fine on my mongo(which is 300S).

0

There are 0 best solutions below