[COMPASS-7567] Running at 100% CPU for a script that inserts 5k records on slow connection Created: 09/Jan/24  Updated: 24/Jan/24

Status: Open
Project: Compass
Component/s: Embedded Shell, Performance
Affects Version/s: None
Fix Version/s: None

Type: Investigation Priority: Major - P3
Reporter: Bjorn Harvold Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

OS: Mac OS Sonoma
node.js / npm versions: 20.10.x
Additional info:


Attachments: File 659ce0de8620958172bbd11e_log.gz     Text File Sample of MongoDB Compass Helper.txt     PNG File Screenshot 2024-01-09 at 15.57.35.png     PNG File Screenshot 2024-01-09 at 15.58.22.png     PNG File Screenshot 2024-01-17 at 6.49.18 PM.png     File responsiveness.mp4    
Assigned Teams:
Developer Tools

 Description   

Problem Statement/Rationale

Very simple insert script execute on MongoDb Atlas and my MacBook Pro M1 is running hot due to Compass Electron app while I insert 1 record every 5 seconds or so. It's crawling to halt. Memory leak?

Please be sure to attach relevant logs with any sensitive data redacted.

Steps to Reproduce

Create a for-loop with 5K records and a JSON payload with 4 - 5 parameters. Can be very simple.

Additional Notes



 Comments   
Comment by Rhys Howell [ 17/Jan/24 ]

bjorn.harvold@traveliko.com Printing a large json to the screen frequently is a costly procedure. In the script that's causing Compass to print so much it's slowed down. Short term I'd recommend updating the script to only printjson sometimes or write to a file in batches to improve the performance.

Here's a minimal reproduction that spikes my cpu:
 

for(let i = 0; i < 100; i++) {
  printjson({
    test: Math.random()*100
  });
}

 
I'll bring this up with the team and see if this is something we want to throttle ourselves or mitigate somehow. Especially if it bricks your machine or app.

Comment by Bjorn Harvold [ 11/Jan/24 ]

Hi leroux.bodenstein@mongodb.com

Yes, this is Compass's embedded mongosh client.

Sample script:

db.getCollection("engineConfigurationView")
.find({"engineConfiguration.primary": true})
.forEach(function(view) {
    print("Found EC with ID: " + view._id);
    
   const ec = view.engineConfiguration;
   let settings = db.getCollection("syndicationSettings").findOne({"ownerIdentifier" : view.engineConfiguration.ownerIdentifier });
   
   if (settings == null) {
       const uuid = UUID().toString('hex').replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, '$1-$2-$3-$4-$5');
       settings = {
           _id: uuid,
           userIdentifier: ec.userIdentifier,
           ownerIdentifier: ec.ownerIdentifier,
           intelligent: true,
           initialDisplayType: "GRID_COLUMNS",
           engineConfigurationIdentifier: view._id,
           createdDate: new ISODate(),
           lastUpdate: new ISODate(),
           version: NumberLong("0")
       };
       
       printjson(settings);
       db.getCollection("syndicationSettings").insertOne(settings);
   }
});

Comment by Le Roux Bodenstein [ 10/Jan/24 ]

Hi bjorn.harvold@traveliko.com

Is this in the embedded mongosh shell in compass? Can you send us an example of your script?

Comment by Bjorn Harvold [ 09/Jan/24 ]

Attached a video where you can see that the app is not responsive at all when I try to click on some of the tabs. Took 10s to response to me clicking on one of the top tabs..

Comment by Bjorn Harvold [ 09/Jan/24 ]

Compass v1.41.0

Comment by PM Bot [ 09/Jan/24 ]

Hello bjorn.harvold@traveliko.com, thank you for reaching out to us! The team will review your issue and get back to you soon as soon as possible.

Please review your issue to ensure you've included your environment details and have attached relevant logs (with any sensitive data redacted), so that we're best able to provide you a timely and thorough response. Thanks again!

Generated at Wed Feb 07 22:46:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.