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

Feature: Improve Agenda Queue Performance #2545

Merged
merged 1 commit into from
Oct 27, 2024

Conversation

andrewbrazzatti
Copy link
Contributor

When the number of jobs in the Agenda queue database gets large, the job polling query starts to tax MongoDB even with appropriate indices on the collection. This PR adds a scheduled Agenda job that moves all the completed jobs to a new history collection so that they can still be interrogated without affecting polling performance.

…nished agenda jobs. This should improve performance for the job processor.
@cofiem
Copy link
Contributor

cofiem commented Oct 22, 2024

Do we care about when completed jobs were moved to the history collection?

Comment on lines +198 to +201
await dbManager.collection(collectionName).find({ nextRunAt: null }).forEach(async (doc) => {
await dbManager.collection(`${collectionName}History`).insertOne(doc);
await dbManager.collection(collectionName).deleteOne({ _id: doc._id });
});
Copy link
Contributor

@cofiem cofiem Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this load all the documents only to write them back?

I don't know how many documents there will be, so this might not matter, but is there a way to do this entirely on the mongodb side?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it does. I did look at using a MongoDB aggregation pipeline but I had concerns about concurrency. It should only be a few dozen records at a time at most. Will backlog a ticket to make it more efficient if we find it isn't enough.

Copy link

codecov bot commented Oct 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 52.65%. Comparing base (7fbb6c9) to head (54d70aa).
Report is 7 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff              @@
##           develop    #2545       +/-   ##
============================================
+ Coverage    31.58%   52.65%   +21.06%     
============================================
  Files          179      179               
  Lines         9374     9380        +6     
  Branches      1354     1354               
============================================
+ Hits          2961     4939     +1978     
+ Misses        6333     4219     -2114     
- Partials        80      222      +142     
Flag Coverage Δ
backend-bruno 44.08% <71.42%> (+20.94%) ⬆️
backend-mocha 48.84% <100.00%> (?)
frontend-app-config 97.87% <ø> (ø)
frontend-core-lib 53.78% <ø> (ø)
frontend-dashboard 74.53% <ø> (ø)
frontend-deleted-records 86.59% <ø> (ø)
frontend-export 100.00% <ø> (ø)
frontend-local-auth 100.00% <ø> (ø)
frontend-manage-roles 63.33% <ø> (ø)
frontend-manage-users 59.81% <ø> (ø)
frontend-report 95.06% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@andrewbrazzatti andrewbrazzatti merged commit c066f73 into develop Oct 27, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants