首页 > 解决方案 > Channels:如何在 Windows Server 上使用 Redis 通道层作为后端来处理大量并发用户?

问题描述

我有一个消费者方法,它使用调度程序(apscheduler库)每 15 秒运行一次。此方法的目的是向频道组中的所有用户发送 JSON 数据。

def auto_update():
    group_name = 'auto_update'
    channel_layer = get_channel_layer()
    async_to_sync(channel_layer.group_send)(
        group_name,
        {
            'type': 'auto_update',  # this is the name of my consumer method which return json data
        }
    )

我已经在 daphne 服务器(作为 API 服务器)上部署了 Django 通道,而 Apache 服务器用于服务 HTTP/HTTPS 请求。

当并发用户增加超过 50(近似值)时,下一个用户将无法接收数据。

收到 403 握手错误。

这种情况的最佳实践是什么?在这里,我只需要向一个大组发送数据(超过 350-460 个并发用户可以达到 1000 个)。

操作系统: Windows Server 2008 R2

内存: 32GB

编辑-1:

在这台服务器上,有两个 daphne 实例正在运行。一个用于此应用程序,另一个用于同样具有 350 个并发用户的应用程序。

达芙妮命令:(作为windows服务)

daphne.exe -e ssl:8081:privateKey=cert\\development.key:certKey=cert\\development.crt --ws-protocol "graphql-ws" --proxy-headers real_time_data.asgi:application

通道层:

CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels_redis.core.RedisChannelLayer",
        "CONFIG": {
            "hosts": [('localhost', 6379)],
        },
    },
}

可能是什么问题?我读过 daphne 可以轻松处理成千上万的用户。有人可以帮助我调试以找到路由原因吗?

编辑2:

来自@MatthausWoolard共享的文档,

A.3.1 Redis 在 Windows 上的缺点

Windows 不支持 fork 系统调用,Redis 在各种情况下使用它来将其数据库转储到磁盘。如果没有 fork 的能力,Redis 无法在不阻塞客户端的情况下执行一些必要的数据库保存方法,直到转储完成。

除了 Redis 之外,还有其他适合生产级用例的 Windows 服务器替代方案吗?或者有什么解决办法?

标签: pythondjangorediswindows-server-2008django-channels

解决方案


推荐阅读