Actions

Adding Load Sharing to Routing Script: Difference between revisions

(Added note on Load sharing script)
mNo edit summary
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
This shows how to add Priority and Load sharing to any Routing scripts. This is a powerful script that allows to regroup Routes of the same kind, distribute load among them and prioritize one group versus another.  Alternatively, you can do the same on NAPs. You will use two additional parameters in the routes: '''group''' and '''weight'''.<br />
{{DISPLAYTITLE:Adding Load Sharing to a Routing Script}}
'''group''' serves as two purpose:
 
# priority: a lower value will have higher priority 
This article show you how to integrate a routing script filter that sorts matching routes by priority and weight (weight is used for load-sharing when multiple routes have the same priority).
# matching routes of the same group will load share according to the weight parameter
 
'''weight''' will load share calls among matching routes of the same group
 
<br>
Once ordered, the routes will be used, one after the other until a route is working (according to [[Route_retry|Route Retry]] parameters).


'''NOTE: starting from version 3.0.80 this script is installed by default (only for new installations, or a fresh routing script)'''
'''NOTE: starting from version 3.0.80 this script is installed by default''' (only for new installations, or a fresh routing script)


== Setting up Filter Scripts<br>  ==
== Setting up Filter Scripts<br>  ==
Line 15: Line 15:
<pre>Gateway -&gt; Routing scripts -&gt; Example Scripts -&gt; simple_routing.rb [Edit]
<pre>Gateway -&gt; Routing scripts -&gt; Example Scripts -&gt; simple_routing.rb [Edit]
</pre>  
</pre>  
Three things need to be added. At the start of the script:<br>  
 
<pre>require 'nap_group_weight_load_balancer'
Three things must be added. At the start of the script:<br>  
</pre>  
1.
<pre>require 'priority_and_weight_load_balancer' unless defined?(PriorityAndWeightLoadBalancer)</pre>  
 
2.
In the main class:<br>  
In the main class:<br>  
<pre>include NapGroupAndWeightLoadBalancer
<pre>include PriorityAndWeightLoadBalancer
</pre>  
</pre>  
<pre>after_filter&nbsp;:method =&gt;&nbsp;:filter_by_group_and_weight
 
3.
<pre>
  after_filter :method => :filter_by_priority_and_weight,
              :weight_by                => :call_attempts,
              :default_load_share_mode  => :alternate_backup,
              :max_priority_delta        => -1
</pre>  
</pre>  
<br>  
<br>  
The final script will look like this:
 
The final script will look like this (with possibly other filters also included):
 
<pre>
<pre>
require 'base_routing'
require 'base_routing'
require 'nap_group_weight_load_balancer'
require 'priority_and_weight_load_balancer' unless defined?(PriorityAndWeightLoadBalancer)


class SimpleRouting < BaseRouting
class SimpleRouting < BaseRouting
   include NapGroupAndWeightLoadBalancer
   include PriorityAndWeightLoadBalancer
    
    
   route_match :call_field_name => :called
   route_match :call_field_name => :called
Line 40: Line 51:
   route_remap :call_field_name => :nap, :route_field_name => :remapped_nap
   route_remap :call_field_name => :nap, :route_field_name => :remapped_nap
    
    
   after_filter&nbsp;:method =&gt;&nbsp;:filter_by_group_and_weight
   after_filter :method => :filter_by_priority_and_weight,
 
              :weight_by                => :call_attempts,
              :default_load_share_mode  => :alternate_backup,
              :max_priority_delta        => -1
end
end
</pre>
</pre>


== Adding New Custom Variables <br>  ==
== Adding New Custom Variables <br>  ==
You need to add two custom columns to use this script. There is a default value creates and it can be changed in each route afterwards.  
You need to add two custom columns to use this script. There is a default value and it can be changed in each route afterwards.  
 
<pre>Gateway -&gt; Routes -&gt; Create New Route Column</pre>
<pre>Gateway -&gt; Routes -&gt; Create New Route Column</pre>
'''Name''': group<br>'''Type attributes''': integer<br>'''Default''': 10 <br>
'''Name''': priority<br>'''Type attributes''': integer<br>'''Default''': 10 <br>


<pre>Gateway -&gt; Routes -&gt; Create New Route Column</pre>
<pre>Gateway -&gt; Routes -&gt; Create New Route Column</pre>
'''Name''': weight<br>'''Type attributes''': integer<br>'''Default''': 100 <br>
'''Name''': weight<br>'''Type attributes''': integer<br>'''Default''': 100 <br>

Latest revision as of 10:37, 13 June 2022


This article show you how to integrate a routing script filter that sorts matching routes by priority and weight (weight is used for load-sharing when multiple routes have the same priority).


Once ordered, the routes will be used, one after the other until a route is working (according to Route Retry parameters).

NOTE: starting from version 3.0.80 this script is installed by default (only for new installations, or a fresh routing script)

Setting up Filter Scripts

To setup a Filter, the main script needs to be modified. The main script can be either simple_routing.rb, or any other script.

First, go to the routing script section of the Web portal

Gateway -> Routing scripts -> Example Scripts -> simple_routing.rb [Edit]

Three things must be added. At the start of the script:
1.

require 'priority_and_weight_load_balancer' unless defined?(PriorityAndWeightLoadBalancer)

2. In the main class:

include PriorityAndWeightLoadBalancer

3.

  after_filter :method => :filter_by_priority_and_weight,
               :weight_by                 => :call_attempts,
               :default_load_share_mode   => :alternate_backup,
               :max_priority_delta        => -1


The final script will look like this (with possibly other filters also included):

require 'base_routing'
require 'priority_and_weight_load_balancer' unless defined?(PriorityAndWeightLoadBalancer)

class SimpleRouting < BaseRouting
  include PriorityAndWeightLoadBalancer
  
  route_match :call_field_name => :called
  route_match :call_field_name => :calling
  route_match :call_field_name => :nap
  route_match :method => :match_nap_availability
  route_remap :call_field_name => :called, :route_field_name => :remapped_called
  route_remap :call_field_name => :calling, :route_field_name => :remapped_calling
  route_remap :call_field_name => :nap, :route_field_name => :remapped_nap
  
  after_filter :method => :filter_by_priority_and_weight,
               :weight_by                 => :call_attempts,
               :default_load_share_mode   => :alternate_backup,
               :max_priority_delta        => -1
end

Adding New Custom Variables

You need to add two custom columns to use this script. There is a default value and it can be changed in each route afterwards.

Gateway -> Routes -> Create New Route Column

Name: priority
Type attributes: integer
Default: 10

Gateway -> Routes -> Create New Route Column

Name: weight
Type attributes: integer
Default: 100