HARMONY-2338: Fix performance issue with work scheduler queueing work items#910
Merged
Conversation
… next work item to queue - from over 7 seconds to just ms in production with 25 million rows in the work_items table.
…ing work items from the database.
…dule differently from the source code.
flamingbear
approved these changes
May 21, 2026
Member
flamingbear
left a comment
There was a problem hiding this comment.
This looks straight forward in terms of the changes and migration.
Removal of the USE_SERVICE_QUEUES flag and associated function relocation for the tests also makes sense.
Migrations work locally and Index shows up when running in Harmony-In-A-Box.
I don't even have any nits.
indiejames
reviewed
May 21, 2026
| * @param reqLogger - a logger instance | ||
| * @returns A work item from the database for the given service ID | ||
| */ | ||
| export async function getWorkFromDatabase(serviceID: string, reqLogger: Logger): Promise<WorkItemData | null> { |
Contributor
There was a problem hiding this comment.
Why did you move this function into test code? Isn't it used in non-test code, e.g., services/hamrony/app/backends/workflow-orchestration.ts?
Contributor
There was a problem hiding this comment.
Oh , wait, never mind, I see now.
indiejames
approved these changes
May 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Jira Issue ID
HARMONY-2338
Description
I found the cause of the poor performance of the work scheduler in production was not a result of locked tables - it was just we needed an index to improve selecting the work item to queue as part of the fair queueing algorithm. After adding the index in production I saw the query went from taking over 7 seconds to just milliseconds.
In addition to adding the index I removed some code that wasn't being used and a feature flag USE_SERVICE_QUEUES that was obsolete.
Local Test Steps
Test the migration up and down.
Verify the index
work_items_ready_lookup_indexis added to the work_items table.If testing harmony in a box build all the images and then run
bin/bootstrap-harmonyand make sure the migrations run. Verify requests continue to work as expected.I tested with harmony in a box and a deployment to sandbox as well.
PR Acceptance Checklist