Openresty并发请求

时间:2017-02-20 13:52:46

标签: multithreading nginx lua openresty

我想将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处理其他请求而不被第一个请求阻止的正确方法是什么?

0 个答案:

没有答案