feat(PyPI): update metadata for jumpavg 0.4.2
[csit.git] / docs / content / methodology / trending / analysis.md
1 ---
2 title: "Analysis"
3 weight: 1
4 ---
5
6 # Trend Analysis
7
8 All measured performance trend data is treated as time-series data
9 that is modeled as a concatenation of groups,
10 within each group the samples come (independently) from
11 the same normal distribution (with some center and standard deviation).
12
13 Center of the normal distribution for the group (equal to population average)
14 is called a trend for the group.
15 All the analysis is based on finding the right partition into groups
16 and comparing their trends.
17
18 ## Anomalies in graphs
19
20 In graphs, the start of the following group is marked as a regression (red
21 circle) or progression (green circle), if the new trend is lower (or higher
22 respectively) then the previous group's.
23
24 ## Implementation details
25
26 ### Partitioning into groups
27
28 While sometimes the samples within a group are far from being distributed
29 normally, currently we do not have a better tractable model.
30
31 Here, "sample" should be the result of single trial measurement, with group
32 boundaries set only at test run granularity. But in order to avoid detecting
33 causes unrelated to VPP performance, the current presentation takes average of
34 all trials within the MRR run as the sample. Effectively, this acts as a single
35 trial with aggregate duration.
36 (Trending of NDR or PDR results take just one sample, the conditional throughput).
37
38 Performance graphs show the run average as a dot (not all individual trial
39 results).
40
41 The group boundaries are selected based on `Minimum Description Length`[^1].
42
43 ### Minimum Description Length
44
45 `Minimum Description Length`[^1] (MDL) is a particular formalization
46 of `Occam's razor`[^2] principle.
47
48 The general formulation mandates to evaluate a large set of models,
49 but for anomaly detection purposes, it is useful to consider
50 a smaller set of models, so that scoring and comparing them is easier.
51
52 For each candidate model, the data should be compressed losslessly,
53 which includes model definitions, encoded model parameters,
54 and the raw data encoded based on probabilities computed by the model.
55 The model resulting in shortest compressed message is the "the" correct model.
56
57 For our model set (groups of normally distributed samples),
58 we need to encode group length (which penalizes too many groups),
59 group average (more on that later), group stdev and then all the samples.
60
61 Luckily, the "all the samples" part turns out to be quite easy to compute.
62 If sample values are considered as coordinates in (multi-dimensional)
63 Euclidean space, fixing average restrict possible values to a (hyper-)plane.
64 Then, fixing stdev means the point with allowed coordinates
65 lays on a sphere (centered the "all samples equal to average" point)
66 within that hyper-plane.
67 And the Gaussian probability density on the resulting sphere is constant.
68 So the only contribution is the "area" of the sphere, which only depends
69 on the number of samples and stdev.
70
71 Still, to get the information content in bits, we need to know what "size"
72 one "pixel" of that area is.
73 Our implementation assumes that measurement precision is such that
74 the max sample value is 4096 (2^12) pixels (inspired by 0.5% precision
75 of NDRPDR tests, roughly two pixels around max value).
76
77 A somehow ambiguous part is in choosing which encoding
78 is used for group size, average and stdev.
79 Different encodings cause different biases to large or small values.
80 In our implementation we have chosen probability density
81 corresponding to uniform distribution (from zero to maximal sample value)
82 for stdev and average of the first group,
83 but for averages of subsequent groups we have chosen a distribution
84 which discourages delimiting groups with averages close together.
85
86 The group selection algorithm currently has no parameters,
87 all the aforementioned encodings and handling of precision is hard-coded.
88 (Although the underlying library "jumpavg" allows users to change the precision,
89 either in absolute units or in bits per max sample.)
90
91 In principle, every group selection is examined, and the one encodable
92 with least amount of bits is selected.
93 As the bit amount for a selection is just sum of bits for every group,
94 finding the best selection takes number of comparisons
95 quadratically increasing with the size of data,
96 the overall time complexity being probably cubic.
97
98 The resulting group distribution looks good
99 if samples are distributed normally enough within a group.
100 But for obviously different distributions (for example
101 `bimodal distribution`[^3]) the groups tend to focus on less relevant factors
102 (such as "outlier" density).
103
104 ## Common Patterns
105
106 When an anomaly is detected, it frequently falls into few known patterns,
107 each having its typical behavior over time.
108
109 We are going to describe the behaviors,
110 as they motivate our choice of trend compliance metrics.
111
112 ### Sample time and analysis time
113
114 But first we need to distinguish two roles time plays in analysis,
115 so it is more clear which role we are referring to.
116
117 Sample time is the more obvious one.
118 It is the time the sample is generated.
119 It is the start time or the end time of the Jenkins job run,
120 does not really matter which (parallel runs are disabled,
121 and length of gap between samples does not affect metrics).
122
123 Analysis time is the time the current analysis is computed.
124 Again, the exact time does not usually matter,
125 what matters is how many later (and how fewer earlier) samples
126 were considered in the computation.
127
128 For some patterns, it is usual for a previously reported
129 anomaly to "vanish", or previously unseen anomaly to "appear late",
130 as later samples change which partition into groups is more probable.
131
132 Dashboard and graphs are always showing the latest analysis time,
133 the compliance metrics are using earlier sample time
134 with the same latest analysis time.
135
136 Alerting e-mails use the latest analysis time at the time of sending,
137 so the values reported there are likely to be different
138 from the later analysis time results shown in dashboard and graphs.
139
140 ### Ordinary regression
141
142 The real performance changes from previously stable value
143 into a new stable value.
144
145 For medium to high magnitude of the change, one run
146 is enough for anomaly detection to mark this regression.
147
148 Ordinary progressions are detected in the same way.
149
150 ### Small regression
151
152 The real performance changes from previously stable value
153 into a new stable value, but the difference is small.
154
155 For the anomaly detection algorithm, this change is harder to detect,
156 depending on the standard deviation of the previous group.
157
158 If the new performance value stays stable, eventually
159 the detection algorithm is able to detect this anomaly
160 when there are enough samples around the new value.
161
162 If the difference is too small, it may remain undetected
163 (as new performance change happens, or full history of samples
164 is still not enough for the detection).
165
166 Small progressions have the same behavior.
167
168 ### Reverted regression
169
170 This pattern can have two different causes.
171 We would like to distinguish them, but that is usually
172 not possible to do just by looking at the measured values (and not telemetry).
173
174 In one cause, the real DUT performance has changed,
175 but got restored immediately.
176 In the other cause, no real performance change happened,
177 just some temporary infrastructure issue
178 has caused a wrong low value to be measured.
179
180 For small measured changes, this pattern may remain undetected.
181 For medium and big measured changes, this is detected when the regression
182 happens on just the last sample.
183
184 For big changes, the revert is also immediately detected
185 as a subsequent progression. The trend is usually different
186 from the previously stable trend (as the two population averages
187 are not likely to be exactly equal), but the difference
188 between the two trends is relatively small.
189
190 For medium changes, the detection algorithm may need several new samples
191 to detect a progression (as it dislikes single sample groups),
192 in the meantime reporting regressions (difference decreasing
193 with analysis time), until it stabilizes the same way as for big changes
194 (regression followed by progression, small difference
195 between the old stable trend and last trend).
196
197 As it is very hard for a fault code or an infrastructure issue
198 to increase performance, the opposite (temporary progression)
199 almost never happens.
200
201 ### Summary
202
203 There is a trade-off between detecting small regressions
204 and not reporting the same old regressions for a long time.
205
206 For people reading e-mails, a sudden regression with a big number of samples
207 in the last group means this regression was hard for the algorithm to detect.
208
209 If there is a big regression with just one run in the last group,
210 we are not sure if it is real, or just a temporary issue.
211 It is useful to wait some time before starting an investigation.
212
213 With decreasing (absolute value of) difference, the number of expected runs
214 increases. If there is not enough runs, we still cannot distinguish
215 real regression from temporary regression just from the current metrics
216 (although humans frequently can tell by looking at the graph).
217
218 When there is a regression or progression with just a small difference,
219 it is probably an artifact of a temporary regression.
220 Not worth examining, unless temporary regressions happen somewhat frequently.
221
222 It is not easy for the metrics to locate the previous stable value,
223 especially if multiple anomalies happened in the last few weeks.
224 It is good to compare last trend with long term trend maximum,
225 as it highlights the difference between "now" and "what could be".
226 It is good to exclude last week from the trend maximum,
227 as including the last week would hide all real progressions.
228
229 [^1]: [Minimum Description Length](https://en.wikipedia.org/wiki/Minimum_description_length)
230 [^2]: [Occam's Razor](https://en.wikipedia.org/wiki/Occam%27s_razor)
231 [^3]: [Bimodal Distribution](https://en.wikipedia.org/wiki/Bimodal_distribution)