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

Memory consumption - com.mongo.MongoNamespace.checkDatabaseNameValidity

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.1.0
    • Affects Version/s: 3.11.2
    • Component/s: Internal
    • Labels:
      None

      Hi,

      Following the migration of the mongodb driver from version 3.4.2 to version 3.11.2, we noticed an overconsumption of memory during our load tests.

      This overconsumption was already existing in 3.4.2, but was accentuated in more recent versions following the addition of characters to check in the name of the database. (com.mongo.MongoNamespace.checkDatabaseNameValidity)

      This overconsumption can be avoided, since the concatenated message is only necessary if the name of the database is not correct, whereas currently the message is concatenated with each call.

      Several solutions to fix this :

      1. Find an error message to throw without concatenation. (Quickwin)
      2. Change the signature of the com.mongodb.assertions.Assertions.isTrueArgument method
      3. Add a cache for the check database name. If database name is present in the Set => no verification, if not present => verification and add to the set if it is correct, otherwise throw an error.

      Example for second option :

       

      public static void checkDatabaseNameValidity(final String databaseName) {
       notNull("databaseName", databaseName);
       isTrueArgument("databaseName is not empty", !databaseName.isEmpty());
       for (int i = 0; i < databaseName.length(); i++) {
       isTrueArgument(!PROHIBITED_CHARACTERS_IN_DATABASE_NAME.contains(databaseName.charAt(i)), 
       "databaseName does not contain '", databaseName.charAt(i), "'");
       }
      }
      public static void isTrueArgument(final boolean condition, final String ... name) {
       if (!condition) {
       throw new IllegalArgumentException("state should be: " + String.join("", name));
       }
      }
      

       

            Assignee:
            john.stewart@mongodb.com John Stewart (Inactive)
            Reporter:
            lucas.pouzac.pro@gmail.com Lucas Pouzac
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: