I’m trying to use both echo module & lua, but I’m having some issues:
I reach quickly “subrequests cycle”. Looking @ the code, subrequests
is unsigned:8,
but I would need thousands of subrequests sometimes. putting
subrequests to unsigned just
results to crashes.
when in config: set_by_lua_file $varname luafile.lua , and
luafile.lua references to ngx.ctx,
I get the following error:
(lua-error)…no request ctx found
according to the doc, ngx.ctx is available in set_lua*, but does not
work. Would anybody suggest
me a workaround ?
I’m trying to use both echo module & lua, but I’m having some issues:
I reach quickly “subrequests cycle”. Looking @ the code, subrequests is
unsigned:8,
but I would need thousands of subrequests sometimes. putting subrequests to
unsigned just
results to crashes.
There’s no way to support thousands of subrequests in a single main
request without patching the nginx core.
But you’re encouraged to try out ngx_lua’s cosocket API to avoid
subrequests altogether. And the cosocket stuff does not have such
limitations.
There’s already several Lua drivers based on that, including
memcached, redis, mysql, http, and mongodb. For instance, the
lua-resty-redis library:
when in config: set_by_lua_file $varname luafile.lua , and luafile.lua
references to ngx.ctx,
I get the following error:
(lua-error)…no request ctx found
according to the doc, ngx.ctx is available in set_lua*, but does not work.
Would anybody suggest
me a workaround ?
This is indeed a bug. Thanks for reporting this!
I’ve just committed a patch for it:
Could you try out the git master HEAD on your side?
There’s no way to support thousands of subrequests in a single main
request without patching the nginx core.
ok
But you’re encouraged to try out ngx_lua’s cosocket API to avoid
subrequests altogether. And the cosocket stuff does not have such
limitations.
hmm, any more documentation about that ?
More about: how to implement it in my lua scripts ?
is that it ? :
local tcp = ngx.socket.tcp
function new(self)
return setmetatable({ sock = tcp() }, mt)
end
?
There’s already several Lua drivers based on that, including
memcached, redis, mysql, http, and mongodb. For instance, the
lua-resty-redis library:
mongodb: you mean mongofs or mongodb ?
But you’re encouraged to try out ngx_lua’s cosocket API to avoid
subrequests altogether. And the cosocket stuff does not have such
limitations.
hmm, any more documentation about that ?
See the official documentation for ngx_lua cosocket:
A little thread hijacking. Are there plans to provide an HTTP response
parser? I suppose that for performance reasons that would have to
be in C along the lines of the Redis parser.
That’s what’s missing, IMHO, in order to completely replace
luasocket.
On Thu, May 3, 2012 at 3:53 PM, Antonio P.P. Almeida [email protected]
wrote:
A little thread hijacking. Are there plans to provide an HTTP response
parser? I suppose that for performance reasons that would have to
be in C along the lines of the Redis parser.
That’s what’s missing, IMHO, in order to completely replace
luasocket.
Liseen Wan has been working on the lua-resty-http library:
https://github.com/liseen/lua-resty-http
We’ll extend that to support more and more HTTP features in the near
future.
But I think it will remain pure Lua because introducing C may not
really help here given the performance of LuaJIT 2.0 (and it has
already been proven in lua-resty-mysql where rewriting the MySQL
packet parser in C actually slowed things down because going across
language boundary is more expensive).
But anyway we can provide pure C API for ngx_lua cosocket, just like
ngx_http_upstream, so a pure C implementation for those lua-resty-*
library will have a chance to achieve better performance than the pure
Lua implementations, but I’m not 100% sure
The cosocket API is used to talk to remote servers in TCP or unix
domain sockets directly. It does not support the subrequest model at
all so it is not used for reusing existing upstream modules.
The “cosocket” term is short for “coroutine-based socket”, it is a
parallel implementation as ngx_http_usptream, see the following graph:
using echo_subrequest_async, I directly reach :
2012/05/03 12:08:25 [error] 13204#0: *1 subrequests cycle while processing
“/trucalacon”,
Which version of nginx are you using?
Last interrogation:
What is the best way to discard body (I mean free the memory by body passed to
subrequests ) ?
There’s no way to release all the memory of a subrequest instantly
because nginx subrequests share the same memory pool as their parent
request. So for long-running requests that issue a lot of serial
subrequests, there will be a good chance of temporary memory leaks in
the lifetime of the main request.
It’s worth mentioning that the ngx_lua cosocket API does not suffer
from this issue because Lua GC handles the resource lifetime there.
Best regards,
-agentzh
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.