Improve soak graphs and content
[csit.git] / docs / report / introduction / methodology_data_plane_throughput / methodology_plrsearch.rst
1 .. _PLRsearch:
2
3 PLRsearch
4 ^^^^^^^^^
5
6 Motivation for PLRsearch
7 ~~~~~~~~~~~~~~~~~~~~~~~~
8
9 Network providers are interested in throughput a system can sustain.
10
11 `RFC 2544`_ assumes loss ratio is given by a deterministic function of
12 offered load. But NFV software systems are not deterministic enough.
13 This makes deterministic algorithms (such as `binary search`_ per RFC 2544
14 and MLRsearch with single trial) to return results,
15 which when repeated show relatively high standard deviation,
16 thus making it harder to tell what "the throughput" actually is.
17
18 We need another algorithm, which takes this indeterminism into account.
19
20 Generic algorithm
21 ~~~~~~~~~~~~~~~~~
22
23 Detailed description of the PLRsearch algorithm is included in the IETF
24 draft `draft-vpolak-bmwg-plrsearch-01`_ that is in the process
25 of being standardized in the IETF Benchmarking Methodology Working Group (BMWG).
26
27 Terms
28 -----
29
30 The rest of this page assumes the reader is familiar with the following terms
31 defined in the IETF draft:
32
33 + Target Loss Ratio
34 + Critical Load
35 + Offered Load regions
36
37   + Zero Loss Region
38   + Non-Deterministic Region
39   + Guaranteed Loss Region
40
41 + Fitting Function
42
43   + Stretch Function
44   + Erf Function
45
46 + Bayesian Inference
47
48   + Prior distribution
49   + Posterior Distribution
50
51 + Numeric Integration
52
53   + Monte Carlo
54   + Importance Sampling
55
56 FD.io CSIT Implementation Specifics
57 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
58
59 The search receives min_rate and max_rate values, to avoid measurements
60 at offered loads not supporeted by the traffic generator.
61
62 The implemented tests cases use bidirectional traffic.
63 The algorithm stores each rate as bidirectional rate (internally,
64 the algorithm is agnostic to flows and directions,
65 it only cares about overall counts of packets sent and packets lost),
66 but debug output from traffic generator lists unidirectional values.
67
68 Measurement delay
69 `````````````````
70
71 In a sample implemenation in FD.io CSIT project, there is roughly 0.5
72 second delay between trials due to restrictons imposed by packet traffic
73 generator in use (T-Rex).
74
75 As measurements results come in, posterior distribution computation takes
76 more time (per sample), although there is a considerable constant part
77 (mostly for inverting the fitting functions).
78
79 Also, the integrator needs a fair amount of samples to reach the region
80 the posterior distribution is concentrated at.
81
82 And of course, speed of the integrator depends on computing power
83 of the CPU the algorithm is able to use.
84
85 All those timing related effects are addressed by arithmetically increasing
86 trial durations with configurable coefficients
87 (currently 5.1 seconds for the first trial,
88 each subsequent trial being 0.1 second longer).
89
90 Rounding errors and underflows
91 ``````````````````````````````
92
93 In order to avoid them, the current implementation tracks natural logarithm
94 (instead of the original quantity) for any quantity which is never negative.
95 Logarithm of zero is minus infinity (not supported by Python),
96 so special value "None" is used instead.
97 Specific functions for frequent operations (such as "logarithm
98 of sum of exponentials") are defined to handle None correctly.
99
100 Fitting functions
101 `````````````````
102
103 Current implementation uses two fitting functions.
104 In general, their estimates for critical rate differ,
105 which adds a simple source of systematic error,
106 on top of randomness error reported by integrator.
107 Otherwise the reported stdev of critical rate estimate
108 is unrealistically low.
109
110 Both functions are not only increasing, but also convex
111 (meaning the rate of increase is also increasing).
112
113 Both fitting functions have several mathematically equivalent formulas,
114 each can lead to an overflow or underflow in different places.
115 Overflows can be eliminated by using different exact formulas
116 for different argument ranges.
117 Underflows can be avoided by using approximate formulas
118 in affected argument ranges, such ranges have their own formulas to compute.
119 At the end, both fitting function implementations
120 contain multiple "if" branches, discontinuities are a possibility
121 at range boundaries.
122
123 Prior distributions
124 ```````````````````
125
126 The numeric integrator expects all the parameters to be distributed
127 (independently and) uniformly on an interval (-1, 1).
128
129 As both "mrr" and "spread" parameters are positive and not not dimensionless,
130 a transformation is needed. Dimentionality is inherited from max_rate value.
131
132 The "mrr" parameter follows a `Lomax distribution`_
133 with alpha equal to one, but shifted so that mrr is always greater than 1
134 packet per second.
135
136 The "stretch" parameter is generated simply as the "mrr" value
137 raised to a random power between zero and one;
138 thus it follows a `reciprocal distribution`_.
139
140 Integrator
141 ``````````
142
143 After few measurements, the posterior distribution of fitting function
144 arguments gets quite concentrated into a small area.
145 The integrator is using `Monte Carlo`_ with `importance sampling`_
146 where the biased distribution is `bivariate Gaussian`_ distribution,
147 with deliberately larger variance.
148 If the generated sample falls outside (-1, 1) interval,
149 another sample is generated.
150
151 The center and the covariance matrix for the biased distribution
152 is based on the first and second moments of samples seen so far
153 (within the computation), with the following additional features
154 designed to avoid hyper-focused distributions.
155
156 Each computation starts with the biased distribution inherited
157 from the previous computation (zero point and unit covariance matrix
158 is used in the first computation), but the overal weight of the data
159 is set to the weight of the first sample of the computation.
160 Also, the center is set to the first sample point.
161 When additional samples come, their weight (including the importance correction)
162 is compared to the weight of data seen so far (within the computation).
163 If the new sample is more than one e-fold more impactful, both weight values
164 (for data so far and for the new sample) are set to (geometric) average
165 of the two weights. Finally, the actual sample generator uses covariance matrix
166 scaled up by a configurable factor (8.0 by default).
167
168 This combination showed the best behavior, as the integrator usually follows
169 two phases. First phase (where inherited biased distribution
170 or single big samples are dominating) is mainly important
171 for locating the new area the posterior distribution is concentrated at.
172 The second phase (dominated by whole sample population)
173 is actually relevant for the critical rate estimation.
174
175 Offered load selection
176 ``````````````````````
177
178 First two measurements are hardcoded to happen at the middle of rate interval
179 and at max_rate. Next two measurements follow MRR-like logic,
180 offered load is decreased so that it would reach target loss ratio
181 if offered load decrease lead to equal decrease of loss rate.
182
183 The rest of measurements alternate between erf and stretch estimate average.
184 There is one workaround implemented, aimed at reducing the number of consequent
185 zero loss measurements (per fitting function). The workaround first stores
186 every measurement result which loss ratio was the targed loss ratio or higher.
187 Sorted list (called lossy loads) of such results is maintained.
188
189 When a sequence of one or more zero loss measurement results is encountered,
190 a smallest of lossy loads is drained from the list.
191 If the estimate average is smaller than the drained value,
192 a weighted average of this estimate and the drained value is used
193 as the next offered load. The weight of the estimate decreases exponentially
194 with the length of consecutive zero loss results.
195
196 This behavior helps the algorithm with convergence speed,
197 as it does not need so many zero loss result to get near critical region.
198 Using the smallest (not srained yet) of lossy loads makes it sure
199 the new offered load is unlikely to result in big loss region.
200 Draining even if the estimate is large enough helps to discard
201 early measurements when loss hapened at too low offered load.
202 Current implementation adds 4 copies of lossy loads and drains 3 of them,
203 which leads to fairly stable behavior even for somewhat inconsistent SUTs.
204
205 Caveats
206 ```````
207
208 As high loss count measurements add many bits of information,
209 they need a large amount of small loss count measurements to balance them,
210 making the algorithm converge quite slowly. Typically, this happens
211 when few initial measurements suggest spread way bigger then later measurements.
212 The workaround in offered load selection helps,
213 but more intelligent workarounds could get faster convergence still.
214
215 Some systems evidently do not follow the assumption of repeated measurements
216 having the same average loss rate (when offered load is the same).
217 The idea of estimating the trend is not implemented at all,
218 as the observed trends have varied characteristics.
219
220 Probably, using a more realistic fitting functions
221 will give better estimates than trend analysis.
222
223 Graphical examples
224 ``````````````````
225
226 The following pictures show the upper (red) and lower (blue) bound,
227 as well as average of stretch (pink) and erf (light green) estimate,
228 and offered load chosen (grey), as computed by PLRsearch,
229 after each trial measurement within the 2 hour duration of a test run.
230
231 Both graphs are focusing on later estimates. Estimates computed from
232 few initial measurements are wildly off the y-axis range shown.
233
234 L2 patch
235 --------
236
237 This test case shows quite narrow critical region. Both fitting functions
238 give similar estimates, the graph shows the randomness of measurements,
239 and a trend. Both fitting functions seem to be fairly precise in estimating
240 the critical rate, but the performance of the system decreases slightly
241 over time. The final estimated interval is fairly narrow,
242 but corresponds to the measured results.
243
244 .. only:: latex
245
246     .. raw:: latex
247
248         \begin{figure}[H]
249             \centering
250                 \graphicspath{{../_tmp/src/introduction/methodology_data_plane_throughput/}}
251                 \includegraphics[width=0.90\textwidth]{PLR_patch}
252                 \label{fig:PLR_patch}
253         \end{figure}
254
255 .. only:: html
256
257     .. figure:: PLR_patch.svg
258         :alt: PLR_patch
259         :align: center
260
261 Vhost
262 -----
263
264 This test case shows quite broad critical region. Fitting functions give
265 fairly differing estimates. Erf function overestimates, stretch function
266 is fairly precise (based on its estimate not moving much with time).
267 The graph mostly shows later measurements slowly bringing the estimates
268 towards each other. The final estimated interval is too broad,
269 a longer run would return a smaller interval within the current one.
270
271 The broadness is caused by result composition, which consists of
272 mostly zero loss measurements, partialy of medium loss measurements,
273 and lack of small loss measurements the loss ratio target would imply.
274
275 With this result composition, it is expected that the convergence
276 of the two bounds is slow.
277
278 .. only:: latex
279
280     .. raw:: latex
281
282         \begin{figure}[H]
283             \centering
284                 \graphicspath{{../_tmp/src/introduction/methodology_data_plane_throughput/}}
285                 \includegraphics[width=0.90\textwidth]{PLR_vhost}
286                 \label{fig:PLR_vhost}
287         \end{figure}
288
289 .. only:: html
290
291     .. figure:: PLR_vhost.svg
292         :alt: PLR_vhost
293         :align: center
294
295 .. _draft-vpolak-bmwg-plrsearch-01: https://tools.ietf.org/html/draft-vpolak-bmwg-plrsearch-01
296 .. _plrsearch draft: https://tools.ietf.org/html/draft-vpolak-bmwg-plrsearch-00
297 .. _RFC 2544: https://tools.ietf.org/html/rfc2544
298 .. _Lomax distribution: https://en.wikipedia.org/wiki/Lomax_distribution
299 .. _reciprocal distribution: https://en.wikipedia.org/wiki/Reciprocal_distribution
300 .. _Monte Carlo: https://en.wikipedia.org/wiki/Monte_Carlo_integration
301 .. _importance sampling: https://en.wikipedia.org/wiki/Importance_sampling
302 .. _bivariate Gaussian: https://en.wikipedia.org/wiki/Multivariate_normal_distribution
303 .. _binary search: https://en.wikipedia.org/wiki/Binary_search_algorithm