title: Using leastconn with weights in HAProxy
body: <p>I would like to be able to use leastconn in HAProxy while still having different weights on backend hosts.</p>
  
  <p>Context: I have ~100 backend hosts that are being accessed by ~2000 front end hosts. All backend hosts process requests the same way (no faster hosts), however some backend hosts can process more requests (they have more cores). The problem is that I cannot use round robin as it is, because sometimes some backend host get stuck with long connections, and with round robin it will keep receiving more and more front end connections, which it never recovers from. In the current situation, I use leastconn, so all backend hosts process ~ the same number of requests, but I don't optimize their CPU usage.</p>
  
  <p>What I would like to achieve is to be able to still use leastconn, but allowing more connections to certain hosts. For example if we have only 2 hosts: host A with 1 core and host B with 2 cores. At any moment, I would like HAProxy to decide which host to pick based on:</p>
  
  <blockquote>
    <p>x= num_current_connections_A, y = 0.5*num_current_connections_B. If x&lt;=y go to A, otherwise go to B.</p>
  </blockquote>
  
  <p>I read this post which states the same issue, but no answer really solved my problem: <a href="http://haproxy.formilux.narkive.com/I6hSmq8H/balance-leastconn-does-not-honor-weight" rel="nofollow noreferrer">http://haproxy.formilux.narkive.com/I6hSmq8H/balance-leastconn-does-not-honor-weight</a></p>
  
  <p>Thank you</p>