net/haproxy: add support for the random balancing algorithm

This commit is contained in:
Frank Wall 2019-09-15 22:43:48 +02:00
parent b51249531d
commit 1603f9a21b
3 changed files with 20 additions and 0 deletions

View file

@ -31,6 +31,13 @@
<help><![CDATA[Define the load balancing algorithm to be used in a Backend Pool. See the <a target="_blank" href="http://cbonte.github.io/haproxy-dconv/2.0/configuration.html#balance">HAProxy documentation</a> for a full description.]]></help>
<hint>Choose a load balancing algorithm.</hint>
</field>
<field>
<id>backend.random_draws</id>
<label>Random Draws</label>
<type>text</type>
<help><![CDATA[When using the Random Balancing Algorithm, this value indicates the number of draws before selecting the least loaded of these servers.]]></help>
<advanced>true</advanced>
</field>
<field>
<id>backend.proxyProtocol</id>
<label>Proxy Protocol</label>

View file

@ -763,8 +763,16 @@
<static-rr>Static Round Robin</static-rr>
<leastconn>Least Connections</leastconn>
<uri>URI Hash (only HTTP mode)</uri>
<random>Random Algorithm</random>
</OptionValues>
</algorithm>
<random_draws type="IntegerField">
<Required>Y</Required>
<default>2</default>
<MinimumValue>2</MinimumValue>
<MaximumValue>1000</MaximumValue>
<ValidationMessage>Please specify a value between 2 and 1000.</ValidationMessage>
</random_draws>
<proxyProtocol type="OptionField">
<Required>N</Required>
<OptionValues>

View file

@ -1269,7 +1269,12 @@ backend {{backend.name}}
{# # Hence we can't automatically set the mode and thus need a #}
{# # (redundant) GUI option for this. #}
mode {{backend.mode}}
{# # balancing algorithm #}
{% if backend.algorithm|default("") == 'random' %}
balance {{backend.algorithm}}({{backend.random_draws}})
{% else %}
balance {{backend.algorithm}}
{% endif %}
{# # call macro to evaluate stickiness config #}
{{ StickTableConfig(backend,true) }}
# tuning options