Hello!
On Tue, Jan 5, 2016 at 8:35 AM, CJ Ess wrote:
> Ok, so the way I would envision this working then is I'd create an array to
> hold the socket_udp objects sometime in the initialization stage, then in
> the request stages I'd try to pop a socket_udp from the array, create a new
> one if the array is empty, include some magic number in my UDP payload so I
> can be certain that anything I receive is for the current request and not a
> previous request, then at the end of the request I push the socket_udp
> object back into the table for the next request. Thats a nice
> middle-of-the-road setup I hadn't considered before.
>
> However, with that setup I'd still be concerned that because nginx is so
> crazy good at what it does, it would be practical to open more then > 64K
> sockets unless I had each worker bind outgoing UDP to a seperate IP address,
> so I'd still like to see if there is some way I could multiplex
> requests/responses to a backend though a single UDP socket per worker.
> Within the lua framework, is there some way I could send out the nginx
> request context (an integer) then have the backend echo that back and
> somehow use that to direct the response received to the right request
> context?
Well, you could do that NOW with init_worker_by_lua* + ngx.timer.at +
ngx.socket.udp + ngx.semaphore. Just keep a live UDP cosocket object
in a background light thread initiated by the timer in
init_worker_by_lua and use this UDP cosocket to multiplex all the
requests of your NGINX's downstream request handlers. And use
ngx.semaphore to synchronize the light threads. This should be very
efficient. You need at least the following version of OpenResty
though:
https://openresty.org/download/ngx_openresty-1.9.7.2rc0.tar.gz
Good luck :)
Best regards,
-agentzh