Hello, having performance problems while proxying without buffering or streaming large video objects using James Hurst's resty.http library, simply doing the following,
local chunksize = chunksize or 8192
local httpc = self.http.new()
httpc:set_timeout(500)
local scheme, host, port, path = unpack(httpc:parse_uri(base_url))
local ok, err = httpc:connect(host, port)
if not ok then
ngx.log(ngx.ERR, err)
return
end
httpc:set_timeout(2000)
local res, err = httpc:request{
method = "GET",
path = string.format("/%s/%s", bucket, key),
headers = {
["Date"] = date_str,
["Authorization"] = get_auth_header,
},
}
if not res then
ngx.say("failed to request: ", err)
return
end
ngx.status = res.status
local reader = res.body_reader
repeat
local chunk, err = reader(8192)
if err then
ngx_log(ngx_ERR, err)
break
end
if chunk then
local res, err = ngx.print(chunk)
if not res then
ngx_log(ngx_ERR, err)
break
end
ngx.flush(true)
end
until not chunk
httpc:set_keepalive()
Using this implementation I don't see large memory utilizations but not the same for the for cpu usage, done a simple two test by
1. proxying 1GB file by utilizing 1gbps network and observed 50% average cpu usage on nginx worker process,
2. serving the file from local file system by utilizing 1gbps network, and observed nearly zero memory and cpu usage,
I am expecting to see the same cpu usage with lua implementation, I could get the flame graphs with sample-bt systemtap script as you can find attached.
Could you suggest howto optimize such cpu cycles?
Regards,
Emin.