h1. Percentage routing {{>toc}} *Percentage routing* - the possibility to control a _traffic portion_, which is routed to particular terminator. h2. Example Let's assume, you have 2 terminators: Terminator1 and Terminator2. You want to spread the traffic this way: * 70% of calls go to Terminator1 * 30% of calls go to Terminator2 To configure the scheme above, you should specify the parameter _traffic portion_ 70 for the route to Terminator1 and 30 for the route to Terminator2. h2. Implementation This feature is implemented in system in the following way. 1. After routing table is built, the system sums the _traffic portion_ for all the routes, on which it's specified. In our example _sum_ = 70 + 30 = 100. Using the _sum_ value the system calculates the actual traffic portions for the routes using the next formula: _actual portion_ = _configured portion_ * 100 / _sum_. For our example the _actual portion_ matches the _configured portion_ (70% and 30%). In case if _traffic portion_ would be configured as 1 and 4, they'd be calculated as 20% and 80%. 2. The system generates the _probability distribution_ for the routes with the _traffic portion_ configured, using their _actual portion_. For the example above the distribution will be as follows: !perc_routing1.gif! 3. System generates random number _rand_ from 0 to 100. 4. System puts the _rand_ onto the _probability distribution_ and checks which route matches it. 5. System leaves only the matching route in the routing table and excludes all the other routes with _traffic portion_ set. As far as during each routing table generation _rand_ is generated into different values, randomly, the routes are chosen randomly. The bigger the area which is occupied by route on the _probability distribution_ - the more often the route is chosen. h2. Interaction with the system of static routing and hunting This feature works together with the system of static routing and [[Hunting]]. Thus, routing table could contain routes either with configured _traffic portion_, or without it. In this case, percentage routing will be applied only to those routes, which have this option configured. Other routes will be present in routing table as usual and won't be excluded. This allows to specify backup routes, which will be used if the routes with percentage routing are unable to connect a call. h2. Configuration +Traffic portion+ is configured in the following menus: * [[Route classes]] * [[Routes]] h2. Checking You can check if the configuration is correct by performing [[Check hunting]]. By refreshing the web page with results - routing table - you will see a different picture each time. For example, for the example above, after refreshing the page 10 times, you will see ~7 times one order of routes and ~3 times - different. *Please notice!* Traffic portions are followed only approximately. [[Процентная маршрутизация|Русский перевод]]