Commit 11a8420
committed
Avoid skipping query stats in case of slow query text/schema collection
Previously the high-frequency stats collection (which occurs every minute,
except at the 10 minute mark) shared a mutex with the full snapshot
collection, in order to record query stats. This effectively meant that
query stats would be missed if the full snapshot took longer than 1
minute, which was observed in practice in the case of very slow query
text file loading (up to 2 minutes by default, higher with changed
settings), or when collecting schema data from many databases (up to 8
minutes total).
Instead, give the high frequency collection its own persisted state
struct and mutex, and move data from that struct during the full
snapshot. Additionally, to improve correctness of statistics, start
each full snapshot by calling the exact same logic that otherwise runs
once a minute. Perform the query text collection afterwards, without
recording statistics at that time.
This effectively means that we are doing an additional pg_stat_statements
access (without query text), but since that only looks at shared memory
and holds the pgss lock very briefly, it should not be a problem, and
avoids incorrect statistics when query text collection is slow (since
pg_stat_statements looks at the statistics after accessing the query text
file).
In passing, improve the correctness of the next query stats collection
after a reset (it had the wrong reference point before), and add a
missing mutex to the state file write (which now also writes out the
separate high frequency state).
An existing short-coming is left for a future improvement (but with an
added note), which is that state file updates only get written every 10
minutes, missing high-frequency updates inbetween in case of crashes.1 parent bd89a1e commit 11a8420
File tree
14 files changed
+312
-244
lines changed- input
- postgres
- output/transform
- runner
- state
14 files changed
+312
-244
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
38 | 62 | | |
39 | 63 | | |
40 | 64 | | |
41 | 65 | | |
42 | 66 | | |
43 | | - | |
44 | 67 | | |
45 | 68 | | |
46 | 69 | | |
47 | 70 | | |
48 | 71 | | |
49 | | - | |
| 72 | + | |
50 | 73 | | |
51 | 74 | | |
52 | 75 | | |
| |||
67 | 90 | | |
68 | 91 | | |
69 | 92 | | |
70 | | - | |
71 | | - | |
| 93 | + | |
| 94 | + | |
72 | 95 | | |
73 | 96 | | |
74 | 97 | | |
| |||
84 | 107 | | |
85 | 108 | | |
86 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
87 | 113 | | |
88 | 114 | | |
89 | 115 | | |
90 | 116 | | |
91 | 117 | | |
92 | 118 | | |
93 | 119 | | |
94 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
95 | 123 | | |
96 | 124 | | |
97 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
98 | 129 | | |
| 130 | + | |
99 | 131 | | |
| 132 | + | |
100 | 133 | | |
101 | 134 | | |
102 | 135 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | 114 | | |
119 | 115 | | |
120 | 116 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
| 272 | + | |
272 | 273 | | |
273 | 274 | | |
274 | 275 | | |
275 | 276 | | |
276 | 277 | | |
277 | 278 | | |
278 | | - | |
| 279 | + | |
279 | 280 | | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
| 281 | + | |
286 | 282 | | |
287 | 283 | | |
288 | 284 | | |
| |||
315 | 311 | | |
316 | 312 | | |
317 | 313 | | |
318 | | - | |
| 314 | + | |
319 | 315 | | |
320 | 316 | | |
321 | 317 | | |
322 | 318 | | |
| 319 | + | |
323 | 320 | | |
324 | 321 | | |
325 | 322 | | |
326 | | - | |
327 | | - | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
328 | 326 | | |
329 | 327 | | |
330 | 328 | | |
331 | | - | |
| 329 | + | |
332 | 330 | | |
333 | 331 | | |
334 | 332 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
173 | | - | |
| 173 | + | |
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
| 97 | + | |
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
112 | 129 | | |
113 | 130 | | |
114 | 131 | | |
115 | 132 | | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
| 133 | + | |
136 | 134 | | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
| 135 | + | |
144 | 136 | | |
145 | 137 | | |
146 | 138 | | |
| |||
153 | 145 | | |
154 | 146 | | |
155 | 147 | | |
156 | | - | |
| 148 | + | |
157 | 149 | | |
158 | 150 | | |
159 | 151 | | |
160 | | - | |
| 152 | + | |
161 | 153 | | |
162 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
163 | 162 | | |
164 | 163 | | |
0 commit comments