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

Send USER_IP commands on a different Redis channel, in order to reduce traffic to workers that do not process these commands. #12809

Merged
merged 3 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/12672.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Send `USER_IP` commands on a different Redis channel, in order to reduce traffic to workers that do not process these commands.
1 change: 0 additions & 1 deletion changelog.d/12672.misc

This file was deleted.

1 change: 1 addition & 0 deletions changelog.d/12809.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Send `USER_IP` commands on a different Redis channel, in order to reduce traffic to workers that do not process these commands.
12 changes: 12 additions & 0 deletions synapse/replication/tcp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ def get_logcontext_id(self) -> str:
# by default, we just use the command name.
return self.NAME

def redis_channel_name(self, prefix: str) -> str:
"""
Returns the Redis channel name upon which to publish this command.

Args:
prefix: The prefix for the channel.
"""
return prefix


SC = TypeVar("SC", bound="_SimpleCommand")

Expand Down Expand Up @@ -395,6 +404,9 @@ def __repr__(self) -> str:
f"{self.user_agent!r}, {self.device_id!r}, {self.last_seen})"
)

def redis_channel_name(self, prefix: str) -> str:
return f"{prefix}/USER_IP"


class RemoteServerUpCommand(_SimpleCommand):
"""Sent when a worker has detected that a remote server is no longer
Expand Down
6 changes: 3 additions & 3 deletions synapse/replication/tcp/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ async def _async_send_command(self, cmd: Command) -> None:
# remote instances.
tcp_outbound_commands_counter.labels(cmd.NAME, "redis").inc()

channel_name = cmd.redis_channel_name(self.synapse_stream_prefix)

await make_deferred_yieldable(
self.synapse_outbound_redis_connection.publish(
self.synapse_stream_prefix, encoded_string
)
self.synapse_outbound_redis_connection.publish(channel_name, encoded_string)
)


Expand Down