cri: Reduce the cpu usage of the function redirectLogs in cri#5286
cri: Reduce the cpu usage of the function redirectLogs in cri#5286estesp merged 1 commit intocontainerd:masterfrom
Conversation
|
Hi @payall4u. Thanks for your PR. I'm waiting for a containerd member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
53611df to
fea6c39
Compare
|
Build succeeded.
|
fea6c39 to
afd9156
Compare
|
Build succeeded.
|
There was a problem hiding this comment.
How about using bytes.Buffer? Would it be slower than fastJoin()?
There was a problem hiding this comment.
Sure, bytes.Buffer is better. I've changed it.
afd9156 to
3e5f608
Compare
|
Build succeeded.
|
There was a problem hiding this comment.
The name fastBuffer is a bit odd. It is faster then the previous implementation, but once we replace the previous implementation with this one, we cannot compare...
That being said, I don't have a better suggestion. Both buf and lineBuffer are taken.
There was a problem hiding this comment.
lineBuffer better. Sorry, I'm too cautious and made me want to find a meaningful name.
3e5f608 to
92482fa
Compare
|
Build succeeded.
|
|
/ok-to-test |
|
/test |
|
@payall4u: The
Use DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
92482fa to
faa8688
Compare
|
Build succeeded.
|
faa8688 to
9fab104
Compare
|
Build succeeded.
|
9fab104 to
4377d43
Compare
|
Build succeeded.
|
|
@payall4u the CI issue has been fixed. would you rebase the master? sorry for any inconvenient. |
Signed-off-by: Zhiyu Li <[email protected]>
4377d43 to
4bc8f69
Compare
|
Build succeeded.
|
mikebrow
left a comment
There was a problem hiding this comment.
age old issue.. should I optimize for cpu or memory. There should be a switch to choose IMO.
I may be reading your graph wrong, but this looks to be a pretty big hit to the memory footprint / pod? Do I read that right?
I'm sorry. I should add more information on the graph. The flame graph is for cpu usage. It's used to illustrate where the problem is. |
Yes, I was reading the part in your usage that showed after this fix virtual and resident memory footprint was (may be) up by a very large margin.. Some cloud products want to optimize for hosting a large number of small pods/containers. IOW I was asking what is the memory footprint of this change. |
You are right. CRI had to keep a buffer for every container, which length equal to
I will find out what happened here soon. |
|
@mikebrow Hi, Mike. Sorry for the late reply. This should be caused by the golang version. The top results with VIRT are obtained from containerd 1.3.4 (compiled by go1.13) and containerd 1.4 (compiled by go1.15) . The binary will alloc a lot of memory from golang1.14. We can learn from strace and pmap: $ strace -f -e memory ./containerd-master
mmap(NULL, 262144, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f04b1a92000
mmap(NULL, 131072, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f04b1a72000
mmap(NULL, 1048576, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f04b1972000
mmap(NULL, 8388608, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f04b1172000
mmap(NULL, 67108864, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f04ad172000
mmap(NULL, 536870912, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f048d172000
# ...
$ pmap -p $(pidof containerd) -x
# ...
00007f048ae41000 36036 36 36 rw--- [ anon ]
00007f048ae41000 0 0 0 rw--- [ anon ]
00007f048d172000 263680 0 0 ----- [ anon ]
00007f048d172000 0 0 0 ----- [ anon ]
00007f049d2f2000 4 4 4 rw--- [ anon ]
00007f049d2f2000 0 0 0 rw--- [ anon ]
00007f049d2f3000 293564 0 0 ----- [ anon ]
00007f049d2f3000 0 0 0 ----- [ anon ]
# ...If we play on containerd 1.3.4, it won't call mmap for the large memory. BTW we can add a param with a default value to limit the cri log buffer length. |


From #5285
I try to reduce the cpu usage of the function redirectLogs of cri.
Signed-off-by: Zhiyu Li [email protected]