Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-4811

'maxIdleTimeMS' is not adhering to the Mongo Docs

    • Type: Icon: Question Question
    • Resolution: Works as Designed
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: Connection Management
    • Labels:
      None

      Summary

      Hi,

      Currently, I'm working on a mongo java project (Spring boot) that enables the mongo connection pooling for mongo replicates (3 replications - 1 master and 2 replicates). Here I'm using the following mongo connection string variables;

      &maxPoolSize=100&minPoolSize=1&waitQueueTimeoutMS=1000&maxIdleTimeMS=10000 

      So according to this connection string, it should create a pool with min 1 connection for the replicates DB, hence the 3 connections from the application. And the definitions from Mongo Docs regarding the `maxIdleTimeMS` (Connection Pool Overview — MongoDB Manual){_}

      Amount of time that a connection can be idle in the pool before closing. Idle connections close until the number of open connections equals minPoolSize.

      Java driver doc;(Connection Options — Java (mongodb.com))

       

      
      

      Specifies the maximum amount of time, in milliseconds, the Java driver will allow a pooled connection to idle before closing the connection. A value of 0 indicates that there is no upper bound on how long the driver can allow a pooled collection to be idle.

      According to Mongo Docs, this means there should be a connection cleaning when there is only min connection opened or if there are more connections (>3) and idle for 10s, the driver should clear all the idle connections except the min pool. 

      From what I observed in my project, the mongo driver is clearing all the connections (even the min pool connections) and creating it again after 10s, and repeating this again and again, which will use more resources for connection creation.

      Please refer to the following sample logs I have collected from the application. connections 1,3,5 is the initial connections created to the replicate server. And those are killed and created again after 10s.

      sample logs;

      08:30:20.149 - [MaintenanceTimer-1-thread-1] INFO  org.mongodb.driver.connection -  - Closed connection [connectionId{localValue:1, serverValue:1992301}] to <REMOVED>.mongodb.net:27017 because it is past its maximum allowed idle time. 08:30:20.176 - [MaintenanceTimer-2-thread-1] INFO  org.mongodb.driver.connection -  - Closed connection [connectionId{localValue:3, serverValue:1992376}] to <REMOVED>.mongodb.net:27017 because it is past its maximum allowed idle time. 08:30:20.176 - [MaintenanceTimer-3-thread-1] INFO  org.mongodb.driver.connection -  - Closed connection [connectionId{localValue:5, serverValue:2001746}] to <REMOVED>.mongodb.net:27017 because it is past its maximum allowed idle time. 08:30:22.627 - [MaintenanceTimer-1-thread-1] INFO  org.mongodb.driver.connection -  - Opened connection [connectionId{localValue:7, serverValue:1992346}] to <REMOVED>.mongodb.net:27017 08:30:22.656 - [MaintenanceTimer-3-thread-1] INFO  org.mongodb.driver.connection -  - Opened connection [connectionId{localValue:8, serverValue:2001795}] to <REMOVED>.mongodb.net:27017 08:30:22.666 - [MaintenanceTimer-2-thread-1] INFO  org.mongodb.driver.connection -  - Opened connection [connectionId{localValue:9, serverValue:1992423}] to <REMOVED>.mongodb.net:27017 08:31:20.147 - [MaintenanceTimer-1-thread-1] INFO  org.mongodb.driver.connection -  - Closed connection [connectionId{localValue:7, serverValue:1992346}] to <REMOVED>.mongodb.net:27017 because it is past its maximum allowed idle time. 08:31:20.177 - [MaintenanceTimer-2-thread-1] INFO  org.mongodb.driver.connection -  - Closed connection [connectionId{localValue:9, serverValue:1992423}] to <REMOVED>.mongodb.net:27017 because it is past its maximum allowed idle time. 08:31:20.177 - [MaintenanceTimer-3-thread-1] INFO  org.mongodb.driver.connection -  - Closed connection [connectionId{localValue:8, serverValue:2001795}] to <REMOVED>.mongodb.net:27017 because it is past its maximum allowed idle time. 08:31:22.656 - [MaintenanceTimer-2-thread-1] INFO  org.mongodb.driver.connection -  - Opened connection [connectionId{localValue:11, serverValue:1992473}] to <REMOVED>.mongodb.net:27017 08:31:22.656 - [MaintenanceTimer-3-thread-1] INFO  org.mongodb.driver.connection -  - Opened connection [connectionId{localValue:12, serverValue:2001841}] to <REMOVED>.mongodb.net:27017 08:31:22.656 - [MaintenanceTimer-1-thread-1] INFO  org.mongodb.driver.connection -  - Opened connection [connectionId{localValue:10, serverValue:1992399}] to <REMOVED>.mongodb.net:27017 08:32:20.151 - [MaintenanceTimer-1-thread-1] INFO  org.mongodb.driver.connection -  - Closed connection [connectionId{localValue:10, serverValue:1992399}] to <REMOVED>.mongodb.net:27017 because it is past its maximum allowed idle time. 08:32:20.181 - [MaintenanceTimer-2-thread-1] INFO  org.mongodb.driver.connection -  - Closed connection [connectionId{localValue:11, serverValue:1992473}] to <REMOVED>.mongodb.net:27017 because it is past its maximum allowed idle time. 08:32:20.181 - [MaintenanceTimer-3-thread-1] INFO  org.mongodb.driver.connection -  - Closed connection [connectionId{localValue:12, serverValue:2001841}] to <REMOVED>.mongodb.net:27017 because it is past its maximum allowed idle time. 08:32:22.615 - [MaintenanceTimer-3-thread-1] INFO  org.mongodb.driver.connection -  - Opened connection [connectionId{localValue:14, serverValue:2001888}] to <REMOVED>.mongodb.net:27017 08:32:22.674 - [MaintenanceTimer-1-thread-1] INFO  org.mongodb.driver.connection -  - Opened connection [connectionId{localValue:13, serverValue:1992442}] to <REMOVED>.mongodb.net:27017 08:32:22.674 - [MaintenanceTimer-2-thread-1] INFO  org.mongodb.driver.connection -  - Opened connection [connectionId{localValue:15, serverValue:1992519}] to <REMOVED>.mongodb.net:27017 08:33:20.150 - [MaintenanceTimer-1-thread-1] INFO  org.mongodb.driver.connection -  - Closed connection [connectionId{localValue:13, serverValue:1992442}] to <REMOVED>.mongodb.net:27017 because it is past its maximum allowed idle time. 08:33:20.180 - [MaintenanceTimer-3-thread-1] INFO  org.mongodb.driver.connection -  - Closed connection [connectionId{localValue:14, serverValue:2001888}] to <REMOVED>.mongodb.net:27017 because it is past its maximum allowed idle time. 08:33:20.180 - [MaintenanceTimer-2-thread-1] INFO  org.mongodb.driver.connection -  - Closed connection [connectionId{localValue:15, serverValue:1992519}] to <REMOVED>.mongodb.net:27017 because it is past its maximum allowed idle time. 08:33:22.574 - [MaintenanceTimer-1-thread-1] INFO  org.mongodb.driver.connection -  - Opened connection [connectionId{localValue:16, serverValue:1992488}] to <REMOVED>.mongodb.net:27017 08:33:22.671 - [MaintenanceTimer-2-thread-1] INFO  org.mongodb.driver.connection -  - Opened connection [connectionId{localValue:17, serverValue:1992562}] to <REMOVED>.mongodb.net:27017 08:33:22.672 - [MaintenanceTimer-3-thread-1] INFO  org.mongodb.driver.connection -  - Opened connection [connectionId{localValue:18, serverValue:2001931}] to <REMOVED>.mongodb.net:27017 08:34:20.148 - [MaintenanceTimer-1-thread-1] INFO  org.mongodb.driver.connection -  - Closed connection [connectionId{localValue:16, serverValue:1992488}] to <REMOVED>.mongodb.net:27017 because it is past its maximum allowed idle time. 08:34:20.178 - [MaintenanceTimer-3-thread-1] INFO  org.mongodb.driver.connection -  - Closed connection [connectionId{localValue:18, serverValue:2001931}] to <REMOVED>.mongodb.net:27017 because it is past its maximum allowed idle time. 08:34:20.178 - [MaintenanceTimer-2-thread-1] INFO  org.mongodb.driver.connection -  - Closed connection [connectionId{localValue:17, serverValue:1992562}] to <REMOVED>.mongodb.net:27017 because it is past its maximum allowed idle time. 08:34:22.611 - [MaintenanceTimer-1-thread-1] INFO  org.mongodb.driver.connection -  - Opened connection [connectionId{localValue:19, serverValue:1992531}] to <REMOVED>.mongodb.net:27017 08:34:22.680 - [MaintenanceTimer-2-thread-1] INFO  org.mongodb.driver.connection -  - Opened connection [connectionId{localValue:20, serverValue:1992608}] to <REMOVED>.mongodb.net:27017 08:34:22.680 - [MaintenanceTimer-3-thread-1] INFO  org.mongodb.driver.connection -  - Opened connection [connectionId{localValue:21, serverValue:2001978}] to <REMOVED>.mongodb.net:27017 
       

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      current mongo drivers: 

      Mongo Server: Replica (1 master and 2 replicates)

      How to Reproduce

      Create a spring-boot project with the above mongo replicate connection with the above string parameters

      Additional Background

       

            Assignee:
            valentin.kovalenko@mongodb.com Valentin Kavalenka
            Reporter:
            namila007@gmail.com Namila Bandara
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: