We use balancer_by_lua which invokes lua code to select an upstream server based on chash. ngx_timer_at is used by one worker to send requests to etcd server in every 10 secs interval.
Lua specific code for sending http request is as follows.
local function fetch(url)
local client = http:new()
client:set_timeout(10000)
client:connect(_M.conf.etcd_host, _M.conf.etcd_port)
local res, err = client:request({path=url, method="GET"})
if err then
return nil, err
end
local body, err = res:read_body()
if err then
return nil, err
end
-- testloginfo("fetch response body: " .. body)
local ok, data = "" body)
if not ok then
testlogerr("In fetch, pcall or json decode failed, body: " .. body)
return nil, data
end
data.etcdIndex = res.headers["x-etcd-index"]
-- testloginfo("fetch end of function, data.etcdIndex: " .. data.etcdIndex)
return data, nil
end
We are seeing high response time in load testing and was trying to understand whether lua-http-resty API calls are blocking the nginx workers.
1. Is the client:connect and client:request API's blocking calls ?
2. How does res:read_body reads the response from server without blocking ?