Commit 899467a
authored
perf(loki.source.file): Reduce allocations during file reading (#5405)
### Pull Request Details
There is a lot of allocations being performed while reading files. I can
clearly see this being a hot spot in our internal clusters.
Two of the biggest issues are:
1. We allocate a new pending buffer as soon as we have completed a line
2. We use ReadBytes api causing new allocation for every call that we
just move to pending
Instead we can use `ReadSlice`, this api will not allocate but return a
slice pointing to the internal buffer while still advancing read
position. We copy it into pending so this is fine and we remove the
intermediate allocation done by `ReadBytes`.
We can also reset length of `pending` and this buffer. This is fine
because we never read past newline boundary.
### Issue(s) fixed by this Pull Request
<!-- Fixes #issue_id -->
### Notes to the Reviewer
<!-- Add any relevant notes for the reviewers and testers of this PR.
-->
### PR Checklist
<!-- Remove items that do not apply. For completed items, change [ ] to
[x]. -->
- [ ] Documentation added
- [x] Tests updated
- [ ] Config converters updated1 parent 1834612 commit 899467a
File tree
2 files changed
+50
-21
lines changed- internal/component/loki/source/file/internal/tail
2 files changed
+50
-21
lines changedLines changed: 39 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
472 | 473 | | |
473 | 474 | | |
474 | 475 | | |
475 | | - | |
476 | | - | |
477 | | - | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
478 | 479 | | |
479 | 480 | | |
480 | 481 | | |
| |||
494 | 495 | | |
495 | 496 | | |
496 | 497 | | |
497 | | - | |
498 | | - | |
| 498 | + | |
| 499 | + | |
499 | 500 | | |
500 | 501 | | |
501 | 502 | | |
| |||
548 | 549 | | |
549 | 550 | | |
550 | 551 | | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
Lines changed: 11 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | 83 | | |
88 | 84 | | |
89 | | - | |
| 85 | + | |
90 | 86 | | |
91 | 87 | | |
92 | 88 | | |
| |||
95 | 91 | | |
96 | 92 | | |
97 | 93 | | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
103 | 98 | | |
104 | | - | |
| 99 | + | |
105 | 100 | | |
106 | 101 | | |
107 | 102 | | |
| |||
115 | 110 | | |
116 | 111 | | |
117 | 112 | | |
118 | | - | |
| 113 | + | |
119 | 114 | | |
120 | 115 | | |
121 | 116 | | |
| |||
142 | 137 | | |
143 | 138 | | |
144 | 139 | | |
145 | | - | |
146 | | - | |
147 | | - | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
148 | 143 | | |
149 | 144 | | |
150 | 145 | | |
| |||
0 commit comments