Hello!
On Wed, Aug 5, 2015 at 10:51 PM, Rick Richardson wrote:
> I wanted to avoid the creation of the Lua String because of the additional
> alloc it would do.
>
Understood.
> I have in fact, created an ngx.write() which takes a LUA_TLIGHTUSERDATA
> and a LUA_TNUMBER and works like ngx.print. I am testing it now.
> I reckon it should probably take a table of userdata,number tuples so it
> can inject multiple buffers per chain
>
Sounds good to me :)
> Obviously this solution needs to be used with flush(true) so I can ensure
> that the data has been written so that I can unmap the memory. Maybe this
> could be tied to some sort of GC or destructor mechanism so that a free
> function can be specified. Unfortunately that is beyond my current lua_ffi
> skillet :)
Oh, no. I suggest you always copy the data from your memory zones to
the buffers used for chain link sending. nginx sends data to the
downstream asynchronously by default (unless you explicitly call
ngx.flush, which is expensive per se).
As compared to dynamic allocations and socket operations, data copying
is (often) not really worth saving in a nontrivial setup. On the other
hand, trying too hard to save data copying can easily lead to (overly)
complicated and fragile memory management.
Well, just my 2 cents.
Regards,
-agentzh