'too many org.mongodb.driver.connection: Opened connection for document DB
We have developed an Arest application that uses document DB to store/retrieve user data.
MongoClientSettings settings =
MongoClientSettings.builder()
.applyToClusterSettings(builder ->
builder.hosts(Arrays.asList(new ServerAddress(clusterEndpoint, 27017))))
.readPreference(ReadPreference.secondaryPreferred())
.retryWrites(false)
.applyToClusterSettings(builder ->
builder.requiredClusterType(ClusterType.REPLICA_SET))
.applyToClusterSettings(builder ->
builder.requiredReplicaSetName("rs0"))
.applyToClusterSettings(builder ->
builder.mode(ClusterConnectionMode.MULTIPLE))
.applyToConnectionPoolSettings(builder ->
builder.maxSize(Integer.parseInt(docDbAppConfig.get("maxSize"))))
.applyToConnectionPoolSettings(builder ->
builder.minSize(Integer.parseInt(docDbAppConfig.get("minSize"))))
.applyToConnectionPoolSettings(builder ->
builder.maxConnectionIdleTime(Integer.parseInt(docDbAppConfig.get("maxConnectionIdleTime")),
TimeUnit.MILLISECONDS))
.credential(MongoCredential.createCredential(username, dbName, password.toCharArray()))
.applyToConnectionPoolSettings(builder ->
builder.maxWaitTime(Integer.parseInt(docDbAppConfig.get("maxWaitTime")), TimeUnit.MINUTES))
.applyToClusterSettings(builder ->
builder.serverSelectionTimeout(Integer.parseInt(docDbAppConfig.get("serverSelectionTimeout")),
TimeUnit.SECONDS))
.applyToSocketSettings(builder ->
builder.connectTimeout(Integer.parseInt(docDbAppConfig.get("connectTimeout")), TimeUnit.SECONDS))
.applyToSocketSettings(builder ->
builder.readTimeout(Integer.parseInt(docDbAppConfig.get("readTimeout")), TimeUnit.SECONDS))
.build();
In our application we have used Dao model and ensure connections are created correctly and closed properly too. Both connection open and close is verified from application logs.
We are using the db.r5.4xlarge server for document DB which has a limit of 14K connections/cursors based on user load. The application works fine when people continue to read/write data, however we are seeing a behaviour where connection goes high and remains in same state for a while unless application is restarted. Below logs are observed during this and after restarting application, connection counts goes back to normal level.
(MaintenanceTimer-5883-thread-1) org.mongodb.driver.connection: Opened connection [connectionId{localValue:61248}]
In order to debug it, we verified all the workflows and their logs for connection open and close, but no anomaly was found. We added debug statements as well when connections are created but that did not help too.
Appreciate if anyone can share their expertise and assist in overcoming this issue.
Solution 1:[1]
Looks like old connections are not closing but new connections are getting opened. please check the different timeout values.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Anshu |