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

Commit

Permalink
Send USER_IP commands on a different Redis channel, in order to red…
Browse files Browse the repository at this point in the history
…uce traffic to workers that do not process these commands. (#12809)
  • Loading branch information
reivilibre committed May 20, 2022
1 parent 10280fc commit 39dee30
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
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

0 comments on commit 39dee30

Please sign in to comment.