use pubsub instead of filenotify to follow json logs#19498
use pubsub instead of filenotify to follow json logs#19498LK4D4 merged 2 commits intomoby:masterfrom
Conversation
c863500 to
16c3c51
Compare
|
@mountkin One logs test failed |
16c3c51 to
2ac8db4
Compare
2ac8db4 to
37cb26a
Compare
d0b5a3f to
7835599
Compare
|
@LK4D4 test passed (I rebased and force pushed so the jenkins jobs started again 🏊 Let's see the final result) |
|
I like the general simplification, but the issue is now for every write we have to notify as well. |
|
@cpuguy83 I think the publish is much cheaper than inotify because if no one is running 'docker logs -f' the 'Publish' function does nothing more than locking and unlocking a mutex. And the 'Publish' is only called when a line is fully written to the disk (while inotify might be triggered many times when writing a line, see my debug log in another PR #17606). |
There was a problem hiding this comment.
I would suggest avoiding timeout. Timers is very heavy.
There was a problem hiding this comment.
@LK4D4 addressed. Thanks for pointing out this.
6635882 to
3f1cb58
Compare
|
@cpuguy83 What's your thoughts? |
|
The extra call for every write even when there may not be a reader is a little iffy. This is comparing just writing with the pubsub call and writing without. |
|
@cpuguy83 the current version of 'Publish' function can be optimized a little. If no subscribers the waitgroup allocation can be omitted. |
319b782 to
1106c13
Compare
|
@cpuguy83 Here is the result of my benchmark: filenotify: before mountkin@1106c13: after mountkin@1106c13: Is the overhead after |
|
looks decent |
|
Thanks @mountkin! Yep, I'm good with those results, but I think we need some simplifications in the code. |
daemon/logger/jsonfilelog/read.go
Outdated
There was a problem hiding this comment.
Can we change this name to writeNotify
1106c13 to
988de9c
Compare
988de9c to
ffe1174
Compare
daemon/logger/jsonfilelog/read.go
Outdated
There was a problem hiding this comment.
Seems like we should read to the end of the current file on rotate.
There was a problem hiding this comment.
@cpuguy83 when this channel is readable the file has already been moved away. So reading the current file leads to a "bad file descriptor" error.
I've no idea how to handle this case correctly.
Moreover, it seems that following rotated log never worked correctly before.
|
@thaJeztah sorry for the late response. I'm on holiday these days. I'll look into the failed tests tomorrow. |
|
Oh no worries, enjoy your Holiday! |
ffe1174 to
445d7e5
Compare
inotify event is trigged immediately there's data written to disk. But at the time that the inotify event is received, the json line might not fully saved to disk. If the json decoder tries to decode in such case, an io.UnexpectedEOF will be trigged. We used to retry for several times to mitigate the io.UnexpectedEOF error. But there are still flaky tests caused by the partial log entries. The daemon knows exactly when there are new log entries emitted. We can use the pubsub package to notify all the log readers instead of inotify. Signed-off-by: Shijiang Wei <[email protected]> try to fix broken test. will squash once tests pass Signed-off-by: Shijiang Wei <[email protected]>
Signed-off-by: Shijiang Wei <[email protected]>
445d7e5 to
1e0f1ec
Compare
|
BTW, it seems that the |
|
@mountkin Let's save it for another PR I think, b/c it's going to make this PR difficult to look at, even if in different commits. |
| writer: writer, | ||
| readers: make(map[*logger.LogWatcher]struct{}), | ||
| extra: extra, | ||
| writeNotifier: pubsub.NewPublisher(0, 10), |
There was a problem hiding this comment.
Probably only need 1 here instead of 10, but this should be fine. We'll just end up reading an EOF if there are extra notifications.
|
1 small nit, but I'm fine with it. LGTM |
|
LGTM |
use pubsub instead of filenotify to follow json logs
|
Based on #20327 (comment), this is a regression in 1.10.x, so I'm adding this to the 1.10.2 milestone |
|
ARM tests are failing in TestLogsFollowSlowStdoutConsumer due to this change. |
|
I'm removing this from 1.10.2 as this changes a lot and we'd rather not add more risk than necessary to 1.10.2 |
|
Yeah, this change is definitely slower :( |
|
And that's with the file poller too, not inotify. |
inotify event is trigged immediately there's data written to disk.
But at the time that the inotify event is received, the json line might
not fully saved to disk. If the json decoder tries to decode in such
case, an io.UnexpectedEOF will be trigged.
We used to retry for several times to mitigate the io.UnexpectedEOF error.
But there are still flaky tests caused by the partial log entries.
The daemon knows exactly when there are new log entries emitted. We can
use the pubsub package to notify all the log readers instead of inotify.
BTW: I can't run the test locally because the testing infrastructure seems to be broken on my laptop.
Signed-off-by: Shijiang Wei [email protected]