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

Commit 39dee30

Browse files
authored
Send USER_IP commands on a different Redis channel, in order to reduce traffic to workers that do not process these commands. (#12809)
1 parent 10280fc commit 39dee30

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

changelog.d/12672.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Send `USER_IP` commands on a different Redis channel, in order to reduce traffic to workers that do not process these commands.

changelog.d/12672.misc

Lines changed: 0 additions & 1 deletion
This file was deleted.

changelog.d/12809.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Send `USER_IP` commands on a different Redis channel, in order to reduce traffic to workers that do not process these commands.

synapse/replication/tcp/commands.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ def get_logcontext_id(self) -> str:
5858
# by default, we just use the command name.
5959
return self.NAME
6060

61+
def redis_channel_name(self, prefix: str) -> str:
62+
"""
63+
Returns the Redis channel name upon which to publish this command.
64+
65+
Args:
66+
prefix: The prefix for the channel.
67+
"""
68+
return prefix
69+
6170

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

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

407+
def redis_channel_name(self, prefix: str) -> str:
408+
return f"{prefix}/USER_IP"
409+
398410

399411
class RemoteServerUpCommand(_SimpleCommand):
400412
"""Sent when a worker has detected that a remote server is no longer

synapse/replication/tcp/redis.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,10 @@ async def _async_send_command(self, cmd: Command) -> None:
221221
# remote instances.
222222
tcp_outbound_commands_counter.labels(cmd.NAME, "redis").inc()
223223

224+
channel_name = cmd.redis_channel_name(self.synapse_stream_prefix)
225+
224226
await make_deferred_yieldable(
225-
self.synapse_outbound_redis_connection.publish(
226-
self.synapse_stream_prefix, encoded_string
227-
)
227+
self.synapse_outbound_redis_connection.publish(channel_name, encoded_string)
228228
)
229229

230230

0 commit comments

Comments
 (0)