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