Commit c58e7d8
filestream: reduce per-scan allocations (#51863)
Two per-file, per-scan allocations are removed:
- fileWatcher.watch resolved the file identity for every file up
front. It is now resolved lazily on first use.
- fileScanner.GetFiles rebuilt its per-scan maps from empty, forcing
repeated grow/rehash allocations on a stable file set. They are now
pre-sized from the previous scan's unique-file count.
Combined effect vs main (go test -bench
'BenchmarkGetFiles|BenchmarkWatchIdle' -benchmem -benchtime=200ms
-count=10):
│ main │ this-commit │
│ sec/op │ sec/op vs base │
GetFiles-14 1.660m ± 16% 1.302m ± 5% -21.55% (p=0.000 n=10)
GetFilesWithFingerprint-14 5.657m ± 9% 4.898m ± 15% -13.42% (p=0.019 n=10)
GetFilesWithFingerprintGrowing/static-14 5.026m ± 14% 4.449m ± 6% -11.49% (p=0.001 n=10)
GetFilesWithFingerprintGrowing/growing-14 6.823m ± 11% 7.775m ± 19% +13.96% (p=0.023 n=10)
WatchIdle/active/path/100_files-14 160.6µ ± 12% 155.9µ ± 6% ~ (p=0.280 n=10)
WatchIdle/active/path/1000_files-14 1.938m ± 12% 1.805m ± 21% ~ (p=0.218 n=10)
WatchIdle/active/path/10000_files-14 27.05m ± 12% 24.65m ± 14% -8.87% (p=0.009 n=10)
WatchIdle/active/fingerprint/100_files-14 439.9µ ± 2% 413.3µ ± 3% -6.04% (p=0.004 n=10)
WatchIdle/active/fingerprint/1000_files-14 5.352m ± 11% 5.300m ± 20% ~ (p=0.853 n=10)
WatchIdle/active/fingerprint/10000_files-14 58.20m ± 6% 59.59m ± 12% ~ (p=0.190 n=10)
WatchIdle/ignored/path/100_files-14 170.0µ ± 9% 140.3µ ± 10% -17.47% (p=0.000 n=10)
WatchIdle/ignored/path/1000_files-14 2.270m ± 9% 1.652m ± 1% -27.23% (p=0.000 n=10)
WatchIdle/ignored/path/10000_files-14 25.86m ± 12% 25.09m ± 10% ~ (p=0.218 n=10)
WatchIdle/ignored/fingerprint/100_files-14 428.7µ ± 14% 398.9µ ± 7% ~ (p=0.218 n=10)
WatchIdle/ignored/fingerprint/1000_files-14 5.107m ± 10% 5.325m ± 15% ~ (p=0.971 n=10)
WatchIdle/ignored/fingerprint/10000_files-14 58.54m ± 10% 56.75m ± 5% ~ (p=0.353 n=10)
geomean 3.486m 3.230m -7.35%
│ main │ this-commit │
│ B/op │ B/op vs base │
GetFiles-14 1.394Mi ± 3% 1.032Mi ± 1% -25.93% (p=0.000 n=10)
GetFilesWithFingerprint-14 2.199Mi ± 3% 1.757Mi ± 4% -20.10% (p=0.000 n=10)
GetFilesWithFingerprintGrowing/static-14 1.611Mi ± 0% 1.275Mi ± 0% -20.87% (p=0.000 n=10)
GetFilesWithFingerprintGrowing/growing-14 5.521Mi ± 0% 5.190Mi ± 0% -5.99% (p=0.000 n=10)
WatchIdle/active/path/100_files-14 121.7Ki ± 0% 101.7Ki ± 0% -16.42% (p=0.000 n=10)
WatchIdle/active/path/1000_files-14 1.452Mi ± 0% 1.108Mi ± 0% -23.64% (p=0.000 n=10)
WatchIdle/active/path/10000_files-14 13.73Mi ± 0% 10.94Mi ± 0% -20.29% (p=0.000 n=10)
WatchIdle/active/fingerprint/100_files-14 172.1Ki ± 0% 152.2Ki ± 0% -11.59% (p=0.000 n=10)
WatchIdle/active/fingerprint/1000_files-14 1.963Mi ± 0% 1.620Mi ± 0% -17.49% (p=0.000 n=10)
WatchIdle/active/fingerprint/10000_files-14 18.72Mi ± 0% 15.94Mi ± 0% -14.88% (p=0.000 n=10)
WatchIdle/ignored/path/100_files-14 121.73Ki ± 0% 98.59Ki ± 0% -19.01% (p=0.000 n=10)
WatchIdle/ignored/path/1000_files-14 1.452Mi ± 0% 1.078Mi ± 0% -25.76% (p=0.000 n=10)
WatchIdle/ignored/path/10000_files-14 13.73Mi ± 0% 10.64Mi ± 0% -22.51% (p=0.000 n=10)
WatchIdle/ignored/fingerprint/100_files-14 172.2Ki ± 0% 133.4Ki ± 0% -22.54% (p=0.000 n=10)
WatchIdle/ignored/fingerprint/1000_files-14 1.964Mi ± 0% 1.436Mi ± 0% -26.86% (p=0.000 n=10)
WatchIdle/ignored/fingerprint/10000_files-14 19.00Mi ± 0% 14.38Mi ± 0% -24.30% (p=0.000 n=10)
geomean 1.721Mi 1.376Mi -20.06%
│ main │ this-commit │
│ allocs/op │ allocs/op vs base │
GetFiles-14 9.155k ± 0% 9.098k ± 0% -0.62% (p=0.000 n=10)
GetFilesWithFingerprint-14 16.34k ± 0% 16.25k ± 0% -0.54% (p=0.000 n=10)
GetFilesWithFingerprintGrowing/static-14 16.09k ± 0% 16.05k ± 0% -0.28% (p=0.000 n=10)
GetFilesWithFingerprintGrowing/growing-14 18.09k ± 0% 18.05k ± 0% -0.25% (p=0.000 n=10)
WatchIdle/active/path/100_files-14 1.452k ± 0% 1.433k ± 0% -1.31% (p=0.000 n=10)
WatchIdle/active/path/1000_files-14 14.09k ± 0% 14.05k ± 0% -0.33% (p=0.000 n=10)
WatchIdle/active/path/10000_files-14 140.3k ± 0% 140.1k ± 0% -0.10% (p=0.000 n=10)
WatchIdle/active/fingerprint/100_files-14 1.956k ± 0% 1.937k ± 0% -0.97% (p=0.000 n=10)
WatchIdle/active/fingerprint/1000_files-14 19.10k ± 0% 19.05k ± 0% -0.25% (p=0.000 n=10)
WatchIdle/active/fingerprint/10000_files-14 190.3k ± 0% 190.2k ± 0% -0.07% (p=0.000 n=10)
WatchIdle/ignored/path/100_files-14 1.452k ± 0% 1.233k ± 0% -15.08% (p=0.000 n=10)
WatchIdle/ignored/path/1000_files-14 14.09k ± 0% 12.05k ± 0% -14.52% (p=0.000 n=10)
WatchIdle/ignored/path/10000_files-14 140.3k ± 0% 120.1k ± 0% -14.36% (p=0.000 n=10)
WatchIdle/ignored/fingerprint/100_files-14 1.956k ± 0% 1.737k ± 0% -11.20% (p=0.000 n=10)
WatchIdle/ignored/fingerprint/1000_files-14 19.10k ± 0% 17.05k ± 0% -10.72% (p=0.000 n=10)
WatchIdle/ignored/fingerprint/10000_files-14 190.3k ± 0% 170.2k ± 0% -10.58% (p=0.000 n=10)
geomean 15.98k 15.14k -5.27%
The map pre-sizing (fileScanner.lastCount) in isolation, benchmarked as
this commit with and without the field:
│ without-lastCount │ with-lastCount │
│ sec/op │ sec/op vs base │
GetFiles-14 1.743m ± 16% 1.293m ± 29% -25.81% (p=0.002 n=10)
GetFilesWithFingerprint-14 5.056m ± 16% 4.905m ± 20% ~ (p=0.529 n=10)
GetFilesWithFingerprintGrowing/static-14 4.642m ± 16% 4.282m ± 19% ~ (p=0.089 n=10)
GetFilesWithFingerprintGrowing/growing-14 8.157m ± 20% 6.981m ± 13% -14.41% (p=0.009 n=10)
WatchIdle/active/path/100_files-14 160.9µ ± 3% 142.1µ ± 4% -11.69% (p=0.000 n=10)
WatchIdle/active/path/1000_files-14 1.997m ± 15% 1.753m ± 8% -12.21% (p=0.001 n=10)
WatchIdle/active/path/10000_files-14 28.54m ± 13% 28.13m ± 17% ~ (p=0.739 n=10)
WatchIdle/active/fingerprint/100_files-14 495.4µ ± 10% 398.5µ ± 7% -19.55% (p=0.000 n=10)
WatchIdle/active/fingerprint/1000_files-14 6.617m ± 14% 5.502m ± 19% -16.86% (p=0.009 n=10)
WatchIdle/active/fingerprint/10000_files-14 58.58m ± 10% 58.93m ± 6% ~ (p=0.796 n=10)
WatchIdle/ignored/path/100_files-14 161.9µ ± 10% 151.9µ ± 10% ~ (p=0.089 n=10)
WatchIdle/ignored/path/1000_files-14 1.915m ± 7% 1.774m ± 8% -7.38% (p=0.015 n=10)
WatchIdle/ignored/path/10000_files-14 25.68m ± 11% 24.15m ± 13% ~ (p=0.218 n=10)
WatchIdle/ignored/fingerprint/100_files-14 431.7µ ± 4% 407.7µ ± 5% -5.54% (p=0.019 n=10)
WatchIdle/ignored/fingerprint/1000_files-14 5.428m ± 21% 4.832m ± 31% -10.98% (p=0.035 n=10)
WatchIdle/ignored/fingerprint/10000_files-14 58.22m ± 7% 55.88m ± 7% ~ (p=0.063 n=10)
geomean 3.551m 3.203m -9.78%
│ without-lastCount │ with-lastCount │
│ B/op │ B/op vs base │
GetFiles-14 1.401Mi ± 3% 1.037Mi ± 5% -25.96% (p=0.000 n=10)
GetFilesWithFingerprint-14 2.117Mi ± 2% 1.755Mi ± 7% -17.11% (p=0.000 n=10)
GetFilesWithFingerprintGrowing/static-14 1.611Mi ± 0% 1.275Mi ± 0% -20.86% (p=0.000 n=10)
GetFilesWithFingerprintGrowing/growing-14 5.521Mi ± 0% 5.190Mi ± 0% -6.00% (p=0.000 n=10)
WatchIdle/active/path/100_files-14 121.7Ki ± 0% 101.7Ki ± 0% -16.45% (p=0.000 n=10)
WatchIdle/active/path/1000_files-14 1.452Mi ± 0% 1.108Mi ± 0% -23.65% (p=0.000 n=10)
WatchIdle/active/path/10000_files-14 13.73Mi ± 0% 10.94Mi ± 0% -20.29% (p=0.000 n=10)
WatchIdle/active/fingerprint/100_files-14 172.1Ki ± 0% 152.2Ki ± 0% -11.59% (p=0.000 n=10)
WatchIdle/active/fingerprint/1000_files-14 1.964Mi ± 0% 1.621Mi ± 0% -17.48% (p=0.000 n=10)
WatchIdle/active/fingerprint/10000_files-14 18.72Mi ± 0% 15.94Mi ± 0% -14.88% (p=0.000 n=10)
WatchIdle/ignored/path/100_files-14 118.60Ki ± 0% 98.60Ki ± 0% -16.86% (p=0.000 n=10)
WatchIdle/ignored/path/1000_files-14 1.421Mi ± 0% 1.078Mi ± 0% -24.14% (p=0.000 n=10)
WatchIdle/ignored/path/10000_files-14 13.42Mi ± 0% 10.64Mi ± 0% -20.75% (p=0.000 n=10)
WatchIdle/ignored/fingerprint/100_files-14 153.3Ki ± 0% 133.4Ki ± 0% -13.00% (p=0.000 n=10)
WatchIdle/ignored/fingerprint/1000_files-14 1.779Mi ± 0% 1.436Mi ± 0% -19.29% (p=0.000 n=10)
WatchIdle/ignored/fingerprint/10000_files-14 17.17Mi ± 2% 14.38Mi ± 2% -16.23% (p=0.000 n=10)
geomean 1.677Mi 1.376Mi -17.93%
│ without-lastCount │ with-lastCount │
│ allocs/op │ allocs/op vs base │
GetFiles-14 9.155k ± 0% 9.100k ± 0% -0.61% (p=0.000 n=10)
GetFilesWithFingerprint-14 16.31k ± 0% 16.25k ± 0% -0.33% (p=0.009 n=10)
GetFilesWithFingerprintGrowing/static-14 16.09k ± 0% 16.05k ± 0% -0.29% (p=0.000 n=10)
GetFilesWithFingerprintGrowing/growing-14 18.09k ± 0% 18.05k ± 0% -0.25% (p=0.000 n=10)
WatchIdle/active/path/100_files-14 1.452k ± 0% 1.433k ± 0% -1.31% (p=0.000 n=10)
WatchIdle/active/path/1000_files-14 14.09k ± 0% 14.05k ± 0% -0.33% (p=0.000 n=10)
WatchIdle/active/path/10000_files-14 140.3k ± 0% 140.1k ± 0% -0.10% (p=0.000 n=10)
WatchIdle/active/fingerprint/100_files-14 1.956k ± 0% 1.937k ± 0% -0.97% (p=0.000 n=10)
WatchIdle/active/fingerprint/1000_files-14 19.10k ± 0% 19.05k ± 0% -0.25% (p=0.000 n=10)
WatchIdle/active/fingerprint/10000_files-14 190.3k ± 0% 190.2k ± 0% -0.07% (p=0.000 n=10)
WatchIdle/ignored/path/100_files-14 1.252k ± 0% 1.233k ± 0% -1.52% (p=0.000 n=10)
WatchIdle/ignored/path/1000_files-14 12.09k ± 0% 12.05k ± 0% -0.38% (p=0.000 n=10)
WatchIdle/ignored/path/10000_files-14 120.3k ± 0% 120.1k ± 0% -0.12% (p=0.000 n=10)
WatchIdle/ignored/fingerprint/100_files-14 1.756k ± 0% 1.737k ± 0% -1.08% (p=0.000 n=10)
WatchIdle/ignored/fingerprint/1000_files-14 17.10k ± 0% 17.05k ± 0% -0.27% (p=0.000 n=10)
WatchIdle/ignored/fingerprint/10000_files-14 170.3k ± 0% 170.2k ± 0% -0.08% (p=0.000 n=10)
geomean 15.22k 15.14k -0.50%
(cherry picked from commit c05890c)1 parent d3fa6c7 commit c58e7d8
3 files changed
Lines changed: 161 additions & 102 deletions
File tree
- changelog/fragments
- filebeat/input/filestream
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
209 | | - | |
| 209 | + | |
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
213 | | - | |
| 213 | + | |
| 214 | + | |
214 | 215 | | |
215 | 216 | | |
216 | 217 | | |
| |||
225 | 226 | | |
226 | 227 | | |
227 | 228 | | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | 229 | | |
233 | 230 | | |
234 | 231 | | |
| |||
239 | 236 | | |
240 | 237 | | |
241 | 238 | | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
268 | 252 | | |
269 | | - | |
270 | 253 | | |
271 | 254 | | |
272 | 255 | | |
273 | 256 | | |
274 | 257 | | |
275 | | - | |
| 258 | + | |
276 | 259 | | |
277 | 260 | | |
278 | 261 | | |
279 | 262 | | |
280 | 263 | | |
281 | | - | |
| 264 | + | |
282 | 265 | | |
283 | 266 | | |
284 | 267 | | |
285 | 268 | | |
286 | 269 | | |
287 | 270 | | |
288 | 271 | | |
289 | | - | |
| 272 | + | |
290 | 273 | | |
291 | 274 | | |
292 | 275 | | |
293 | 276 | | |
294 | 277 | | |
295 | 278 | | |
296 | | - | |
| 279 | + | |
297 | 280 | | |
298 | 281 | | |
299 | 282 | | |
| |||
306 | 289 | | |
307 | 290 | | |
308 | 291 | | |
309 | | - | |
310 | | - | |
311 | | - | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
312 | 295 | | |
313 | 296 | | |
314 | 297 | | |
315 | 298 | | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | 299 | | |
321 | 300 | | |
322 | 301 | | |
| |||
446 | 425 | | |
447 | 426 | | |
448 | 427 | | |
449 | | - | |
450 | | - | |
451 | | - | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
452 | 432 | | |
453 | 433 | | |
454 | 434 | | |
| |||
491 | 471 | | |
492 | 472 | | |
493 | 473 | | |
494 | | - | |
495 | | - | |
496 | | - | |
497 | | - | |
498 | | - | |
499 | | - | |
500 | | - | |
501 | | - | |
502 | | - | |
503 | | - | |
504 | | - | |
505 | | - | |
506 | | - | |
507 | | - | |
508 | | - | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
509 | 490 | | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
510 | 495 | | |
511 | | - | |
512 | | - | |
513 | | - | |
514 | | - | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
515 | 499 | | |
516 | 500 | | |
517 | 501 | | |
| |||
569 | 553 | | |
570 | 554 | | |
571 | 555 | | |
572 | | - | |
573 | | - | |
574 | | - | |
575 | | - | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
576 | 560 | | |
577 | 561 | | |
578 | 562 | | |
| |||
635 | 619 | | |
636 | 620 | | |
637 | 621 | | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
638 | 625 | | |
639 | 626 | | |
640 | 627 | | |
| |||
717 | 704 | | |
718 | 705 | | |
719 | 706 | | |
720 | | - | |
| 707 | + | |
| 708 | + | |
721 | 709 | | |
722 | | - | |
| 710 | + | |
723 | 711 | | |
724 | | - | |
| 712 | + | |
725 | 713 | | |
726 | 714 | | |
727 | 715 | | |
| |||
792 | 780 | | |
793 | 781 | | |
794 | 782 | | |
| 783 | + | |
795 | 784 | | |
796 | 785 | | |
797 | 786 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1560 | 1560 | | |
1561 | 1561 | | |
1562 | 1562 | | |
1563 | | - | |
1564 | | - | |
1565 | | - | |
1566 | | - | |
1567 | | - | |
1568 | | - | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
1569 | 1568 | | |
1570 | | - | |
1571 | | - | |
| 1569 | + | |
| 1570 | + | |
1572 | 1571 | | |
1573 | | - | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
1574 | 1577 | | |
1575 | 1578 | | |
1576 | 1579 | | |
| |||
1586 | 1589 | | |
1587 | 1590 | | |
1588 | 1591 | | |
1589 | | - | |
1590 | | - | |
1591 | | - | |
1592 | | - | |
1593 | | - | |
1594 | | - | |
1595 | | - | |
1596 | | - | |
1597 | | - | |
1598 | | - | |
| 1592 | + | |
1599 | 1593 | | |
1600 | 1594 | | |
1601 | 1595 | | |
| |||
1637 | 1631 | | |
1638 | 1632 | | |
1639 | 1633 | | |
1640 | | - | |
1641 | | - | |
1642 | | - | |
1643 | | - | |
1644 | | - | |
1645 | | - | |
1646 | | - | |
1647 | | - | |
1648 | | - | |
1649 | | - | |
| 1634 | + | |
1650 | 1635 | | |
1651 | 1636 | | |
1652 | 1637 | | |
| |||
1667 | 1652 | | |
1668 | 1653 | | |
1669 | 1654 | | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
| 1693 | + | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
| 1719 | + | |
| 1720 | + | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
1670 | 1737 | | |
1671 | 1738 | | |
1672 | 1739 | | |
| |||
0 commit comments