Hello! 2013/5/28 charlieyang: > 一直关注你的ngx_lua项目,现在正打算用ngx_lua来代替线上的ip查询服务(python+gevent)。基本思路是用C语言扩展Lua,做成lua模块,供lua直接调用C函数,详细代码 > https://github.com/charlieYong/ipquery 。 > > 大致说下其中ngx_lua的用法,有用得不合适的地方请章老师给点意见 :) > > -- nginx启动时加载ipquery模块,同时加载ip数据数据文件 > init_by_lua ' > _q = require "ipquery" > _q.load_data_file("data/qqwry.dat") > '; > > -- 调用_q.get_ip_info(ip)方法获取ip对应的信息(内存操作) > location /ip { > default_type 'text/plain'; > content_by_lua ' > local args = ngx.req.get_uri_args() > local ip = args["ip"] > if not ip then > ngx.say([[ERR\nNO_IP_ARG\n]]) > return > end > local info = _q.get_ip_info(ip) > if info then > info = [[OK\n]] .. info > else > info = [[ERR\r\nNO_RESULT]] > end > ngx.say(info) > '; > } > > 我大致压了下性能,每秒7k+的吞吐量,虽然没预期好,但是也够应付线上请求。因为用法有点奇怪,一般ngx_lua可以都用于跟上游服务之间的逻辑处理,但我这个其实是纯在nginx进程内进行内存查找,属于CPU密集型操作。不知道是否合适?或者有没有更好的方式呢?谢谢 > :) > 可以,挺好。 单次 CPU 密集型的操作只要不要达到毫秒级的延时就没啥。 另外,你可以使用火焰图工具活体分析你的 nginx worker 进程的 CPU 时间分布: https://github.com/agentzh/nginx-systemtap-toolkit#ngx-sample-bt 同时抄送给 openresty 中文邮件列表:https://groups.google.com/group/openresty 建议你也加入此列表并在那里交流这样的问题,谢谢合作! Best regards, -agentzh
Hello! 2013/5/28 charlieyang: > 一直关注你的ngx_lua项目,现在正打算用ngx_lua来代替线上的ip查询服务(python+gevent)。基本思路是用C语言扩展Lua,做成lua模块,供lua直接调用C函数,详细代码 > https://github.com/charlieYong/ipquery 。 > > 大致说下其中ngx_lua的用法,有用得不合适的地方请章老师给点意见 :) > > -- nginx启动时加载ipquery模块,同时加载ip数据数据文件 > init_by_lua ' > _q = require "ipquery" > _q.load_data_file("data/qqwry.dat") > '; > > -- 调用_q.get_ip_info(ip)方法获取ip对应的信息(内存操作) > location /ip { > default_type 'text/plain'; > content_by_lua ' > local args = ngx.req.get_uri_args() > local ip = args["ip"] > if not ip then > ngx.say([[ERR\nNO_IP_ARG\n]]) > return > end > local info = _q.get_ip_info(ip) > if info then > info = [[OK\n]] .. info > else > info = [[ERR\r\nNO_RESULT]] > end > ngx.say(info) > '; > } > > 我大致压了下性能,每秒7k+的吞吐量,虽然没预期好,但是也够应付线上请求。因为用法有点奇怪,一般ngx_lua可以都用于跟上游服务之间的逻辑处理,但我这个其实是纯在nginx进程内进行内存查找,属于CPU密集型操作。不知道是否合适?或者有没有更好的方式呢?谢谢 > :) > 可以,挺好。 单次 CPU 密集型的操作只要不要达到毫秒级的延时就没啥。 另外,你可以使用火焰图工具活体分析你的 nginx worker 进程的 CPU 时间分布: https://github.com/agentzh/nginx-systemtap-toolkit#ngx-sample-bt 同时抄送给 openresty 中文邮件列表:https://groups.google.com/group/openresty 建议你也加入此列表并在那里交流这样的问题,谢谢合作! Best regards, -agentzh --
@charlieyang , hehe,大家都在做类似的事情,qqwry 如果只是查询,用 lua 可以做到相当好的效率,我的生产环境上每秒能到 24k+/s ,当然和你的具体用法可能不太一样 Lance 2013/5/29 agentzh <age...@gmail.com> Hello! 2013/5/28 charlieyang: > 一直关注你的ngx_lua项目,现在正打算用ngx_lua来代替线上的ip查询服务(python+gevent)。基本思路是用C语言扩展Lua,做成lua模块,供lua直接调用C函数,详细代码 > https://github.com/charlieYong/ipquery 。 > > 大致说下其中ngx_lua的用法,有用得不合适的地方请章老师给点意见 :) > > -- nginx启动时加载ipquery模块,同时加载ip数据数据文件 > init_by_lua ' > _q = require "ipquery" > _q.load_data_file("data/qqwry.dat") > '; > > -- 调用_q.get_ip_info(ip)方法获取ip对应的信息(内存操作) > location /ip { > default_type 'text/plain'; > content_by_lua ' > local args = ngx.req.get_uri_args() > local ip = args["ip"] > if not ip then > ngx.say([[ERR\nNO_IP_ARG\n]]) > return > end > local info = _q.get_ip_info(ip) > if info then > info = [[OK\n]] .. info > else > info = [[ERR\r\nNO_RESULT]] > end > ngx.say(info) > '; > } > > 我大致压了下性能,每秒7k+的吞吐量,虽然没预期好,但是也够应付线上请求。因为用法有点奇怪,一般ngx_lua可以都用于跟上游服务之间的逻辑处理,但我这个其实是纯在nginx进程内进行内存查找,属于CPU密集型操作。不知道是否合适?或者有没有更好的方式呢?谢谢 > :) > 可以,挺好。 单次 CPU 密集型的操作只要不要达到毫秒级的延时就没啥。 另外,你可以使用火焰图工具活体分析你的 nginx worker 进程的 CPU 时间分布: https://github.com/agentzh/nginx-systemtap-toolkit#ngx-sample-bt 同时抄送给 openresty 中文邮件列表:https://groups.google.com/group/openresty 建议你也加入此列表并在那里交流这样的问题,谢谢合作! Best regards, -agentzh --
@lance, qqwry是直接mmap到内存只用于查询的。7k-1w/s的性能就是我担心的,预期能更高,所以不清楚用法上是不是有别扭的地方,当然也有可能是我查询逻辑的代码没写好。在 2013年5月29日星期三UTC+8上午11时21分02秒,Lance Li写道: @charlieyang , hehe,大家都在做类似的事情,qqwry 如果只是查询,用 lua 可以做到相当好的效率,我的生产环境上每秒能到 24k+/s ,当然和你的具体用法可能不太一样 Lance 2013/5/29 agentzh <age...@gmail.com> Hello! 2013/5/28 charlieyang: > 一直关注你的ngx_lua项目,现在正打算用ngx_lua来代替线上的ip查询服务(python+gevent)。基本思路是用C语言扩展Lua,做成lua模块,供lua直接调用C函数,详细代码 > https://github.com/charlieYong/ipquery 。 > > 大致说下其中ngx_lua的用法,有用得不合适的地方请章老师给点意见 :) > > -- nginx启动时加载ipquery模块,同时加载ip数据数据文件 > init_by_lua ' > _q = require "ipquery" > _q.load_data_file("data/qqwry.dat") > '; > > -- 调用_q.get_ip_info(ip)方法获取ip对应的信息(内存操作) > location /ip { > default_type 'text/plain'; > content_by_lua ' > local args = ngx.req.get_uri_args() > local ip = args["ip"] > if not ip then > ngx.say([[ERR\nNO_IP_ARG\n]]) > return > end > local info = _q.get_ip_info(ip) > if info then > info = [[OK\n]] .. info > else > info = [[ERR\r\nNO_RESULT]] > end > ngx.say(info) > '; > } > > 我大致压了下性能,每秒7k+的吞吐量,虽然没预期好,但是也够应付线上请求。因为用法有点奇怪,一般ngx_lua可以都用于跟上游服务之间的逻辑处理,但我这个其实是纯在nginx进程内进行内存查找,属于CPU密集型操作。不知道是否合适?或者有没有更好的方式呢?谢谢 > :) > 可以,挺好。 单次 CPU 密集型的操作只要不要达到毫秒级的延时就没啥。 另外,你可以使用火焰图工具活体分析你的 nginx worker 进程的 CPU 时间分布: https://github.com/agentzh/nginx-systemtap-toolkit#ngx-sample-bt 同时抄送给 openresty 中文邮件列表:https://groups.google.com/group/openresty 建议你也加入此列表并在那里交流这样的问题,谢谢合作! Best regards, -agentzh -- -- #xA0;
@charlieyang , hehe,大家都在做类似的事情,qqwry 如果只是查询,用 lua 可以做到相当好的效率,我的生产环境上每秒能到 24k+/s ,当然和你的具体用法可能不太一样 Lance 2013/5/29 agentzh <age...@gmail.com> Hello! 2013/5/28 charlieyang: > 一直关注你的ngx_lua项目,现在正打算用ngx_lua来代替线上的ip查询服务(python+gevent)。基本思路是用C语言扩展Lua,做成lua模块,供lua直接调用C函数,详细代码 > https://github.com/charlieYong/ipquery 。 > > 大致说下其中ngx_lua的用法,有用得不合适的地方请章老师给点意见 :) > > -- nginx启动时加载ipquery模块,同时加载ip数据数据文件 > init_by_lua ' > _q = require "ipquery" > _q.load_data_file("data/qqwry.dat") > '; > > -- 调用_q.get_ip_info(ip)方法获取ip对应的信息(内存操作) > location /ip { > default_type 'text/plain'; > content_by_lua ' > local args = ngx.req.get_uri_args() > local ip = args["ip"] > if not ip then > ngx.say([[ERR\nNO_IP_ARG\n]]) > return > end > local info = _q.get_ip_info(ip) > if info then > info = [[OK\n]] .. info > else > info = [[ERR\r\nNO_RESULT]] > end > ngx.say(info) > '; > } > > 我大致压了下性能,每秒7k+的吞吐量,虽然没预期好,但是也够应付线上请求。因为用法有点奇怪,一般ngx_lua可以都用于跟上游服务之间的逻辑处理,但我这个其实是纯在nginx进程内进行内存查找,属于CPU密集型操作。不知道是否合适?或者有没有更好的方式呢?谢谢 > :) > 可以,挺好。 单次 CPU 密集型的操作只要不要达到毫秒级的延时就没啥。 另外,你可以使用火焰图工具活体分析你的 nginx worker 进程的 CPU 时间分布: https://github.com/agentzh/nginx-systemtap-toolkit#ngx-sample-bt 同时抄送给 openresty 中文邮件列表:https://groups.google.com/group/openresty 建议你也加入此列表并在那里交流这样的问题,谢谢合作! Best regards, -agentzh -- -- #xA0;