[QUESTION]:Why frequently use util.RandomSleep? #369
Answered
by
messixukejia
JeffPhoneix
asked this question in
Help
-
LogFileReader 的run协程中, 使用 util.RandomSleep 这种休眠是为了解决什么问题吗? |
Beta Was this translation helpful? Give feedback.
Answered by
messixukejia
Sep 6, 2022
Replies: 2 comments 1 reply
-
主要的处理逻辑在processor process 里,会一直读到文件无换行符,之后会进行sleep 操作,仅仅是一般避免浪费CPU 的考虑, 这部分代码有部分每个文件独立协程,在内存优化方面,如重用对象BLock,以及尽可能避免拷贝等来节省CPU 消耗, 达到在单行采集下逼近CPP部分代码的效率 |
Beta Was this translation helpful? Give feedback.
0 replies
-
“仅仅是一般避免浪费CPU 的考虑” |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
golang实现的LogFileReader,仅仅是在K8s标准输出采集下使用,这里是一种轮询的机制,轮询要有一点时间间隔,降低不必要的系统调用。
而对于K8s文件采集则由c++部分实现,采用了轮询(polling)与事件(inotify)并存的模式进行日志采集,具体原理参见https://mp.weixin.qq.com/s/5j5KJe9BmpZ1tdb-KCx_CQ。