Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Bug Report: Very High CPU Utilization and Slow MongoDB Queries due to missing Indexes #7430

Closed
2 tasks done
L-U-C-K-Y opened this issue Jan 4, 2025 · 2 comments · Fixed by #7431
Closed
2 tasks done
Labels

Comments

@L-U-C-K-Y
Copy link
Contributor

L-U-C-K-Y commented Jan 4, 2025

📜 Description

Our application experiences extremely high CPU utilization and slow MongoDB query performance when using Novu for notifications. Even after upgrading to a high-performance server (Standard D64lds v5: 64 vCPUs, 128 GiB memory on Azure), Novu consistently utilizes 100% of the CPU. Analysis reveals that MongoDB queries on the jobs collection result in full collection scans (COLLSCAN), leading to long execution times and high resource consumption.

Here are some sample query statistics:

Query 1:

  • Filter: {"_environmentId": "", "_parentId": ""}
  • Execution Time: 74 seconds
  • Plan Summary: COLLSCAN

Query 2:

  • Filter: {"transactionId": null, "_environmentId": null}
  • Execution Time: 38 seconds
  • Plan Summary: COLLSCAN
SCR-20250104-nvhr-2 SCR-20250104-niuy-2 image

👟 Reproduction steps

  1. Configure Novu with a MongoDB database.
  2. Run the application under normal usage with notifications being sent.
  3. Monitor MongoDB queries using db.currentOp() or the MongoDB profiler.
  4. Observe queries on the jobs collection with filters such as:
{"_environmentId": "<value>", "_parentId": "<value>"}
{"transactionId": null, "_environmentId": null}
  1. Note the planSummary field, which reports COLLSCAN.

👍 Expected behavior

Queries on the jobs collection should use indexes to ensure efficient performance, avoiding full collection scans. CPU utilization should remain within reasonable limits even under high query loads.

  1. Verify that appropriate indexes exist on the jobs collection for fields such as _environmentId, _parentId, and transactionId.
  2. Optimize query structure to ensure indexes are utilized.
  3. Profile queries to ensure efficient execution plans and address potential performance bottlenecks.

👎 Actual Behavior with Screenshots

  • MongoDB queries use COLLSCAN, resulting in high query execution times (up to 74 seconds).
  • CPU utilization reaches 100% on a powerful server (64 vCPUs, 128 GiB memory).
  • Slow query performance affects the overall application responsiveness.

Novu version

v2.1.0

npm version

No response

node version

No response

📃 Provide any additional context for the Bug.

No response

👀 Have you spent some time to check if this bug has been raised before?

  • I checked and didn't find a similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to submit PR?

Yes I am willing to submit a PR!

@github-actions github-actions bot added the triage label Jan 4, 2025
@L-U-C-K-Y
Copy link
Contributor Author

Ohhhh! I thought something might be up and I saw that in the DAL indexes are defined.

With some searching, I found the environment variable AUTO_CREATE_INDEXES and set it to true.

I'll create a PR that mentions this in the docs / docker-compose if that's fine.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant