我想使用带有Lua解释器的OpenResty。
我不能让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处理额外的请求而不被第一个请求阻塞的正确方法是什么?
发布于 2017-02-22 16:38:47
local function busyWaiting()
local self = ngx.coroutine.running()
local i = 1
while i < 9999999 do
i = i + 1
ngx.coroutine.yield(self)
end
end
local thread = ngx.thread.spawn(busyWaiting)
while (ngx.coroutine.status(thread) ~= 'dead') do
ngx.coroutine.resume(thread)
end
ngx.say('test1!')https://stackoverflow.com/questions/42346401
复制相似问题