Commit b4d0479
committed
perf(pruning): skip empty shards + per-shard byte counters
CompactSharded256 and CompactPrefixHex256 sweep the full 256-byte
keyspace once `compaction_interval` is crossed. CometBFT key schemas
("tx.hash", "tx.height", "block.height", event-type prefixes) live in
the lowercase-ASCII zone (~30 of 256 byte values), so ~220 of those
shard sweeps target ranges with zero keys.
Each empty Compact still spins up goleveldb's compaction-scheduling
state and (on populated databases) can trigger background level work.
On a 45 GB tx_index.db with 23k SSTs we observed 275 GB written for
21,935 deleted entries (12.5 MB/entry) — the per-prune sweep was
amplifying ~6× the DB size into write traffic and ~33 GB of OS page
cache.
Three changes:
1. shardHasKeys probe: one IteratorWithOpts(DontFillCache=true).Valid()
per shard, microseconds. Empty shards are skipped, populated ones
proceed unchanged.
2. CompactAndLog now reads /proc/self/io read_bytes/write_bytes around
db.Compact and logs the delta. Pins per-shard amplification cost in
production logs so we can attribute the spike post hoc without a
rebuild. On non-linux the helper returns 0/0 and the log line shows
zero-deltas — no functional change off-linux.
3. WaitTimeBetweenCompactions: 50ms -> 200ms. With skip-empty the
active shard count drops to ~30, so 30 * 200ms = 6s extra pacing
per sweep — well inside the 3h pruner budget — gives the kernel
real time to drain dirty pages between bursts.
Tests:
- TestCompactSharded256_SkipsEmptyShards: seed only 't.*' keys, assert
exactly one shard fires.
- TestCompactSharded256_EmptyDB_NoShardsCompacted: empty DB, zero shards.
- TestCompactPrefixHex256_SkipsEmptyShards: same coverage for prefix-hex.
Existing CompactIntSharded tests untouched (path is height-bounded so
sharding is dense by construction; skip-empty there would never fire).1 parent b940185 commit b4d0479
2 files changed
Lines changed: 147 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| 10 | + | |
9 | 11 | | |
| 12 | + | |
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
| |||
24 | 27 | | |
25 | 28 | | |
26 | 29 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
32 | 35 | | |
33 | 36 | | |
34 | 37 | | |
| |||
146 | 149 | | |
147 | 150 | | |
148 | 151 | | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
149 | 156 | | |
150 | 157 | | |
151 | 158 | | |
152 | 159 | | |
153 | 160 | | |
154 | 161 | | |
155 | 162 | | |
| 163 | + | |
156 | 164 | | |
157 | 165 | | |
158 | 166 | | |
| |||
173 | 181 | | |
174 | 182 | | |
175 | 183 | | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
176 | 193 | | |
177 | 194 | | |
178 | 195 | | |
179 | 196 | | |
180 | 197 | | |
181 | | - | |
| 198 | + | |
| 199 | + | |
182 | 200 | | |
183 | 201 | | |
184 | 202 | | |
185 | 203 | | |
186 | 204 | | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
187 | 210 | | |
188 | 211 | | |
189 | 212 | | |
| 213 | + | |
190 | 214 | | |
191 | 215 | | |
192 | 216 | | |
| |||
203 | 227 | | |
204 | 228 | | |
205 | 229 | | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
206 | 239 | | |
207 | 240 | | |
208 | 241 | | |
209 | 242 | | |
210 | 243 | | |
211 | | - | |
| 244 | + | |
| 245 | + | |
212 | 246 | | |
213 | 247 | | |
214 | 248 | | |
215 | | - | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
216 | 267 | | |
217 | 268 | | |
218 | 269 | | |
219 | 270 | | |
220 | 271 | | |
| 272 | + | |
221 | 273 | | |
222 | 274 | | |
223 | 275 | | |
| 276 | + | |
224 | 277 | | |
225 | 278 | | |
226 | 279 | | |
227 | 280 | | |
228 | 281 | | |
| 282 | + | |
| 283 | + | |
229 | 284 | | |
230 | 285 | | |
231 | 286 | | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
232 | 316 | | |
233 | 317 | | |
234 | 318 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
0 commit comments