6f208c1ecead5f74d62c18995f09f2475bbc28e2
[csit.git] / docs / content / methodology / measurements / data_plane_throughput / plr_search.md
1 ---
2 title: "PLR Search"
3 weight: 3
4 ---
5
6 # PLR Search
7
8 ## Motivation for PLRsearch
9
10 Network providers are interested in throughput a system can sustain.
11
12 `RFC 2544`[^1] 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`[^2] 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 `Probabilistic Loss Ratio Search for Packet Throughput`[^3] that is in the
25 process of being standardized in the IETF Benchmarking Methodology Working Group
26 (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 In CSIT, tests that employ PLRsearch are identified as SOAK tests,
70 the search time is set to 30 minuts.
71
72 ### Measurement Delay
73
74 In a sample implemenation in FD.io CSIT project, there is roughly 0.5
75 second delay between trials due to restrictons imposed by packet traffic
76 generator in use (T-Rex).
77
78 As measurements results come in, posterior distribution computation takes
79 more time (per sample), although there is a considerable constant part
80 (mostly for inverting the fitting functions).
81
82 Also, the integrator needs a fair amount of samples to reach the region
83 the posterior distribution is concentrated at.
84
85 And of course, the speed of the integrator depends on computing power
86 of the CPU the algorithm is able to use.
87
88 All those timing related effects are addressed by arithmetically increasing
89 trial durations with configurable coefficients
90 (currently 5.1 seconds for the first trial,
91 each subsequent trial being 0.1 second longer).
92
93 ### Rounding Errors and Underflows
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 Current implementation uses two fitting functions, called "stretch" and "erf".
105 In general, their estimates for critical rate differ,
106 which adds a simple source of systematic error,
107 on top of randomness error reported by integrator.
108 Otherwise the reported stdev of critical rate estimate
109 is unrealistically low.
110
111 Both functions are not only increasing, but also convex
112 (meaning the rate of increase is also increasing).
113
114 Both fitting functions have several mathematically equivalent formulas,
115 each can lead to an arithmetic overflow or underflow in different sub-terms.
116 Overflows can be eliminated by using different exact formulas
117 for different argument ranges.
118 Underflows can be avoided by using approximate formulas
119 in affected argument ranges, such ranges have their own formulas to compute.
120 At the end, both fitting function implementations
121 contain multiple "if" branches, discontinuities are a possibility
122 at range boundaries.
123
124 ### Prior Distributions
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 dimensionless,
130 a transformation is needed. Dimentionality is inherited from max_rate value.
131
132 The "mrr" parameter follows a `Lomax distribution`[^4]
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`[^5].
139
140 ### Integrator
141
142 After few measurements, the posterior distribution of fitting function
143 arguments gets quite concentrated into a small area.
144 The integrator is using `Monte Carlo`[^6] with `importance sampling`[^7]
145 where the biased distribution is `bivariate Gaussian`[^8] distribution,
146 with deliberately larger variance.
147 If the generated sample falls outside (-1, 1) interval,
148 another sample is generated.
149
150 The center and the covariance matrix for the biased distribution
151 is based on the first and second moments of samples seen so far
152 (within the computation). The center is used directly,
153 covariance matrix is scaled up by a heurictic constant (8.0 by default).
154 The following additional features are applied
155 designed to avoid hyper-focused distributions.
156
157 Each computation starts with the biased distribution inherited
158 from the previous computation (zero point and unit covariance matrix
159 is used in the first computation), but the overal weight of the data
160 is set to the weight of the first sample of the computation.
161 Also, the center is set to the first sample point.
162 When additional samples come, their weight (including the importance correction)
163 is compared to sum of the weights of data seen so far (within the iteration).
164 If the new sample is more than one e-fold more impactful, both weight values
165 (for data so far and for the new sample) are set to (geometric) average
166 of the two weights.
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 sample 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 First two measurements are hardcoded to happen at the middle of rate interval
178 and at max_rate. Next two measurements follow MRR-like logic,
179 offered load is decreased so that it would reach target loss ratio
180 if offered load decrease lead to equal decrease of loss rate.
181
182 The rest of measurements start directly in between
183 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 drained 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 As high loss count measurements add many bits of information,
208 they need a large amount of small loss count measurements to balance them,
209 making the algorithm converge quite slowly. Typically, this happens
210 when few initial measurements suggest spread way bigger then later measurements.
211 The workaround in offered load selection helps,
212 but more intelligent workarounds could get faster convergence still.
213
214 Some systems evidently do not follow the assumption of repeated measurements
215 having the same average loss rate (when the offered load is the same).
216 The idea of estimating the trend is not implemented at all,
217 as the observed trends have varied characteristics.
218
219 Probably, using a more realistic fitting functions
220 will give better estimates than trend analysis.
221
222 ## Bottom Line
223
224 The notion of Throughput is easy to grasp, but it is harder to measure
225 with any accuracy for non-deterministic systems.
226
227 Even though the notion of critical rate is harder to grasp than the notion
228 of throughput, it is easier to measure using probabilistic methods.
229
230 In testing, the difference between througput measurements and critical
231 rate measurements is usually small.
232
233 In pactice, rules of thumb such as "send at max 95% of purported throughput"
234 are common. The correct benchmarking analysis should ask "Which notion is
235 95% of throughput an approximation to?" before attempting to answer
236 "Is 95% of critical rate safe enough?".
237
238 ## Algorithmic Analysis
239
240 ### Motivation
241
242 While the estimation computation is based on hard probability science;
243 the offered load selection part of PLRsearch logic is pure heuristics,
244 motivated by what would a human do based on measurement and computation results.
245
246 The quality of any heuristic is not affected by soundness of its motivation,
247 just by its ability to achieve the intended goals.
248 In case of offered load selection, the goal is to help the search to converge
249 to the long duration estimates sooner.
250
251 But even those long duration estimates could still be of poor quality.
252 Even though the estimate computation is Bayesian (so it is the best it could be
253 within the applied assumptions), it can still of poor quality when compared
254 to what a human would estimate.
255
256 One possible source of poor quality is the randomnes inherently present
257 in Monte Carlo numeric integration, but that can be supressed
258 by tweaking the time related input parameters.
259
260 The most likely source of poor quality then are the assumptions.
261 Most importantly, the number and the shape of fitting functions;
262 but also others, such as trial order independence and duration independence.
263
264 The result can have poor quality in basically two ways.
265 One way is related to location. Both upper and lower bounds
266 can be overestimates or underestimates, meaning the entire estimated interval
267 between lower bound and upper bound lays above or below (respectively)
268 of human-estimated interval.
269 The other way is related to the estimation interval width.
270 The interval can be too wide or too narrow, compared to human estimation.
271
272 An estimate from a particular fitting function can be classified
273 as an overestimate (or underestimate) just by looking at time evolution
274 (without human examining measurement results). Overestimates
275 decrease by time, underestimates increase by time (assuming
276 the system performance stays constant).
277
278 Quality of the width of the estimation interval needs human evaluation,
279 and is unrelated to both rate of narrowing (both good and bad estimate intervals
280 get narrower at approximately the same relative rate) and relatative width
281 (depends heavily on the system being tested).
282
283 ### Graphical Examples
284
285 The following pictures show the upper (red) and lower (blue) bound,
286 as well as average of Stretch (pink) and Erf (light green) estimate,
287 and offered load chosen (grey), as computed by PLRsearch,
288 after each trial measurement within the 30 minute duration of a test run.
289
290 Both graphs are focusing on later estimates. Estimates computed from
291 few initial measurements are wildly off the y-axis range shown.
292
293 The following analysis will rely on frequency of zero loss measurements
294 and magnitude of loss ratio if nonzero.
295
296 The offered load selection strategy used implies zero loss measurements
297 can be gleaned from the graph by looking at offered load points.
298 When the points move up farther from lower estimate, it means
299 the previous measurement had zero loss. After non-zero loss,
300 the offered load starts again right between (the previous values of)
301 the estimate curves.
302
303 The very big loss ratio results are visible as noticeable jumps
304 of both estimates downwards. Medium and small loss ratios are much harder
305 to distinguish just by looking at the estimate curves,
306 the analysis is based on raw loss ratio measurement results.
307
308 The following descriptions should explain why the graphs seem to signal
309 low quality estimate at first sight, but a more detailed look
310 reveals the quality is good (considering the measurement results).
311
312 #### L2 patch
313
314 Both fitting functions give similar estimates, the graph shows
315 "stochasticity" of measurements (estimates increase and decrease
316 within small time regions), and an overall trend of decreasing estimates.
317
318 On the first look, the final interval looks fairly narrow,
319 especially compared to the region the estimates have travelled
320 during the search. But the look at the frequency of zero loss results shows
321 this is not a case of overestimation. Measurements at around the same
322 offered load have higher probability of zero loss earlier
323 (when performed farther from upper bound), but smaller probability later
324 (when performed closer to upper bound). That means it is the performance
325 of the system under test that decreases (slightly) over time.
326
327 With that in mind, the apparent narrowness of the interval
328 is not a sign of low quality, just a consequence of PLRsearch assuming
329 the performance stays constant.
330
331 {{< figure src="/cdocs/PLR_patch.svg" >}}
332
333 #### Vhost
334
335 This test case shows what looks like a quite broad estimation interval,
336 compared to other test cases with similarly looking zero loss frequencies.
337 Notable features are infrequent high-loss measurement results
338 causing big drops of estimates, and lack of long-term convergence.
339
340 Any convergence in medium-sized intervals (during zero loss results)
341 is reverted by the big loss results, as they happen quite far
342 from the critical load estimates, and the two fitting functions
343 extrapolate differently.
344
345 In other words, human only seeing estimates from one fitting function
346 would expect narrower end interval, but human seeing the measured loss ratios
347 agrees that the interval should be wider than that.
348
349 {{< figure src="/cdocs/PLR_vhost.svg" >}}
350
351 #### Summary
352
353 The two graphs show the behavior of PLRsearch algorithm applied to soak test
354 when some of PLRsearch assumptions do not hold:
355
356 + L2 patch measurement results violate the assumption
357   of performance not changing over time.
358 + Vhost measurement results violate the assumption
359   of Poisson distribution matching the loss counts.
360
361 The reported upper and lower bounds can have distance larger or smaller
362 than a first look by a human would expect, but a more closer look reveals
363 the quality is good, considering the circumstances.
364
365 The usefullness of the critical load estimate is of questionable value
366 when the assumptions are violated.
367
368 Some improvements can be made via more specific workarounds,
369 for example long term limit of L2 patch performance could be estmated
370 by some heuristic.
371
372 Other improvements can be achieved only by asking users
373 whether loss patterns matter. Is it better to have single digit losses
374 distributed fairly evenly over time (as Poisson distribution would suggest),
375 or is it better to have short periods of medium losses
376 mixed with long periods of zero losses (as happens in Vhost test)
377 with the same overall loss ratio?
378
379 [^1]: [RFC 2544: Benchmarking Methodology for Network Interconnect Devices](https://tools.ietf.org/html/rfc2544)
380 [^2]: [Binary search](https://en.wikipedia.org/wiki/Binary_search_algorithm)
381 [^3]: [Probabilistic Loss Ratio Search for Packet Throughput](https://tools.ietf.org/html/draft-vpolak-bmwg-plrsearch-02)
382 [^4]: [Lomax distribution](https://en.wikipedia.org/wiki/Lomax_distribution)
383 [^5]: [Reciprocal distribution](https://en.wikipedia.org/wiki/Reciprocal_distribution)
384 [^6]: [Monte Carlo](https://en.wikipedia.org/wiki/Monte_Carlo_integration)
385 [^7]: [Importance sampling](https://en.wikipedia.org/wiki/Importance_sampling)
386 [^8]: [Bivariate Gaussian](https://en.wikipedia.org/wiki/Multivariate_normal_distribution)