question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Memory spike when using `find()`

See original GitHub issue

Do you want to request a feature or report a bug? Report a bug

What is the current behavior? When I make a Model#find call with an $or operator, not only does the operation take ~5 minutes, it also takes up ~1 GB memory.

If the current behavior is a bug, please provide the steps to reproduce. My use-case:

  const result = await Guild.find({
    $or: [
      { premium: { $eq: true } },
      { prefix: { $ne: 'p!' } },
      { blacklistedChannels: { $exists: true, $ne: [], $type: 'array' } },
    ],
  });

Reproduction repo: https://github.com/almeidx/mongoose-memory-leak-repro

When I run node index.js on this repository: image

Not sure if relevant but, here are my collection details:

  • documents: 8360
  • size: 38.71MB

What is the expected behavior? I expected it to not take ~5 minutes to process, but I can understand why it could take that long to process. What I really didn’t expect is the operation using ~1 GB of memory.

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that “latest” is not a version. 14.17.1, 5.12.15 and 3.6.8, respectively (I’m not sure if by ‘MongoDB’ you meant the mongodb npm module or the version of the database. I am using MongoDB Atlas version 4.4.6, mongodb npm module version 3.6.8)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:12

github_iconTop GitHub Comments

2reactions
vkarpov15commented, Oct 7, 2021

Managed to shave off another 5% in 5f9d7ba by reducing unnecessary key creation. In the future, we’ll investigate wrapping strictMode in a getter to see if that gives us a little more.

2reactions
vkarpov15commented, Sep 14, 2021

No worries, glad you found a workaround. We’re going to keep working to try to improve our memory usage going forward, so thanks for your patience and for reporting this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Performance Monitor to Find a User-Mode Memory Leak
After you have determined which process is leaking memory, use the UMDH tool to determine the specific routine that is at fault. For...
Read more >
5 useful tools to detect memory leaks with examples
In this tutorial I will share different methods and tools to detect and find memory leaks with different processes in Linux. As a...
Read more >
Memory leak detection - How to find, eliminate, and avoid
Another method for memory leak detection is to use logging intelligently. Sometimes, faulty code doesn't cause a memory leak, but your users do....
Read more >
How can I find a memory leak of a running process?
Here are the steps that almost guarantee to find what is leaking memory: · Find out the PID of the process which causing...
Read more >
Chasing memory spikes and leaks in Python - Metabob
These spikes were of various heights. My first response was to let it run to the end by greatly increasing the memory available....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found