python - 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 服务器替代方案吗?或者有什么解决办法?
解决方案
推荐阅读
- r - 从 R 工作室连接到 SQL Server:“错误:nanodbc/nanodbc.cpp:983:00000:[unixODBC][驱动程序管理器]无法打开 lib '驱动程序':找不到文件”
- java - Gradle 构建开始失败并出现错误 - 无法解析配置“:编译”的所有文件
- sql - 删除按三列分组并按日期排序的旧记录
- reactjs - React Call on mount(使用钩子)希望依赖项仍在 TypeScript 中
- c - Valgrind 奇怪的内存泄漏
- python - 树莓派相机 101
- javascript - Javascript回调混淆 - 需要清晰
- azure - 有没有办法将 PowerShell 脚本的失败返回到 azure CLi?
- ruby - 如何使用外部自定义本机库作为依赖项发送 ruby gem/库?
- excel - 如何从 Excel 中的记录列表中选择 MAX 日期 - 项目仪表板