Report methodology: PLRsearch update with graphs
[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-02`_ 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 + Trial Order Independent System
34 + Duration Independent System
35 + Target Loss Ratio
36 + Critical Load
37 + Offered Load regions
38
39   + Zero Loss Region
40   + Non-Deterministic Region
41   + Guaranteed Loss Region
42
43 + Fitting Function
44
45   + Stretch Function
46   + Erf Function
47
48 + Bayesian Inference
49
50   + Prior distribution
51   + Posterior Distribution
52
53 + Numeric Integration
54
55   + Monte Carlo
56   + Importance Sampling
57
58 FD.io CSIT Implementation Specifics
59 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
60
61 The search receives min_rate and max_rate values, to avoid measurements
62 at offered loads not supporeted by the traffic generator.
63
64 The implemented tests cases use bidirectional traffic.
65 The algorithm stores each rate as bidirectional rate (internally,
66 the algorithm is agnostic to flows and directions,
67 it only cares about aggregate counts of packets sent and packets lost),
68 but debug output from traffic generator lists unidirectional values.
69
70 Measurement Delay
71 `````````````````
72
73 In a sample implemenation in FD.io CSIT project, there is roughly 0.5
74 second delay between trials due to restrictons imposed by packet traffic
75 generator in use (T-Rex).
76
77 As measurements results come in, posterior distribution computation takes
78 more time (per sample), although there is a considerable constant part
79 (mostly for inverting the fitting functions).
80
81 Also, the integrator needs a fair amount of samples to reach the region
82 the posterior distribution is concentrated at.
83
84 And of course, the speed of the integrator depends on computing power
85 of the CPU the algorithm is able to use.
86
87 All those timing related effects are addressed by arithmetically increasing
88 trial durations with configurable coefficients
89 (currently 5.1 seconds for the first trial,
90 each subsequent trial being 0.1 second longer).
91
92 Rounding Errors and Underflows
93 ``````````````````````````````
94
95 In order to avoid them, the current implementation tracks natural logarithm
96 (instead of the original quantity) for any quantity which is never negative.
97 Logarithm of zero is minus infinity (not supported by Python),
98 so special value "None" is used instead.
99 Specific functions for frequent operations (such as "logarithm
100 of sum of exponentials") are defined to handle None correctly.
101
102 Fitting Functions
103 `````````````````
104
105 Current implementation uses two fitting functions.
106 In general, their estimates for critical rate differ,
107 which adds a simple source of systematic error,
108 on top of randomness error reported by integrator.
109 Otherwise the reported stdev of critical rate estimate
110 is unrealistically low.
111
112 Both functions are not only increasing, but also convex
113 (meaning the rate of increase is also increasing).
114
115 Both fitting functions have several mathematically equivalent formulas,
116 each can lead to an overflow or underflow in different sub-terms.
117 Overflows can be eliminated by using different exact formulas
118 for different argument ranges.
119 Underflows can be avoided by using approximate formulas
120 in affected argument ranges, such ranges have their own formulas to compute.
121 At the end, both fitting function implementations
122 contain multiple "if" branches, discontinuities are a possibility
123 at range boundaries.
124
125 Prior Distributions
126 ```````````````````
127
128 The numeric integrator expects all the parameters to be distributed
129 (independently and) uniformly on an interval (-1, 1).
130
131 As both "mrr" and "spread" parameters are positive and not not dimensionless,
132 a transformation is needed. Dimentionality is inherited from max_rate value.
133
134 The "mrr" parameter follows a `Lomax distribution`_
135 with alpha equal to one, but shifted so that mrr is always greater than 1
136 packet per second.
137
138 The "stretch" parameter is generated simply as the "mrr" value
139 raised to a random power between zero and one;
140 thus it follows a `reciprocal distribution`_.
141
142 Integrator
143 ``````````
144
145 After few measurements, the posterior distribution of fitting function
146 arguments gets quite concentrated into a small area.
147 The integrator is using `Monte Carlo`_ with `importance sampling`_
148 where the biased distribution is `bivariate Gaussian`_ distribution,
149 with deliberately larger variance.
150 If the generated sample falls outside (-1, 1) interval,
151 another sample is generated.
152
153 The center and the covariance matrix for the biased distribution
154 is based on the first and second moments of samples seen so far
155 (within the computation). The center is used directly,
156 covariance matrix is scaled up by a heurictic constant (8.0 by default).
157 The following additional features are applied
158 designed to avoid hyper-focused distributions.
159
160 Each computation starts with the biased distribution inherited
161 from the previous computation (zero point and unit covariance matrix
162 is used in the first computation), but the overal weight of the data
163 is set to the weight of the first sample of the computation.
164 Also, the center is set to the first sample point.
165 When additional samples come, their weight (including the importance correction)
166 is compared to sum of the weights of data seen so far (within the iteration).
167 If the new sample is more than one e-fold more impactful, both weight values
168 (for data so far and for the new sample) are set to (geometric) average
169 of the two weights.
170
171 This combination showed the best behavior, as the integrator usually follows
172 two phases. First phase (where inherited biased distribution
173 or single big sample are dominating) is mainly important
174 for locating the new area the posterior distribution is concentrated at.
175 The second phase (dominated by whole sample population)
176 is actually relevant for the critical rate estimation.
177
178 Offered Load Selection
179 ``````````````````````
180
181 First two measurements are hardcoded to happen at the middle of rate interval
182 and at max_rate. Next two measurements follow MRR-like logic,
183 offered load is decreased so that it would reach target loss ratio
184 if offered load decrease lead to equal decrease of loss rate.
185
186 The rest of measurements start directly in between
187 erf and stretch estimate average.
188 There is one workaround implemented, aimed at reducing the number of consequent
189 zero loss measurements (per fitting function). The workaround first stores
190 every measurement result which loss ratio was the targed loss ratio or higher.
191 Sorted list (called lossy loads) of such results is maintained.
192
193 When a sequence of one or more zero loss measurement results is encountered,
194 a smallest of lossy loads is drained from the list.
195 If the estimate average is smaller than the drained value,
196 a weighted average of this estimate and the drained value is used
197 as the next offered load. The weight of the estimate decreases exponentially
198 with the length of consecutive zero loss results.
199
200 This behavior helps the algorithm with convergence speed,
201 as it does not need so many zero loss result to get near critical region.
202 Using the smallest (not drained yet) of lossy loads makes it sure
203 the new offered load is unlikely to result in big loss region.
204 Draining even if the estimate is large enough helps to discard
205 early measurements when loss hapened at too low offered load.
206 Current implementation adds 4 copies of lossy loads and drains 3 of them,
207 which leads to fairly stable behavior even for somewhat inconsistent SUTs.
208
209 Caveats
210 ```````
211
212 As high loss count measurements add many bits of information,
213 they need a large amount of small loss count measurements to balance them,
214 making the algorithm converge quite slowly. Typically, this happens
215 when few initial measurements suggest spread way bigger then later measurements.
216 The workaround in offered load selection helps,
217 but more intelligent workarounds could get faster convergence still.
218
219 Some systems evidently do not follow the assumption of repeated measurements
220 having the same average loss rate (when the offered load is the same).
221 The idea of estimating the trend is not implemented at all,
222 as the observed trends have varied characteristics.
223
224 Probably, using a more realistic fitting functions
225 will give better estimates than trend analysis.
226
227 Bottom Line
228 ~~~~~~~~~~~
229
230 The notion of Throughput is easy to grasp, but it is harder to measure
231 with any accuracy for non-deterministic systems.
232
233 Even though the notion of critical rate is harder to grasp than the notion
234 of throughput, it is easier to measure using probabilistic methods.
235
236 In testing, the difference between througput measurements and critical
237 rate measurements is usually small, see :ref:`soak vs ndr comparison`.
238
239 In pactice, rules of thumb such as "send at max 95% of purported throughput"
240 are common. The correct benchmarking analysis should ask "Which notion is
241 95% of throughput an approximation to?" before attempting to answer
242 "Is 95% of critical rate safe enough?".
243
244 Algorithmic Analysis
245 ~~~~~~~~~~~~~~~~~~~~
246
247 Motivation
248 ``````````
249
250 While the estimation computation is based on hard probability science;
251 the offered load selection part of PLRsearch logic is pure heuristics,
252 motivated by what would a human do based on measurement and computation results.
253
254 The quality of any heuristic is not affected by soundness of its motivation,
255 just by its ability to achieve the intended goals.
256 In case of offered load selection, the goal is to help the search to converge
257 to the long duration estimates sooner.
258
259 But even those long duration estimates could still be of poor quality.
260 Even though the estimate computation is Bayesian (so it is the best it could be
261 within the applied assumptions), it can still of poor quality when compared
262 to what a human would estimate.
263
264 One possible source of poor quality is the randomnes inherently present
265 in Monte Carlo numeric integration, but that can be supressed
266 by tweaking the time related input parameters.
267
268 The most likely source of poor quality then are the assumptions.
269 Most importantly, the number and the shape of fitting functions;
270 but also others, such as trial order independence and duration independence.
271
272 The result can have poor quality in basically two ways.
273 One way is related to location. Both upper and lower bounds
274 can be overestimates or underestimates, meaning the entire estimated interval
275 between lower bound and upper bound lays above or below (respectively)
276 of human-estimated interval.
277 The other way is related to the estimation interval width.
278 The interval can be too wide or too narrow, compared to human estimation.
279
280 An estimate from a particular fitting function can be classified
281 as an overestimate (or underestimate) just by looking at time evolution
282 (without human examining measurement results). Overestimates
283 decrease by time, underestimates increase by time (assuming
284 the system performance stays constant).
285
286 Quality of the width of the estimation interval needs human evaluation,
287 and is unrelated to both rate of narrowing (both good and bad estimate intervals
288 get narrower at approximately the same relative rate) and relatative width
289 (depends heavily on the system being tested).
290
291 Graphical Examples
292 ``````````````````
293
294 The following pictures show the upper (red) and lower (blue) bound,
295 as well as average of Stretch (pink) and Erf (light green) estimate,
296 and offered load chosen (grey), as computed by PLRsearch,
297 after each trial measurement within the 30 minute duration of a test run.
298
299 Both graphs are focusing on later estimates. Estimates computed from
300 few initial measurements are wildly off the y-axis range shown.
301
302 The following analysis will rely on frequency of zero loss measurements
303 and magnitude of loss ratio if nonzero.
304
305 The offered load selection strategy used implies zero loss measurements
306 can be gleamed from the graph by looking at offered load points.
307 When the points move up farther from lower estimate, it means
308 the previous measurement had zero loss. After non-zero loss,
309 the offered load starts again right between (the previous values of)
310 the estimate curves.
311
312 The very big loss ratio results are visible as noticeable jumps
313 of both estimates downwards. Medium and small loss ratios are much harder
314 to distinguish just by looking at the estimate curves,
315 the analysis is based on raw loss ratio measurement results.
316
317 The following descriptions should explain why the graphs seem to signal
318 low quality estimate at first sight, but a more detailed look
319 reveals the quality is good (considering the measurement results).
320
321 L2 patch
322 --------
323
324 Both fitting functions give similar estimates, the graph shows
325 "stochasticity" of measurements (estimates increase and decrease
326 within small time regions), and an overall trend of decreasing estimates.
327
328 On the first look, the final interval looks fairly narrow,
329 especially compared to the region the estimates have travelled
330 during the search. But the look at the frequency of zero loss results shows
331 this is not a case of overestimation. Measurements at around the same
332 offered load have higher probability of zero loss earlier
333 (when performed farther from upper bound), but smaller probability later
334 (when performed closer to upper bound). That means it is the performance
335 of the system under test that decreases (slightly) over time.
336
337 With that in mind, the apparent narrowness of the interval
338 is not a sign of low quality, just a consequence of PLRsearch assuming
339 the performance stays constant.
340
341 .. only:: latex
342
343     .. raw:: latex
344
345         \begin{figure}[H]
346             \centering
347                 \graphicspath{{../_tmp/src/introduction/methodology_data_plane_throughput/}}
348                 \includegraphics[width=0.90\textwidth]{PLR_patch}
349                 \label{fig:PLR_patch}
350         \end{figure}
351
352 .. only:: html
353
354     .. figure:: PLR_patch.svg
355         :alt: PLR_patch
356         :align: center
357
358 Vhost
359 -----
360
361 This test case shows what looks like a quite broad estimation interval,
362 compared to other test cases with similarly looking zero loss frequencies.
363 Notable features are infrequent high-loss measurement results
364 causing big drops of estimates, and lack of long-term convergence.
365
366 Any convergence in medium-sized intervals (during zero loss results)
367 is reverted by the big loss results, as they happen quite far
368 from the critical load estimates, and the two fitting functions
369 extrapolate differently.
370
371 In other words, human only seeing estimates from one fitting function
372 would expect narrower end interval, but human seeing the measured loss ratios
373 agrees that the interval should be wider than that.
374
375 .. only:: latex
376
377     .. raw:: latex
378
379         \begin{figure}[H]
380             \centering
381                 \graphicspath{{../_tmp/src/introduction/methodology_data_plane_throughput/}}
382                 \includegraphics[width=0.90\textwidth]{PLR_vhost}
383                 \label{fig:PLR_vhost}
384         \end{figure}
385
386 .. only:: html
387
388     .. figure:: PLR_vhost.svg
389         :alt: PLR_vhost
390         :align: center
391
392 Summary
393 -------
394
395 The two graphs show the behavior of PLRsearch algorithm applied to soaking test
396 when some of PLRsearch assumptions do not hold:
397
398 + L2 patch measurement results violate the assumption
399   of performance not changing over time.
400 + Vhost measurement results violate the assumption
401   of Poisson distribution matching the loss counts.
402
403 The reported upper and lower bounds can have distance larger or smaller
404 than a first look by a human would expect, but a more closer look reveals
405 the quality is good, considering the circumstances.
406
407 The usefullness of the critical load estimate is of questionable value
408 when the assumptions are violated.
409
410 Some improvements can be made via more specific workarounds,
411 for example long term limit of L2 patch performance could be estmated
412 by some heuristic.
413
414 Other improvements can be achieved only by asking users
415 whether loss patterns matter. Is it better to have single digit losses
416 distributed fairly evenly over time (as Poisson distribution would suggest),
417 or is it better to have short periods of medium losses
418 mixed with long periods of zero losses (as happens in Vhost test)
419 with the same overall loss ratio?
420
421 .. _draft-vpolak-bmwg-plrsearch-02: https://tools.ietf.org/html/draft-vpolak-bmwg-plrsearch-02
422 .. _plrsearch draft: https://tools.ietf.org/html/draft-vpolak-bmwg-plrsearch-00
423 .. _RFC 2544: https://tools.ietf.org/html/rfc2544
424 .. _Lomax distribution: https://en.wikipedia.org/wiki/Lomax_distribution
425 .. _reciprocal distribution: https://en.wikipedia.org/wiki/Reciprocal_distribution
426 .. _Monte Carlo: https://en.wikipedia.org/wiki/Monte_Carlo_integration
427 .. _importance sampling: https://en.wikipedia.org/wiki/Importance_sampling
428 .. _bivariate Gaussian: https://en.wikipedia.org/wiki/Multivariate_normal_distribution
429 .. _binary search: https://en.wikipedia.org/wiki/Binary_search_algorithm