New upstream version 18.02
[deb_dpdk.git] / doc / guides / sample_app_ug / load_balancer.rst
1 ..  SPDX-License-Identifier: BSD-3-Clause
2     Copyright(c) 2010-2014 Intel Corporation.
3
4 Load Balancer Sample Application
5 ================================
6
7 The Load Balancer sample application demonstrates the concept of isolating the packet I/O task
8 from the application-specific workload.
9 Depending on the performance target,
10 a number of logical cores (lcores) are dedicated to handle the interaction with the NIC ports (I/O lcores),
11 while the rest of the lcores are dedicated to performing the application processing (worker lcores).
12 The worker lcores are totally oblivious to the intricacies of the packet I/O activity and
13 use the NIC-agnostic interface provided by software rings to exchange packets with the I/O cores.
14
15 Overview
16 --------
17
18 The architecture of the Load Balance application is presented in the following figure.
19
20 .. _figure_load_bal_app_arch:
21
22 .. figure:: img/load_bal_app_arch.*
23
24    Load Balancer Application Architecture
25
26
27 For the sake of simplicity, the diagram illustrates a specific case of two I/O RX and two I/O TX lcores off loading the packet I/O
28 overhead incurred by four NIC ports from four worker cores, with each I/O lcore handling RX/TX for two NIC ports.
29
30 I/O RX Logical Cores
31 ~~~~~~~~~~~~~~~~~~~~
32
33 Each I/O RX lcore performs packet RX from its assigned NIC RX rings and then distributes the received packets to the worker threads.
34 The application allows each I/O RX lcore to communicate with any of the worker threads,
35 therefore each (I/O RX lcore, worker lcore) pair is connected through a dedicated single producer - single consumer software ring.
36
37 The worker lcore to handle the current packet is determined by reading a predefined 1-byte field from the input packet:
38
39 worker_id = packet[load_balancing_field] % n_workers
40
41 Since all the packets that are part of the same traffic flow are expected to have the same value for the load balancing field,
42 this scheme also ensures that all the packets that are part of the same traffic flow are directed to the same worker lcore (flow affinity)
43 in the same order they enter the system (packet ordering).
44
45 I/O TX Logical Cores
46 ~~~~~~~~~~~~~~~~~~~~
47
48 Each I/O lcore owns the packet TX for a predefined set of NIC ports. To enable each worker thread to send packets to any NIC TX port,
49 the application creates a software ring for each (worker lcore, NIC TX port) pair,
50 with each I/O TX core handling those software rings that are associated with NIC ports that it handles.
51
52 Worker Logical Cores
53 ~~~~~~~~~~~~~~~~~~~~
54
55 Each worker lcore reads packets from its set of input software rings and
56 routes them to the NIC ports for transmission by dispatching them to output software rings.
57 The routing logic is LPM based, with all the worker threads sharing the same LPM rules.
58
59 Compiling the Application
60 -------------------------
61
62 To compile the sample application see :doc:`compiling`.
63
64 The application is located in the ``load_balancer`` sub-directory.
65
66 Running the Application
67 -----------------------
68
69 To successfully run the application,
70 the command line used to start the application has to be in sync with the traffic flows configured on the traffic generator side.
71
72 For examples of application command lines and traffic generator flows, please refer to the DPDK Test Report.
73 For more details on how to set up and run the sample applications provided with DPDK package,
74 please refer to the *DPDK Getting Started Guide*.
75
76 Explanation
77 -----------
78
79 Application Configuration
80 ~~~~~~~~~~~~~~~~~~~~~~~~~
81
82 The application run-time configuration is done through the application command line parameters.
83 Any parameter that is not specified as mandatory is optional,
84 with the default value hard-coded in the main.h header file from the application folder.
85
86 The list of application command line parameters is listed below:
87
88 #.  --rx "(PORT, QUEUE, LCORE), ...": The list of NIC RX ports and queues handled by the I/O RX lcores.
89     This parameter also implicitly defines the list of I/O RX lcores. This is a mandatory parameter.
90
91 #.  --tx "(PORT, LCORE), ... ": The list of NIC TX ports handled by the I/O TX lcores.
92     This parameter also implicitly defines the list of I/O TX lcores.
93     This is a mandatory parameter.
94
95 #.  --w "LCORE, ...": The list of the worker lcores. This is a mandatory parameter.
96
97 #.  --lpm "IP / PREFIX => PORT; ...": The list of LPM rules used by the worker lcores for packet forwarding.
98     This is a mandatory parameter.
99
100 #.  --rsz "A, B, C, D": Ring sizes:
101
102     #.  A = The size (in number of buffer descriptors) of each of the NIC RX rings read by the I/O RX lcores.
103
104     #.  B = The size (in number of elements) of each of the software rings used by the I/O RX lcores to send packets to worker lcores.
105
106     #.  C = The size (in number of elements) of each of the software rings used by the worker lcores to send packets to I/O TX lcores.
107
108     #.  D = The size (in number of buffer descriptors) of each of the NIC TX rings written by I/O TX lcores.
109
110 #.  --bsz "(A, B), (C, D), (E, F)": Burst sizes:
111
112     #.  A = The I/O RX lcore read burst size from NIC RX.
113
114     #.  B = The I/O RX lcore write burst size to the output software rings.
115
116     #.  C = The worker lcore read burst size from the input software rings.
117
118     #.  D = The worker lcore write burst size to the output software rings.
119
120     #.  E = The I/O TX lcore read burst size from the input software rings.
121
122     #.  F = The I/O TX lcore write burst size to the NIC TX.
123
124 #.  --pos-lb POS: The position of the 1-byte field within the input packet used by the I/O RX lcores
125     to identify the worker lcore for the current packet.
126     This field needs to be within the first 64 bytes of the input packet.
127
128 The infrastructure of software rings connecting I/O lcores and worker lcores is built by the application
129 as a result of the application configuration provided by the user through the application command line parameters.
130
131 A specific lcore performing the I/O RX role for a specific set of NIC ports can also perform the I/O TX role
132 for the same or a different set of NIC ports.
133 A specific lcore cannot perform both the I/O role (either RX or TX) and the worker role during the same session.
134
135 Example:
136
137 .. code-block:: console
138
139     ./load_balancer -l 3-7 -n 4 -- --rx "(0,0,3),(1,0,3)" --tx "(0,3),(1,3)" --w "4,5,6,7" --lpm "1.0.0.0/24=>0; 1.0.1.0/24=>1;" --pos-lb 29
140
141 There is a single I/O lcore (lcore 3) that handles RX and TX for two NIC ports (ports 0 and 1) that
142 handles packets to/from four worker lcores (lcores 4, 5, 6 and 7) that
143 are assigned worker IDs 0 to 3 (worker ID for lcore 4 is 0, for lcore 5 is 1, for lcore 6 is 2 and for lcore 7 is 3).
144
145 Assuming that all the input packets are IPv4 packets with no VLAN label and the source IP address of the current packet is A.B.C.D,
146 the worker lcore for the current packet is determined by byte D (which is byte 29).
147 There are two LPM rules that are used by each worker lcore to route packets to the output NIC ports.
148
149 The following table illustrates the packet flow through the system for several possible traffic flows:
150
151 +------------+----------------+-----------------+------------------------------+--------------+
152 | **Flow #** | **Source**     | **Destination** | **Worker ID (Worker lcore)** | **Output**   |
153 |            | **IP Address** | **IP Address**  |                              | **NIC Port** |
154 |            |                |                 |                              |              |
155 +============+================+=================+==============================+==============+
156 | 1          | 0.0.0.0        | 1.0.0.1         | 0 (4)                        | 0            |
157 |            |                |                 |                              |              |
158 +------------+----------------+-----------------+------------------------------+--------------+
159 | 2          | 0.0.0.1        | 1.0.1.2         | 1 (5)                        | 1            |
160 |            |                |                 |                              |              |
161 +------------+----------------+-----------------+------------------------------+--------------+
162 | 3          | 0.0.0.14       | 1.0.0.3         | 2 (6)                        | 0            |
163 |            |                |                 |                              |              |
164 +------------+----------------+-----------------+------------------------------+--------------+
165 | 4          | 0.0.0.15       | 1.0.1.4         | 3 (7)                        | 1            |
166 |            |                |                 |                              |              |
167 +------------+----------------+-----------------+------------------------------+--------------+
168
169 NUMA Support
170 ~~~~~~~~~~~~
171
172 The application has built-in performance enhancements for the NUMA case:
173
174 #.  One buffer pool per each CPU socket.
175
176 #.  One LPM table per each CPU socket.
177
178 #.  Memory for the NIC RX or TX rings is allocated on the same socket with the lcore handling the respective ring.
179
180 In the case where multiple CPU sockets are used in the system,
181 it is recommended to enable at least one lcore to fulfill the I/O role for the NIC ports that
182 are directly attached to that CPU socket through the PCI Express* bus.
183 It is always recommended to handle the packet I/O with lcores from the same CPU socket as the NICs.
184
185 Depending on whether the I/O RX lcore (same CPU socket as NIC RX),
186 the worker lcore and the I/O TX lcore (same CPU socket as NIC TX) handling a specific input packet,
187 are on the same or different CPU sockets, the following run-time scenarios are possible:
188
189 #.  AAA: The packet is received, processed and transmitted without going across CPU sockets.
190
191 #.  AAB: The packet is received and processed on socket A,
192     but as it has to be transmitted on a NIC port connected to socket B,
193     the packet is sent to socket B through software rings.
194
195 #.  ABB: The packet is received on socket A, but as it has to be processed by a worker lcore on socket B,
196     the packet is sent to socket B through software rings.
197     The packet is transmitted by a NIC port connected to the same CPU socket as the worker lcore that processed it.
198
199 #.  ABC: The packet is received on socket A, it is processed by an lcore on socket B,
200     then it has to be transmitted out by a NIC connected to socket C.
201     The performance price for crossing the CPU socket boundary is paid twice for this packet.