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

Conversation

MadLittleMods
Copy link
Contributor

@MadLittleMods MadLittleMods commented May 12, 2023

Process previously failed backfill events in the background because they are bound to fail again and we don't need to waste time holding up the request for something that is bound to fail again.

Fix #13623

Follow-up to #13621 and #13622

Part of making /messages faster: #13356


For example, in this /messages request, this PR would have saved 15s because the event being processed by the _process_pulled_event with a ❗ has already failed 4 times previously and we would just process it in the background.

Full Jaeger trace JSON

Dev notes

backfill
_process_pulled_events
_process_pulled_event

Testing:

SYNAPSE_POSTGRES=1 SYNAPSE_POSTGRES_USER=postgres SYNAPSE_TEST_LOG_LEVEL=INFO python -m twisted.trial tests.storage.test_event_federation.EventFederationWorkerStoreTestCase.test_separate_event_ids_with_failed_pull_attempts
COMPLEMENT_ALWAYS_PRINT_SERVER_LOGS=1 COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh -run TestImportHistoricalMessages

Related PRs

Todo

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Pull request includes a sign off
  • Code style is correct
    (run the linters)

This function is used for backfill and when another server sends us a PDU. In
either case, we're trying to avoid the costly state calculations to see if
it's allowed so I think we should always do this check

See #15585 (comment)
@MadLittleMods MadLittleMods marked this pull request as ready for review May 17, 2023 10:02
@MadLittleMods MadLittleMods requested a review from a team as a code owner May 17, 2023 10:02
@MadLittleMods MadLittleMods added A-Performance Performance, both client-facing and admin-facing T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements. A-Messages-Endpoint /messages client API endpoint (`RoomMessageListRestServlet`) (which also triggers /backfill) A-Federation labels May 17, 2023
Comment on lines +755 to +757
# Ensure `run_as_background_process(...)` has a chance to run (essentially
# `wait_for_background_processes()`)
self.reactor.pump((0.1,))
Copy link
Contributor Author

@MadLittleMods MadLittleMods May 24, 2023

Choose a reason for hiding this comment

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

Continuing from previous comment,

The test passes even without this pump(). I'm uncertain about the exact intricacies and details of run_as_background_process(...) that allow it to pass. It is possible that the test passes due to its time-sensitive nature, and without the pump(), it might become flakey. However, these are merely theoretical assumptions.

But I want to ensure that this test is robust to any work that may happen in run_as_background_process(...) in the future. Ideally, we would have an idiomatic wait_for_background_processes() that would indicate clear intentions and handle the complexity of whatever waiting is necessary.

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.

Looks good! Thanks for working through it with me.

@clokep
Copy link
Member

clokep commented May 24, 2023

Although I see now that CI is unhappy...

@MadLittleMods MadLittleMods merged commit 77156a4 into develop May 25, 2023
@MadLittleMods MadLittleMods deleted the madlittlemods/process-previously-failed-events-in-background branch May 25, 2023 04:22
@MadLittleMods
Copy link
Contributor Author

Thanks for the review and extra push today @clokep to get this across the line 🦮

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Federation A-Messages-Endpoint /messages client API endpoint (`RoomMessageListRestServlet`) (which also triggers /backfill) A-Performance Performance, both client-facing and admin-facing T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Process previously failed backfill events in the background
2 participants