-
Notifications
You must be signed in to change notification settings - Fork 2k
Provide ability to bulk insert tasks in TaskRunRecorder #19586
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
Provide ability to bulk insert tasks in TaskRunRecorder #19586
Conversation
5cb526a to
43d9d94
Compare
CodSpeed Performance ReportMerging #19586 will not alter performanceComparing Summary
|
43d9d94 to
6d534e4
Compare
141f126 to
d08f928
Compare
01cd336 to
eecbf78
Compare
|
I changed the approach slightly to insert by task state as ordered in the |
98c61c6 to
e614f33
Compare
desertaxle
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, this is an awesome PR! I have a couple of concerns about the bulk task run insertion, and I left some suggestions for you to consider.
| # Should be the same for all in the batch | ||
| update_cols = batch[0]["task_run_dict"].keys() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might be a somewhat dangerous assumption since there could be variation in the event payload between versions, and those could be in the same batch if they have the same state type.
Could you make this more explicit by batching by the key signature itself? I'm thinking something like this:
batches_by_keys: dict[frozenset[str], list] = {}
for tr in all_task_runs:
key_signature = frozenset(tr["task_run_dict"].keys())
batches_by_keys.setdefault(key_signature, []).append(tr)to replace your current batching by state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, makes sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, took this approach in latest version. Thanks for the review.
3fe7836 to
2e823a0
Compare
desertaxle
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for the awesome PR @saschwartz!
Overview
This merge request attempts to address part of #18753, by making the
TaskRunRecorderservice more efficiently insert tasks into the database by means of bulk insertion.Current Behaviour
Currently, tasks are inserted one-by-one into the database by the service. This is very slow and can cause the messaging layer to become backed up. The throughput in a real-world setting with 5x replicas of TaskRunRecorder was <10 tasks inserted into database per second.
Proposed Behaviour
Tasks are inserted accordingly to a parametrizable batch size and flush interval (this mirrors the configuration parameters for the
EventPersisterServiceDependencies
The PR depends on a few things being merged first:
Testing
Unit tests have been added covering the new codepath. Additionally, this has been stress-tested in an OSS HA setup and with 5x replicas of the
TaskRunRecorder, about 5K per second insertions are achieved with a HA postgres instance.Checklist
<link to issue>"mint.json.