Repository navigation
Do not open log file with O_SYNC - #5547
Conversation
|
Just checked how it affects runc exec, out of curiosity: A rootless busybox container, with $ hyperfine -N -w 20 -r 300 \
-n before "runc.before --root $R --debug --log $L/before.log exec bench true" \
-n after "runc.after --root $R --debug --log $L/after.log exec bench true" \
-n nolog "runc.after --root $R exec bench true"
| `runc exec` | mean ± σ | max |
|-----------------------|-----------------|---------|
| before (with O_SYNC) | 31.2 ± 4.6 ms | 91.4 ms |
| after (no O_SYNC) | 11.1 ± 1.0 ms | 14.3 ms |
| no `--log` at all | 10.7 ± 1.1 ms | 14.4 ms |A single This is a fast local NVMe drive. On a network-attached cloud volume, where fsync takes milliseconds, the difference should be much bigger. |
9e8879e to
c1586ca
Compare
kolyshkin
left a comment
There was a problem hiding this comment.
(fake review to trigger review-policy check)
|
Review-policy workflow works, giving other maintainers time to review:
So it's either 2 LGTMs or 1 LGTM + 1 week. |
|
I'm shocked how big an impact |
|
Weird, all the checks passed...? |
Logging to a real fs is not the common case. The common cases (when run from podman or docker or some such) are either logging to pipes or to tmpfs. |
The log file is opened with O_SYNC since commit 8f20692 ("Ensure logs are flushed", PR opencontainers#637). The intent was to make sure log entries are not lingering in a buffer, but *os.File is not buffered: logrus does a single Write per entry, which is a single write(2), and the data is visible to any reader (e.g. containerd reading the log after runc exits) as soon as it returns. What O_SYNC actually does is wait for the data to hit the disk on every write, which only helps to preserve the log in case of a host crash or power loss. This is of little value for runc logs, while the cost on a slow disk (e.g. a network-attached cloud volume) is substantial, especially with --debug. Remove O_SYNC. Fixes: opencontainers#5540 Suggested-by: Benjamin Peterson <[email protected]> Signed-off-by: Kir Kolyshkin <[email protected]>
c1586ca to
2b5f516
Compare
Upstream runc is about to make similar change: opencontainers/runc#5547 Signed-off-by: Benjamin Peterson <[email protected]>
The log file is opened with O_SYNC since commit 8f20692 ("Ensure logs
are flushed", PR #637). The intent was to make sure log entries are not
lingering in a buffer, but *os.File is not buffered: logrus does a
single Write per entry, which is a single write(2), and the data is
visible to any reader (e.g. containerd reading the log after runc
exits) as soon as it returns.
What O_SYNC actually does is wait for the data to hit the disk on every
write, which only helps to preserve the log in case of a host crash or
power loss. This is of little value for runc logs, while the cost on a
slow disk (e.g. a network-attached cloud volume) is substantial,
especially with --debug.
Remove O_SYNC.
Fixes: #5540