mirror of
https://github.com/langgenius/dify.git
synced 2026-04-25 05:06:15 +08:00
Currently, the celery worker executing workflows / chatflows uses redis pubsub to publish events to api. (See \_topic\_msg\_generator and \_publish\_streaming\_response) The current implementation uses the default redis client. For large scale deployment, we need to use a dedicated redis cluster to ensure performance. To achieve this, you should: 1. introduce a dedicated configuration class to control the redis address used for pubsub. (Ideally, there should only be one configuration item such as `pubsub_redis_url`, and its default value should be the original redis confugration.) 2. Add an option to switch between pubsub and sharded pubsub. When shared pubsub is specified, the ShardedRedisBroadcastChannel should be used instead. COmplete the task above, add some unit tests.
21 lines
759 B
Python
21 lines
759 B
Python
from configs import dify_config
|
|
from extensions import ext_redis
|
|
from libs.broadcast_channel.redis.channel import BroadcastChannel as RedisBroadcastChannel
|
|
from libs.broadcast_channel.redis.sharded_channel import ShardedRedisBroadcastChannel
|
|
|
|
|
|
def test_get_pubsub_broadcast_channel_defaults_to_pubsub(monkeypatch):
|
|
monkeypatch.setattr(dify_config, "PUBSUB_REDIS_CHANNEL_TYPE", "pubsub")
|
|
|
|
channel = ext_redis.get_pubsub_broadcast_channel()
|
|
|
|
assert isinstance(channel, RedisBroadcastChannel)
|
|
|
|
|
|
def test_get_pubsub_broadcast_channel_sharded(monkeypatch):
|
|
monkeypatch.setattr(dify_config, "PUBSUB_REDIS_CHANNEL_TYPE", "sharded")
|
|
|
|
channel = ext_redis.get_pubsub_broadcast_channel()
|
|
|
|
assert isinstance(channel, ShardedRedisBroadcastChannel)
|