Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Claim local one-time-keys in bulk #16565

Merged
merged 15 commits into from
Oct 30, 2023
Merged

Claim local one-time-keys in bulk #16565

merged 15 commits into from
Oct 30, 2023

Conversation

DMRobertson
Copy link
Contributor

@DMRobertson DMRobertson commented Oct 27, 2023

One of the performance optimsations that Rich spotted in #16554. Another in #16570.

See https://gist.github.com/DMRobertson/243121754aed82eff56fa8ec5181184a for how I convinced myself that the SQL query was legit.

Commitwise reviewable, but sitting in CI over the weekend to see if this works.

David Robertson added 3 commits October 27, 2023 23:33
Otherwise symbols like `count` start to clash. Also my brain hurts.
David Robertson added 2 commits October 28, 2023 00:21
I'm gonna iterate over it multiple times.
@DMRobertson DMRobertson force-pushed the dmr/batch_keys_claim branch 3 times, most recently from cf5f79f to 9c03551 Compare October 28, 2023 00:20
David Robertson added 3 commits October 28, 2023 02:08
We could probably use executemany? But I don't care.
@DMRobertson DMRobertson changed the title WIP: Claim local one-time-keys in bulk Claim local one-time-keys in bulk Oct 28, 2023
@DMRobertson
Copy link
Contributor Author

I think the sytest failure is a flake. Waiting for sytest+workers to finish but I'm gonna assume they pass.

@DMRobertson DMRobertson marked this pull request as ready for review October 28, 2023 01:42
@DMRobertson DMRobertson requested a review from a team as a code owner October 28, 2023 01:42
@clokep
Copy link
Member

clokep commented Oct 28, 2023

I kicked them off again, not sure if they flaked twice or not though.

Comment on lines +1322 to +1329
seen_user_device: Set[Tuple[str, str]] = set()
for user_id, device_id, _, _, _ in otk_rows:
if (user_id, device_id) in seen_user_device:
continue
seen_user_device.add((user_id, device_id))
self._invalidate_cache_and_stream(
txn, self.count_e2e_one_time_keys, (user_id, device_id)
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The old code never used to have this deduplication. If the same (user, device) showed up twice (either with multiple algorithms or claiming multiple keys) we'd send out more than one invalidation for that (user, device). I don't know how much this matters in practice.

Copy link
Member

Choose a reason for hiding this comment

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

I don't know how much this matters in practice.

I suspect it is just inefficient, but doesn't matter too much?

@clokep clokep self-assigned this Oct 30, 2023
Copy link
Member

@clokep clokep left a comment

Choose a reason for hiding this comment

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

Seems reasonable, and I think doing it in bulk will be faster (as less back & forth with the database); but any idea if the database will handle this query sanely?

synapse/storage/databases/main/end_to_end_keys.py Outdated Show resolved Hide resolved
synapse/storage/databases/main/end_to_end_keys.py Outdated Show resolved Hide resolved
@clokep
Copy link
Member

clokep commented Oct 30, 2023

And I think the same question as #16570 -- any idea if this is unit tested? I think it has decent tests though.

Co-authored-by: Patrick Cloke <[email protected]>
@DMRobertson
Copy link
Contributor Author

And I think the same question as #16570 -- any idea if this is unit tested? I think it has decent tests though.

Similar deal. There are tests for handling one key at a time, but none for bulk. I can cobble one together.

@DMRobertson
Copy link
Contributor Author

And I think the same question as #16570 -- any idea if this is unit tested? I think it has decent tests though.

Similar deal. There are tests for handling one key at a time, but none for bulk. I can cobble one together.

🏓 back you, Patrick. I'm not super thrilled with how the test came out and it feels a little too abstract. WDYT?

Copy link
Member

@clokep clokep left a comment

Choose a reason for hiding this comment

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

Seems fine, although a annoying.

@clokep
Copy link
Member

clokep commented Oct 30, 2023

(Assuming the thread I left is accurate)

Co-authored-by: Patrick Cloke <[email protected]>
@DMRobertson DMRobertson merged commit de981ae into develop Oct 30, 2023
41 checks passed
@DMRobertson DMRobertson deleted the dmr/batch_keys_claim branch October 30, 2023 21:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants