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

Add ability to shard the federation sender #7798

Merged
merged 13 commits into from
Jul 10, 2020

Conversation

erikjohnston
Copy link
Member

No description provided.

@erikjohnston erikjohnston force-pushed the erikj/shard_federation_sender branch from 85251e9 to 83fed31 Compare July 7, 2020 14:51
@erikjohnston erikjohnston force-pushed the erikj/shard_federation_sender branch 2 times, most recently from 5895375 to 3f0613e Compare July 9, 2020 11:08
@erikjohnston erikjohnston force-pushed the erikj/shard_federation_sender branch from 3f0613e to 04fb6f5 Compare July 9, 2020 11:22
@erikjohnston erikjohnston requested a review from a team July 9, 2020 11:22
Attributes in `Config` object should be accessed via the sections, i.e.
`config.server.start_pushers` rather than `config.start_pushers`,
however a lot of code still uses the latter. If we set
`config.start_pushers` then only that only changes the config for the
latter style lookup.
@clokep clokep self-assigned this Jul 9, 2020
Comment on lines +38 to +40
# If multiple federation senders are not defined we always return true.
if not self.instances or len(self.instances) == 1:
return True
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 think this can change after creation, so should we do this in FederationConfig() and have a MonolithFederationSendingConfig which always returns True fro should_send_to?

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought about this and I think its more lines of code for not a lot. Sending federation requests is sufficiently expensive that I don't think avoiding two boolean checks really makes a difference

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.

Not fully related to this PR, but it seems that _send_pdu is re-doing some work of the caller.

Comment on lines +76 to +77
for domain in federation_domain_whitelist:
self.federation_domain_whitelist[domain] = True
Copy link
Member

Choose a reason for hiding this comment

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

Not really related to this PR, but we should probably normalize these domains.

Also, can't this be a set() instead of a dict()?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd rather not try and deal with that here.

Comment on lines 460 to 461
if destination == self.server_name:
continue
Copy link
Member

Choose a reason for hiding this comment

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

Is it worth uplifting the check of whether to not self-send into should_send_to? It seems to be done in many places already!

Copy link
Member Author

Choose a reason for hiding this comment

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

Possibly, but I think that'll risk conflating different ideas in a way that is going to lead to confusion down the line

synapse/federation/sender/__init__.py Outdated Show resolved Hide resolved
synapse/federation/sender/per_destination_queue.py Outdated Show resolved Hide resolved
tests/replication/test_federation_sender_shard.py Outdated Show resolved Hide resolved
tests/replication/test_federation_sender_shard.py Outdated Show resolved Hide resolved
tests/replication/test_federation_sender_shard.py Outdated Show resolved Hide resolved

sent_on_1 = False
sent_on_2 = False
for i in range(20):
Copy link
Member

Choose a reason for hiding this comment

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

This loops seems a bit hammer-ish, can't we choose server names such that we know they'll be shared separately? Or do you not want this test to have any knowledge of the sharding algorithm?

Alternately, it could make sense to use a test-sharding class which does something simpler. Of course the sharding logic would be tested then, but it could be tested with a lower-level unit tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

Err, i was planning on using hard coded domains but i forget why I didn't :/ But I'm not terribly concerned with this style if I'm honest.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not super concerned either, there's I suppose a small chance of a flaky test, but....

@erikjohnston erikjohnston requested a review from clokep July 10, 2020 17:02
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, assuming CI passes.

babolivier pushed a commit that referenced this pull request Sep 1, 2021
* commit 'f299441cc':
  Add ability to shard the federation sender (#7798)
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