gpt4 book ai didi

sockets - Lua打开套接字报错

转载 作者:可可西里 更新时间:2023-11-01 17:24:16 25 4
gpt4 key购买 nike

我使用 lua 作为 nginx (openresty) 的模块从远程主机获取文件。我的功能:

function readfile(url)
local http = require ("socket.http")
if not http then
error("Couldn't open socket.http")
end
http.TIMEOUT = 5
local body, code = http.request(url)
if not body then
error("Couldn't read the remote file: " .. code)
end
return body
end

我已经使用 Siege 测试了这段代码。当我设置的用户超过 100 个(例如)时,我发现了这个错误:

2018/03/27 09:36:38 [info] 10#10: *91018 shutdown() failed (107: Socket not connected), client: 172.18.0.7, server: localhost

当我设置更多的用户时,我有更多的错误。这是什么意思?感谢您的帮助。

最佳答案

不要将 luasocket 库与 OpenResty 一起使用。生成的代码将在 http.request() 上阻塞。

我想所有的 nginx worker 都阻塞了,这就是这些错误的原因。

为了您的目的,您可以使用以下库之一:

首先是更灵活,允许使用安全传输。第二个具有更简单的 API。

并且两者都在内部使用 nginx Lua cosocket API,并且开箱即用 100% 非阻塞。

关于sockets - Lua打开套接字报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49511172/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com