现在有这样一个需求,前段访问我们的openresty服务器,我会在后台发起多个新的Http请求,但是在请求之前我得判断这些http请求是否达到了最大的QPS的值(每秒都要统计,每次请求都要验证),如果已经达到则不发请求到这个Http链接
后端用的是ngx.thread.spawn来并行的执行请求。请问大家有什么好的方法么local function query_http(url, index) local httpc = http.new() httpc:set_timeout(100) local res, err = httpc:request_uri(url, { method = "GET", headers = { ["Content-Type"] = "application/x-www-form-urlencoded", } }) if not res then logger("Server Url: " .. err .. "ERROR" .. ", request the next server") else result[index] = res.body; endend
--
2016-07-26 16:43 GMT+08:00 <soae...@gmail.com>:现在有这样一个需求,前段访问我们的openresty服务器,我会在后台发起多个新的Http请求,但是在请求之前我得判断这些http请求是否达到了最大的QPS的值(每秒都要统计,每次请求都要验证),如果已经达到则不发请求到这个Http链接有个问题,你这里说的最大 QPS 限制,指的是前端到你,还是你到后端服务,两边有些不对称。如果是前者,可以在不同阶段完成不同任务:log 阶段完成统计信息的收集,收集信息可以存放到 nginx share dict 里面。业务处理阶段,直接使用统计结果进行业务判断。 后端用的是ngx.thread.spawn来并行的执行请求。请问大家有什么好的方法么local function query_http(url, index) local httpc = http.new() httpc:set_timeout(100) local res, err = httpc:request_uri(url, { method = "GET", headers = { ["Content-Type"] = "application/x-www-form-urlencoded", } }) if not res then logger("Server Url: " .. err .. "ERROR" .. ", request the next server") else result[index] = res.body; endendngx.thread + resty-http 的组合,应该是很好的搭配,这块应该问题不大。 -- -- YuanSheng Wang---------------------------------------My Github: https://github.com/membphisOpenResty lover ^_^
openresty 现在在什么阶段能够直接获取 location 的QPS ? 如果没有的话是否有好的思路在 2016年7月26日星期二 UTC+8下午8:40:24,YuanSheng写道:2016-07-26 16:43 GMT+08:00 <soae...@gmail.com>:现在有这样一个需求,前段访问我们的openresty服务器,我会在后台发起多个新的Http请求,但是在请求之前我得判断这些http请求是否达到了最大的QPS的值(每秒都要统计,每次请求都要验证),如果已经达到则不发请求到这个Http链接有个问题,你这里说的最大 QPS 限制,指的是前端到你,还是你到后端服务,两边有些不对称。如果是前者,可以在不同阶段完成不同任务:log 阶段完成统计信息的收集,收集信息可以存放到 nginx share dict 里面。业务处理阶段,直接使用统计结果进行业务判断。 后端用的是ngx.thread.spawn来并行的执行请求。请问大家有什么好的方法么local function query_http(url, index) local httpc = http.new() httpc:set_timeout(100) local res, err = httpc:request_uri(url, { method = "GET", headers = { ["Content-Type"] = "application/x-www-form-urlencoded", } }) if not res then logger("Server Url: " .. err .. "ERROR" .. ", request the next server") else result[index] = res.body; endendngx.thread + resty-http 的组合,应该是很好的搭配,这块应该问题不大。 -- -- YuanSheng Wang---------------------------------------My Github: https://github.com/membphisOpenResty lover ^_^ --
2016-07-26 16:43 GMT+08:00 <soae...@gmail.com>:现在有这样一个需求,前段访问我们的openresty服务器,我会在后台发起多个新的Http请求,但是在请求之前我得判断这些http请求是否达到了最大的QPS的值(每秒都要统计,每次请求都要验证),如果已经达到则不发请求到这个Http链接有个问题,你这里说的最大 QPS 限制,指的是前端到你,还是你到后端服务,两边有些不对称。如果是前者,可以在不同阶段完成不同任务:log 阶段完成统计信息的收集,收集信息可以存放到 nginx share dict 里面。业务处理阶段,直接使用统计结果进行业务判断。 后端用的是ngx.thread.spawn来并行的执行请求。请问大家有什么好的方法么local function query_http(url, index) local httpc = http.new() httpc:set_timeout(100) local res, err = httpc:request_uri(url, { method = "GET", headers = { ["Content-Type"] = "application/x-www-form-urlencoded", } }) if not res then logger("Server Url: " .. err .. "ERROR" .. ", request the next server") else result[index] = res.body; endendngx.thread + resty-http 的组合,应该是很好的搭配,这块应该问题不大。 -- -- YuanSheng Wang---------------------------------------My Github: https://github.com/membphisOpenResty lover ^_^ --
-- -- YuanSheng Wang---------------------------------------My Github: https://github.com/membphisOpenResty lover ^_^