Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define custom load balancing algorithm

Here is the situation:

I have a number of web servers, say 10. I need to use a (software) load balancer which can be implemented using a reverse proxy server, like HAProxy or Varnish. Now, All the traffic that we serve is over https and not http, so Varnish is out of the question.

Now, I want to divide the users' request into a few categories, which depend on one of the input (POST) parameters of the request. Depending on that parameter, I need to divide the request among the servers, as based on that, (even if all other input (POST) parameters are same) different servers would serve differently.

So, I need to define a custom load balancing algorithm, such that, for a particular value of that parameter, I divide the load to specific 3 (say), for some other value, divide the request to specific 2 and for other value(s), to remaining 5.

Since I cannot use varnish, as it cannot be use to terminate ssl (defining custom algorithm would have been easy in VCL), I am thinking of using HA-Proxy.

So, here is the question:

Can anyone help me with how to define a custom load balancing function using HA-Proxy?

I've researched a lot and I could not find any such document with which we can. So, if it is not possible with HA-Proxy, can you refer me to some other reverse-proxy service, that can be used as a load balancer too, such that it meets both the above criteria? (ssl termination and ability to define a custom load balancing).

EDIT:

This question is in succession with one of my previous questions. Varnish to be used for https

like image 427
vish4071 Avatar asked Dec 03 '15 15:12

vish4071


People also ask

What is a load balancing algorithm?

What is a load balancing algorithm? A load balancer is a software or hardware device that keeps any one server from becoming overloaded. A load balancing algorithm is the logic that a load balancer uses to distribute network traffic between servers (an algorithm is a set of predefined rules).

What is load balancing explain with examples?

Load balancing is a core networking solution used to distribute traffic across multiple servers in a server farm. Load balancers improve application availability and responsiveness and prevent server overload.

What is load balancing algorithm in cloud computing?

Load balancing is the process of redistribution of workload in a distributed system like cloud computing ensuring no computing machine is overloaded, under-loaded or idle [12, 13]. Load balancing tries to speed up different constrained parameters like response time, execution time, system stability etc.


1 Answers

I'm not sure what your goal is, but I'd suggest NOT doing custom routing based on the HTTP request body at all. This will perform very poorly, and likely outweigh any benefit you are trying to achieve.

Anything that has to parse values beyond typical HTTP headers at your load balancer will slow things down. Cookies by themselves are generally a bad idea if you can avoid it.

If you can control the path/route values that is likely a much better idea than to parse every POST for certain values.


You can probably achieve what you want via NGINX with lua scripts (the Kong platform is based on them), but I can't say how hard that would be for you...

https://github.com/openresty/lua-nginx-module#readme

Here's an article with a specific example of setting different upstreams based on lua input.

http://sosedoff.com/2012/06/11/dynamic-nginx-upstreams-with-lua-and-redis.html

server {
  ...BASE CONFIG HERE...

  port_in_redirect off;

  location /somepath {
    lua_need_request_body on;

    set $upstream "default.server.hostname";

    rewrite_by_lua '
      ngx.req.read_body()  -- explicitly read the req body
      local data = ngx.req.get_body_data()
      if data then
        -- use data: see
        -- https://github.com/openresty/lua-nginx-module#ngxreqget_body_data
        ngx.var.upstream = some_deterministic_value
      end
    '

    ...OTHER PARAMS...
    proxy_pass http://$upstream
  }
}
like image 161
Tracker1 Avatar answered Oct 04 '22 08:10

Tracker1