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