[JAVA-3619] Memory consumption - com.mongo.MongoNamespace.checkDatabaseNameValidity Created: 04/Feb/20  Updated: 28/Oct/23  Resolved: 21/Feb/20

Status: Closed
Project: Java Driver
Component/s: Internal
Affects Version/s: 3.11.2
Fix Version/s: 4.1.0

Type: Improvement Priority: Major - P3
Reporter: Lucas Pouzac Assignee: John Stewart (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File mission_control.png    

 Description   

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));
 }
}

 



 Comments   
Comment by Githook User [ 21/Feb/20 ]

Author:

{'username': 'jstewart-mongo', 'name': 'John Stewart', 'email': 'john.stewart@mongodb.com'}

Message: Improve performance of MongoNamespace.checkDatabaseNameValidity

JAVA-3619
Branch: 4.0.x
https://github.com/mongodb/mongo-java-driver/commit/0c0b5de928e6f42558ab9a9349d5ea8d4ba13bd5

Comment by Githook User [ 21/Feb/20 ]

Author:

{'name': 'John Stewart', 'username': 'jstewart-mongo', 'email': 'john.stewart@mongodb.com'}

Message: Improve performance of MongoNamespace.checkDatabaseNameValidity

JAVA-3619
Branch: 3.11.x
https://github.com/mongodb/mongo-java-driver/commit/0c008785a3f7874f6807167932ac49b2d26815a8

Comment by Githook User [ 21/Feb/20 ]

Author:

{'name': 'John Stewart', 'username': 'jstewart-mongo', 'email': 'john.stewart@mongodb.com'}

Message: Improve performance of MongoNamespace.checkDatabaseNameValidity

JAVA-3619
Branch: 3.12.x
https://github.com/mongodb/mongo-java-driver/commit/892d0dec8caaeacf772d67a930957fd007ad37bd

Comment by Githook User [ 21/Feb/20 ]

Author:

{'name': 'John Stewart', 'username': 'jstewart-mongo', 'email': 'john.stewart@mongodb.com'}

Message: Improve performance of MongoNamespace.checkDatabaseNameValidity

JAVA-3619
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/cbbaf4fcfe8621ad1da12fdce62f840e949a31f4

Generated at Thu Feb 08 09:00:02 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.