通道:如何在windows server上使用Redis通道层作为后端处理大量并发用户?

2024-10-16 20:40:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个consumer方法,它使用调度程序(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(近似值)时,下一个用户将无法接收数据

Getting 403 handshake error.

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

OS:Windows Server 2008 R2

RAM:32GB

编辑-1:

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

Daphne命令:(作为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)],
        },
    },
}

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

编辑-2:

从@MatthausWoolard共享的doc

A.3.1 Drawbacks of Redis on Windows

Windows doesn’t support the fork system call, which Redis uses in a variety of situations to dump its database to disk. Without the ability to fork, Redis is unable to perform some of its necessary database-saving methods without blocking clients until the dump has completed.

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


Tags: oftheto用户name服务器redislayer