【发布时间】:2017-02-20 13:52:45
【问题描述】:
我想将 OpenResty 与 Lua 解释器一起使用。
我无法让 OpenResty 框架处理对两个不同端点的两个并发请求。我模拟了一个请求通过在一个长循环中运行来进行一些艰苦的计算:
local function busyWaiting()
local self = coroutine.running()
local i = 1
while i < 9999999 do
i = i + 1
coroutine.yield(self)
end
end
local self = coroutine.running()
local thread = ngx.thread.spawn(busyWaiting)
while (coroutine.status(thread) ~= 'zombie') do
coroutine.yield(self)
end
ngx.say('test1!')
另一个端点只是立即发送响应。
ngx.say('test2')
我向第一个端点发送请求,然后向第二个端点发送第二个请求。但是,OpenResty 被第一个请求阻止了,所以我几乎同时收到了两个响应。
将 nginx 参数 worker_processes 1; 设置为更高的数字也无济于事,无论如何我希望只有一个工作进程。
让 OpenResty 处理额外请求而不被第一个请求阻塞的正确方法是什么?
【问题讨论】:
-
您没有提供任何代码向我们展示您如何发送子请求。我假设您使用 ngx.location.capture 之类的东西将子请求发送到端点。对于并行运行的子请求,您应该使用 github.com/openresty/lua-nginx-module#ngxlocationcapture_multi API。
-
我没有使用 ngx.location.capture。我使用两个单独的客户端连接到同一服务器上的两个不同端点。
-
@JeFi 抱歉,没看懂你的用例,现在明白了,看下面我的回答
-
你解决过这个问题吗?
-
@MappaM ,不幸的是我没有。
标签: multithreading nginx lua openresty