Need help on Load Balancing algorithms

Hi everyone,

Some of my load balancers have to implement a Least Time type algorithms and some other need to use a combination of a Power of two random choices type algorithm with a Least Time one after the random selection of two nodes have been done. I have found 2 relevant articles refering to such a set up, one for HaProxy (Test Driving “Power of Two Random Choices” Load Balancing - HAProxy Technologies) and one for NGINX (NGINX and the “Power of Two Choices” Load-Balancing Algorithm - NGINX).

In HaProxy official documentation, I have yet not found any reference to a Least Time or any combination of Power of two random choices and Least Time algorithms : DevDocs

Do such algorithms exist in HaProxy ?

I am in a situation where I cannot escape from using those algos, any help on this would be highly appreciated !

Hi,

The “least time” alogrithm does not exist in HAProxy. And combining 2 algorithms is not possible.

The only solution I see for you is to code your own algorithm in Lua and use it in HAProxy:

backend foo
  http-request lua.mylbalgo
  use-server %[var(txn.destination)]

and the lua script would do something like:

core.register_action("mylbalgo", { "http-req" }, mylbalgo)

function mylbalgo(txn)
  var dest
  -- do your magic here and set destination into 'dest' variable
  txn:set_var(txn, "txn.destination", dest)
end)
1 Like

Hey Baptiste,

Thanks a lot for your clear answer, using lua can indeed be a nice customizable solution. I’ll keep you updated on how it goes testing this out.

Hey Baptiste,

I am working on implementing a Least Time LB algorithm, which will arbitrate regarding both the current connections on servers and the average processing time of requests by a specific server.
Hence, I need to fetch and store the processing time of each request (probably on a local redis or another high availability key/value store).

Do you have any idea on how to fetch such data (processing time of request, based on the last byte received preferably or on the response header receival time alternatively) ?