[ANN] ngx_lua v0.1.5: ability to capture multiple parallel subrequests

agentzh agentzh at gmail.com
Thu Feb 10 08:30:14 MSK 2011


On Wed, Feb 9, 2011 at 6:34 PM, Marcus Clyne <maccaday at gmail.com> wrote:
> Hi,
>
> Nice work guys!
>

Thanks! :D

>
> Is it also possible to pass an array of requests and get an array of
> responses, or otherwise send requests in parallel when you don't know in
> advance how many subrequests you want to issue?
>

Sure! For instance,

    -- construct the requests table
    local reqs = {}
    table.insert(reqs, { "/mysql" })
    table.insert(reqs, { "/postgres" })
    table.insert(reqs, { "/redis" })
    table.insert(reqs, { "/memcached" })

    -- issue all the requests at once and wait when they all return
    local resps = { ngx.location.capture_multi(reqs) }

    -- loop over the responses table
    for i, resp in ipairs(resps) do
         -- process the response table "resp"
    end

Well, it's mostly a feature on the Lua language level ;)

> Looking at the documentation, it doesn't appear that this is currently
> possible.

I'll add a note for this to ngx_lua's documentation :)

> I'd like to get into using Lua on Nginx for something I'm working on right
> now that issues lots of subrequests, but I don't know how many I need to
> issue in advance.
>

Yeah, that's understandable :)

BTW, I've cc'd the nginx mailing list for reference :)

Cheers,
-agentzh



More information about the nginx mailing list