feat(docs): Add Methodology
[csit.git] / docs / content / methodology / data_plane_throughput / plrsearch.md
1 ---
2 bookToc: false
3 title: "PLRsearch"
4 weight: 3
5 ---
6
7 # PLRsearch
8
9 ## Motivation for PLRsearch
10
11 Network providers are interested in throughput a system can sustain.
12
13 `RFC 2544`[^3] assumes loss ratio is given by a deterministic function of
14 offered load. But NFV software systems are not deterministic enough.
15 This makes deterministic algorithms (such as `binary search`[^9] per RFC 2544
16 and MLRsearch with single trial) to return results,
17 which when repeated show relatively high standard deviation,
18 thus making it harder to tell what "the throughput" actually is.
19
20 We need another algorithm, which takes this indeterminism into account.
21
22 ## Generic Algorithm
23
24 Detailed description of the PLRsearch algorithm is included in the IETF
25 draft `draft-vpolak-bmwg-plrsearch-02`[^1] that is in the process
26 of being standardized in the IETF Benchmarking Methodology Working Group (BMWG).
27
28 ### Terms
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 The search receives min_rate and max_rate values, to avoid measurements
61 at offered loads not supporeted by the traffic generator.
62
63 The implemented tests cases use bidirectional traffic.
64 The algorithm stores each rate as bidirectional rate (internally,
65 the algorithm is agnostic to flows and directions,
66 it only cares about aggregate counts of packets sent and packets lost),
67 but debug output from traffic generator lists unidirectional values.
68
69 ### Measurement Delay
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, the 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 In order to avoid them, the current implementation tracks natural logarithm
93 (instead of the original quantity) for any quantity which is never negative.
94 Logarithm of zero is minus infinity (not supported by Python),
95 so special value "None" is used instead.
96 Specific functions for frequent operations (such as "logarithm
97 of sum of exponentials") are defined to handle None correctly.
98
99 ### Fitting Functions
100
101 Current implementation uses two fitting functions, called "stretch" and "erf".
102 In general, their estimates for critical rate differ,
103 which adds a simple source of systematic error,
104 on top of randomness error reported by integrator.
105 Otherwise the reported stdev of critical rate estimate
106 is unrealistically low.
107
108 Both functions are not only increasing, but also convex
109 (meaning the rate of increase is also increasing).
110
111 Both fitting functions have several mathematically equivalent formulas,
112 each can lead to an arithmetic overflow or underflow in different sub-terms.
113 Overflows can be eliminated by using different exact formulas
114 for different argument ranges.
115 Underflows can be avoided by using approximate formulas
116 in affected argument ranges, such ranges have their own formulas to compute.
117 At the end, both fitting function implementations
118 contain multiple "if" branches, discontinuities are a possibility
119 at range boundaries.
120
121 ### Prior Distributions
122
123 The numeric integrator expects all the parameters to be distributed
124 (independently and) uniformly on an interval (-1, 1).
125
126 As both "mrr" and "spread" parameters are positive and not dimensionless,
127 a transformation is needed. Dimentionality is inherited from max_rate value.
128
129 The "mrr" parameter follows a `Lomax distribution`[^4]
130 with alpha equal to one, but shifted so that mrr is always greater than 1
131 packet per second.
132
133 The "stretch" parameter is generated simply as the "mrr" value
134 raised to a random power between zero and one;
135 thus it follows a `reciprocal distribution`[^5].
136
137 ### Integrator
138
139 After few measurements, the posterior distribution of fitting function
140 arguments gets quite concentrated into a small area.
141 The integrator is using `Monte Carlo`[^6] with `importance sampling`[^7]
142 where the biased distribution is `bivariate Gaussian`[^8] distribution,
143 with deliberately larger variance.
144 If the generated sample falls outside (-1, 1) interval,
145 another sample is generated.
146
147 The center and the covariance matrix for the biased distribution
148 is based on the first and second moments of samples seen so far
149 (within the computation). The center is used directly,
150 covariance matrix is scaled up by a heurictic constant (8.0 by default).
151 The following additional features are applied
152 designed to avoid hyper-focused distributions.
153
154 Each computation starts with the biased distribution inherited
155 from the previous computation (zero point and unit covariance matrix
156 is used in the first computation), but the overal weight of the data
157 is set to the weight of the first sample of the computation.
158 Also, the center is set to the first sample point.
159 When additional samples come, their weight (including the importance correction)
160 is compared to sum of the weights of data seen so far (within the iteration).
161 If the new sample is more than one e-fold more impactful, both weight values
162 (for data so far and for the new sample) are set to (geometric) average
163 of the two weights.
164
165 This combination showed the best behavior, as the integrator usually follows
166 two phases. First phase (where inherited biased distribution
167 or single big sample are dominating) is mainly important
168 for locating the new area the posterior distribution is concentrated at.
169 The second phase (dominated by whole sample population)
170 is actually relevant for the critical rate estimation.
171
172 ### Offered Load Selection
173
174 First two measurements are hardcoded to happen at the middle of rate interval
175 and at max_rate. Next two measurements follow MRR-like logic,
176 offered load is decreased so that it would reach target loss ratio
177 if offered load decrease lead to equal decrease of loss rate.
178
179 The rest of measurements start directly in between
180 erf and stretch estimate average.
181 There is one workaround implemented, aimed at reducing the number of consequent
182 zero loss measurements (per fitting function). The workaround first stores
183 every measurement result which loss ratio was the targed loss ratio or higher.
184 Sorted list (called lossy loads) of such results is maintained.
185
186 When a sequence of one or more zero loss measurement results is encountered,
187 a smallest of lossy loads is drained from the list.
188 If the estimate average is smaller than the drained value,
189 a weighted average of this estimate and the drained value is used
190 as the next offered load. The weight of the estimate decreases exponentially
191 with the length of consecutive zero loss results.
192
193 This behavior helps the algorithm with convergence speed,
194 as it does not need so many zero loss result to get near critical region.
195 Using the smallest (not drained yet) of lossy loads makes it sure
196 the new offered load is unlikely to result in big loss region.
197 Draining even if the estimate is large enough helps to discard
198 early measurements when loss hapened at too low offered load.
199 Current implementation adds 4 copies of lossy loads and drains 3 of them,
200 which leads to fairly stable behavior even for somewhat inconsistent SUTs.
201
202 ### Caveats
203
204 As high loss count measurements add many bits of information,
205 they need a large amount of small loss count measurements to balance them,
206 making the algorithm converge quite slowly. Typically, this happens
207 when few initial measurements suggest spread way bigger then later measurements.
208 The workaround in offered load selection helps,
209 but more intelligent workarounds could get faster convergence still.
210
211 Some systems evidently do not follow the assumption of repeated measurements
212 having the same average loss rate (when the offered load is the same).
213 The idea of estimating the trend is not implemented at all,
214 as the observed trends have varied characteristics.
215
216 Probably, using a more realistic fitting functions
217 will give better estimates than trend analysis.
218
219 ## Bottom Line
220
221 The notion of Throughput is easy to grasp, but it is harder to measure
222 with any accuracy for non-deterministic systems.
223
224 Even though the notion of critical rate is harder to grasp than the notion
225 of throughput, it is easier to measure using probabilistic methods.
226
227 In testing, the difference between througput measurements and critical
228 rate measurements is usually small.
229
230 In pactice, rules of thumb such as "send at max 95% of purported throughput"
231 are common. The correct benchmarking analysis should ask "Which notion is
232 95% of throughput an approximation to?" before attempting to answer
233 "Is 95% of critical rate safe enough?".
234
235 ## Algorithmic Analysis
236
237 ### Motivation
238
239 While the estimation computation is based on hard probability science;
240 the offered load selection part of PLRsearch logic is pure heuristics,
241 motivated by what would a human do based on measurement and computation results.
242
243 The quality of any heuristic is not affected by soundness of its motivation,
244 just by its ability to achieve the intended goals.
245 In case of offered load selection, the goal is to help the search to converge
246 to the long duration estimates sooner.
247
248 But even those long duration estimates could still be of poor quality.
249 Even though the estimate computation is Bayesian (so it is the best it could be
250 within the applied assumptions), it can still of poor quality when compared
251 to what a human would estimate.
252
253 One possible source of poor quality is the randomnes inherently present
254 in Monte Carlo numeric integration, but that can be supressed
255 by tweaking the time related input parameters.
256
257 The most likely source of poor quality then are the assumptions.
258 Most importantly, the number and the shape of fitting functions;
259 but also others, such as trial order independence and duration independence.
260
261 The result can have poor quality in basically two ways.
262 One way is related to location. Both upper and lower bounds
263 can be overestimates or underestimates, meaning the entire estimated interval
264 between lower bound and upper bound lays above or below (respectively)
265 of human-estimated interval.
266 The other way is related to the estimation interval width.
267 The interval can be too wide or too narrow, compared to human estimation.
268
269 An estimate from a particular fitting function can be classified
270 as an overestimate (or underestimate) just by looking at time evolution
271 (without human examining measurement results). Overestimates
272 decrease by time, underestimates increase by time (assuming
273 the system performance stays constant).
274
275 Quality of the width of the estimation interval needs human evaluation,
276 and is unrelated to both rate of narrowing (both good and bad estimate intervals
277 get narrower at approximately the same relative rate) and relatative width
278 (depends heavily on the system being tested).
279
280 ### Graphical Examples
281
282 The following pictures show the upper (red) and lower (blue) bound,
283 as well as average of Stretch (pink) and Erf (light green) estimate,
284 and offered load chosen (grey), as computed by PLRsearch,
285 after each trial measurement within the 30 minute duration of a test run.
286
287 Both graphs are focusing on later estimates. Estimates computed from
288 few initial measurements are wildly off the y-axis range shown.
289
290 The following analysis will rely on frequency of zero loss measurements
291 and magnitude of loss ratio if nonzero.
292
293 The offered load selection strategy used implies zero loss measurements
294 can be gleaned from the graph by looking at offered load points.
295 When the points move up farther from lower estimate, it means
296 the previous measurement had zero loss. After non-zero loss,
297 the offered load starts again right between (the previous values of)
298 the estimate curves.
299
300 The very big loss ratio results are visible as noticeable jumps
301 of both estimates downwards. Medium and small loss ratios are much harder
302 to distinguish just by looking at the estimate curves,
303 the analysis is based on raw loss ratio measurement results.
304
305 The following descriptions should explain why the graphs seem to signal
306 low quality estimate at first sight, but a more detailed look
307 reveals the quality is good (considering the measurement results).
308
309 #### L2 patch
310
311 Both fitting functions give similar estimates, the graph shows
312 "stochasticity" of measurements (estimates increase and decrease
313 within small time regions), and an overall trend of decreasing estimates.
314
315 On the first look, the final interval looks fairly narrow,
316 especially compared to the region the estimates have travelled
317 during the search. But the look at the frequency of zero loss results shows
318 this is not a case of overestimation. Measurements at around the same
319 offered load have higher probability of zero loss earlier
320 (when performed farther from upper bound), but smaller probability later
321 (when performed closer to upper bound). That means it is the performance
322 of the system under test that decreases (slightly) over time.
323
324 With that in mind, the apparent narrowness of the interval
325 is not a sign of low quality, just a consequence of PLRsearch assuming
326 the performance stays constant.
327
328 {{< svg "static/PLR_patch.svg" >}}
329
330 #### Vhost
331
332 This test case shows what looks like a quite broad estimation interval,
333 compared to other test cases with similarly looking zero loss frequencies.
334 Notable features are infrequent high-loss measurement results
335 causing big drops of estimates, and lack of long-term convergence.
336
337 Any convergence in medium-sized intervals (during zero loss results)
338 is reverted by the big loss results, as they happen quite far
339 from the critical load estimates, and the two fitting functions
340 extrapolate differently.
341
342 In other words, human only seeing estimates from one fitting function
343 would expect narrower end interval, but human seeing the measured loss ratios
344 agrees that the interval should be wider than that.
345
346 {{< svg "static/PLR_vhost.svg" >}}
347
348 #### Summary
349
350 The two graphs show the behavior of PLRsearch algorithm applied to soaking test
351 when some of PLRsearch assumptions do not hold:
352
353 + L2 patch measurement results violate the assumption
354   of performance not changing over time.
355 + Vhost measurement results violate the assumption
356   of Poisson distribution matching the loss counts.
357
358 The reported upper and lower bounds can have distance larger or smaller
359 than a first look by a human would expect, but a more closer look reveals
360 the quality is good, considering the circumstances.
361
362 The usefullness of the critical load estimate is of questionable value
363 when the assumptions are violated.
364
365 Some improvements can be made via more specific workarounds,
366 for example long term limit of L2 patch performance could be estmated
367 by some heuristic.
368
369 Other improvements can be achieved only by asking users
370 whether loss patterns matter. Is it better to have single digit losses
371 distributed fairly evenly over time (as Poisson distribution would suggest),
372 or is it better to have short periods of medium losses
373 mixed with long periods of zero losses (as happens in Vhost test)
374 with the same overall loss ratio?
375
376 [^1]: [draft-vpolak-bmwg-plrsearch-02](https://tools.ietf.org/html/draft-vpolak-bmwg-plrsearch-02)
377 [^2]: [plrsearch draft](https://tools.ietf.org/html/draft-vpolak-bmwg-plrsearch-00)
378 [^3]: [RFC 2544](https://tools.ietf.org/html/rfc2544)
379 [^4]: [Lomax distribution](https://en.wikipedia.org/wiki/Lomax_distribution)
380 [^5]: [reciprocal distribution](https://en.wikipedia.org/wiki/Reciprocal_distribution)
381 [^6]: [Monte Carlo](https://en.wikipedia.org/wiki/Monte_Carlo_integration)
382 [^7]: [importance sampling](https://en.wikipedia.org/wiki/Importance_sampling)
383 [^8]: [bivariate Gaussian](https://en.wikipedia.org/wiki/Multivariate_normal_distribution)
384 [^9]: [binary search](https://en.wikipedia.org/wiki/Binary_search_algorithm)