How Load Balancing Works?
What will we learn in this article?
- How Load Balancing Works on a Cisco router when CEF is disabled.
- How Load Balancing Works on a Cisco router when CEF is enabled.
- How the load is distributed among various equal cost path interfaces of a router.
So, let's continue..
Load balancing is a standard functionality of the Cisco IOS and is available across all router platforms. It allows a router to use multiple paths to a destination when forwarding packets. If the router has multiple equal cost/metric paths to a destination prefix, load-balancing is automatically enabled because it is inherent to the forwarding process in the router. All IP routing protocols (RIPv1/v2, EIGRP, OSPF, BGP) are capable of load balancing on maximum 6 equal-cost paths. By default, all IP protocols can load balance on to 4 paths, with an exception of BGP where only one entry is default.
IGRP and EIGRP protocols are exceptional IGPs that also support unequal cost path load-balancing using Variance option.
To check equal cost routes/path on a router, we an use 'show ip route' command.
With regards to the topology below, router R1 is running RIPv2 and has 3 equal cost paths in its routing table for destination 192.9.1.5/32 as shown in the output below.
We can also see that there is an Aestrick(*) in front of last route which learned via R2 via F1/0.
R1#show ip route 192.9.1.5
Routing entry for 192.9.1.5/32
Known via "rip", distance 120, metric 2
Redistributing via rip
Last update from 10.10.13.3 on FastEthernet1/1, 00:00:12 ago
Routing Descriptor Blocks:
10.10.14.4, from 10.10.14.4, 00:00:25 ago, via FastEthernet2/0
Route metric is 2, traffic share count is 1
10.10.13.3, from 10.10.13.3, 00:00:12 ago, via FastEthernet1/1
Route metric is 2, traffic share count is 1
* 10.10.12.2, from 10.10.12.2, 00:00:13 ago, via FastEthernet1/0
Route metric is 2, traffic share count is 1
Aestrick(*) sign denotes the active route that will be used to carry new or next traffic.
There are 2 types of load-balancing.
For example, for process-switching(per packet), load balancing happens on a per-packet basis and the asterisk (*) points to the outgoing interface over which the next packet is sent.
On the other hand, for fast-switching(per destination), load balancing happens on per-destination basis and the asterisk (*) points to the interface over which the next destination-based flow/traffic is sent.
The position of the asterisk (*) keeps rotating among the equal cost paths each time a packet/flow is served.
With per-destination or per flow type of load balancing, the router distributes the packets based on the destination address. Given multiple paths to the same network, all packets for destination subnet X go over the first path, all packets for destination subnet Y go over the second path, and so on. The router performs internal hash computation to decide on which link out of available equal cost paths will be chosen to send the traffic. For example:
For sending traffic to destination 192.9.1.5/32(FTP flow) - Router chose outgoing interface F1/0
For sending traffic to destination 192.9.1.6/32(HTTP flow) - Router chose outgoing interface F1/1
For sending traffic to destination 192.9.1.7/32(SNMP flow - Router chose outgoing interface F2/0
For sending traffic to destination 192.9.1.8/32(Telnet flow) - Router chose outgoing interface F1/1
R1# sh ip int f1/0 | i fast
IP fast switching is enabled
IP multicast fast switching is enabled
IP multicast distributed fast switching is disabled
To enable per packet load balancing, you can disable the fast-switching. That will enable process switching (per packet load balancing).
R1#show ip route 192.9.1.5
Routing entry for 192.9.1.5/32
Known via "rip", distance 120, metric 2
Redistributing via rip
Last update from 10.10.13.3 on FastEthernet1/1, 00:00:12 ago
Routing Descriptor Blocks:
10.10.14.4, from 10.10.14.4, 00:00:25 ago, via FastEthernet2/0
Route metric is 2, traffic share count is 1
10.10.13.3, from 10.10.13.3, 00:00:12 ago, via FastEthernet1/1
Route metric is 2, traffic share count is 1
* 10.10.12.2, from 10.10.12.2, 00:00:13 ago, via FastEthernet1/0
Route metric is 2, traffic share count is 1
Aestrick(*) sign denotes the active route that will be used to carry new or next traffic.
There are 2 types of load-balancing.
- Per Destination (When the data/traffic is fast-switched)
- Per Packet (When the data/traffic is process switched)
For example, for process-switching(per packet), load balancing happens on a per-packet basis and the asterisk (*) points to the outgoing interface over which the next packet is sent.
On the other hand, for fast-switching(per destination), load balancing happens on per-destination basis and the asterisk (*) points to the interface over which the next destination-based flow/traffic is sent.
The position of the asterisk (*) keeps rotating among the equal cost paths each time a packet/flow is served.
With per-destination or per flow type of load balancing, the router distributes the packets based on the destination address. Given multiple paths to the same network, all packets for destination subnet X go over the first path, all packets for destination subnet Y go over the second path, and so on. The router performs internal hash computation to decide on which link out of available equal cost paths will be chosen to send the traffic. For example:
For sending traffic to destination 192.9.1.5/32(FTP flow) - Router chose outgoing interface F1/0
For sending traffic to destination 192.9.1.6/32(HTTP flow) - Router chose outgoing interface F1/1
For sending traffic to destination 192.9.1.7/32(SNMP flow - Router chose outgoing interface F2/0
For sending traffic to destination 192.9.1.8/32(Telnet flow) - Router chose outgoing interface F1/1
With per destination type of load balancing we could see unequal usage of link bandwidth. What this means is that interface F1/0 could be 70% utilized in terms of WAN bandwidth, interface F1/1 could be 50% utilized, and interface F2/0 could be 20% utilized.
Per-packet load-balancing means that the router sends one packet for destination subnet X over the first path, the second packet for (the same) destination subnet X over the second path, and so on. Per-packet load balancing guarantees equal load across all links. However, there is a possibility that the packets may arrive out of order at the destination because differential delay which may exist within the network. Therefore, per-packet load balancing is not well suited for slow speed links.
By default, on most Cisco routers, fast switching is enabled under interfaces. This is a demand caching scheme that does per-destination load-balancing.
Per-packet load-balancing means that the router sends one packet for destination subnet X over the first path, the second packet for (the same) destination subnet X over the second path, and so on. Per-packet load balancing guarantees equal load across all links. However, there is a possibility that the packets may arrive out of order at the destination because differential delay which may exist within the network. Therefore, per-packet load balancing is not well suited for slow speed links.
By default, on most Cisco routers, fast switching is enabled under interfaces. This is a demand caching scheme that does per-destination load-balancing.
R1# sh ip int f1/0 | i fast
IP fast switching is enabled
IP multicast fast switching is enabled
IP multicast distributed fast switching is disabled
To enable per packet load balancing, you can disable the fast-switching. That will enable process switching (per packet load balancing).
R1(config)# interface f1/0
R1(config-if)# no ip route-cache
Once you enable per packet load balancing, the Router's CPU will look at or process every single packet and load balances on the number of paths/routes in the routing table for the destination. This can overload the CPU of a low end router leading to crash.
To re-enable fast switching, use no ip route-cache command.
R1(config)# interface f1/0
R1(config-if)# ip route-cache
How Load Balancing Works using CEF?
The concepts we have learned so far are true until we enable Cisco Express Forwarding(CEF). Cisco Express Forwarding is an advanced Layer 3 IP switching technology. It optimizes network performance and scalability for all kinds of networks.
To check if CEF is enabled or not on the router and if not enabled, how to enable CEF on router, below commands are useful.
R1#sh ip cef
%IPv4 CEF not running
R1#conf t
R1(config)#ip cef
While CEF is enabled, per-destination is the default load balancing mechanism followed on the Cisco router. Now a days, CEF is enabled by default on all Cisco routers.
While CEF is enabled, per-destination is the default load balancing mechanism followed on the Cisco router. Now a days, CEF is enabled by default on all Cisco routers.
R1#sh cef interface f1/0
FastEthernet1/0 is up (if_number 3)
Corresponding hwidb fast_if_number 3
Corresponding hwidb firstsw->if_number 3
Internet address is 10.10.12.1/24
ICMP redirects are always sent
Per packet load-sharing is disabled
IP unicast RPF check is disabled
Input features: Ingress-NetFlow
Output features: Post-Ingress-NetFlow
IP policy routing is disabled
BGP based policy accounting on input is disabled
BGP based policy accounting on output is disabled
Hardware idb is FastEthernet1/0
Fast switching type 1, interface type 18
IP CEF switching enabled
IP CEF switching turbo vector
IP CEF turbo switching turbo vector
IP prefix lookup IPv4 mtrie 8-8-8-8 optimized
Input fast flags 0x0, Output fast flags 0x0
ifindex 3(3)
Slot Slot unit 0 VC -1
IP MTU 1500
FastEthernet1/0 is up (if_number 3)
Corresponding hwidb fast_if_number 3
Corresponding hwidb firstsw->if_number 3
Internet address is 10.10.12.1/24
ICMP redirects are always sent
Per packet load-sharing is disabled
IP unicast RPF check is disabled
Input features: Ingress-NetFlow
Output features: Post-Ingress-NetFlow
IP policy routing is disabled
BGP based policy accounting on input is disabled
BGP based policy accounting on output is disabled
Hardware idb is FastEthernet1/0
Fast switching type 1, interface type 18
IP CEF switching enabled
IP CEF switching turbo vector
IP CEF turbo switching turbo vector
IP prefix lookup IPv4 mtrie 8-8-8-8 optimized
Input fast flags 0x0, Output fast flags 0x0
ifindex 3(3)
Slot Slot unit 0 VC -1
IP MTU 1500
To disable per-destination switching mechanism of load balancing or to enable per-packet load balancing mechanism, you can use below command.
R1#conf t
R1(config-if)#ip load-sharing per-packet
R1(config-if)#ip load-sharing per-packet
R1#sh cef interface f1/0
FastEthernet1/0 is up (if_number 3)
Corresponding hwidb fast_if_number 3
Corresponding hwidb firstsw->if_number 3
Internet address is 10.10.12.1/24
ICMP redirects are always sent
Per packet load-sharing is enabled
IP unicast RPF check is disabled
Input features: Ingress-NetFlow
Output features: Post-Ingress-NetFlow
IP policy routing is disabled
BGP based policy accounting on input is disabled
BGP based policy accounting on output is disabled
Hardware idb is FastEthernet1/0
Fast switching type 1, interface type 18
IP CEF switching enabled
IP CEF switching turbo vector
IP CEF turbo switching turbo vector
IP prefix lookup IPv4 mtrie 8-8-8-8 optimized
Input fast flags 0x0, Output fast flags 0x0
ifindex 3(3)
Slot Slot unit 0 VC -1
IP MTU 1500
FastEthernet1/0 is up (if_number 3)
Corresponding hwidb fast_if_number 3
Corresponding hwidb firstsw->if_number 3
Internet address is 10.10.12.1/24
ICMP redirects are always sent
Per packet load-sharing is enabled
IP unicast RPF check is disabled
Input features: Ingress-NetFlow
Output features: Post-Ingress-NetFlow
IP policy routing is disabled
BGP based policy accounting on input is disabled
BGP based policy accounting on output is disabled
Hardware idb is FastEthernet1/0
Fast switching type 1, interface type 18
IP CEF switching enabled
IP CEF switching turbo vector
IP CEF turbo switching turbo vector
IP prefix lookup IPv4 mtrie 8-8-8-8 optimized
Input fast flags 0x0, Output fast flags 0x0
ifindex 3(3)
Slot Slot unit 0 VC -1
IP MTU 1500
To re-enable per-destination load balancing use below command
R1(config)#int f1/0
R1(config-if)#ip load-sharing per-destination
R1(config-if)#ip load-sharing per-destination
If you understood the concept and liked this article, kindly share it with your friends.
0 Comments
Please do not enter any spam link in the comment box.