Lua back-end load balancing

Hi
I’m using nginx-lua to get some info from a back end “auth” server for
each request
The back end server is a simple http server written by myself - i.e. it
is nowhere near as fast or as optimised as nginx and can therefore be
considered a bottleneck
I could run multiple backend server instances to give it a better chance
of keeping up (i.e. one per cpu core) - but then I’d need to load
balance (only round-robin style) to the multiple backends in my lua
code.
Is there something I can do in lua code to accomplish this?

Many thanks as always

On Fri, Jun 10, 2011 at 7:40 AM, Richard K.
[email protected] wrote:

Im using nginx-lua to get some info from a back end auth server for each
request

Sounds cool :slight_smile:

The back end server is a simple http server written by myself i.e. it is
nowhere near as fast or as optimised as nginx and can therefore be
considered a bottleneck

I could run multiple backend server instances to give it a better chance of
keeping up (i.e. one per cpu core) but then Id need to load balance (only
round-robin style) to the multiple backends in my lua code.

Why not use the nginx upstream block directly? For example:

upstream backend {
     server 10.32.56.4;
     server 10.32.56.3;
}

location = /auth {
     proxy_pass http://backend;
}

No Lua is required here unless you need to custimize the load
balancing algorithm.

Is there something I can do in lua code to accomplish this?

If you insist in using Lua, just a quick note on this: the standard
ngx_proxy module supports dynamic resolvers by interpolating nginx
variables into the proxy_pass directive. I think you can use Lua to
compute the value of your nginx variables, which points to a custom
backend server.

Regards,
-agentzh

Ofcourse!
Many thanks

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs