[common][linux]: improve readlines performance. #1515
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR will improve the following two points. This idea is based on #1514. Thank you so much.
os.ReadFile()
andstrings.Split()
instead ofReadLinesOffsetN()
oncommon.ReadLines()
/proc/stat
from tail.For 1, previously
ReadLines()
usesReadLinesOffsetN()
. but this function is simply too complicated when reading the entire contents of a file. So just use stdlib.For 2, The
btime
line is usually found at the bottom part of thestat
file. Therefore, I tried to read them in reverse order. It has little effect with my 4 CPUs, but I suspect it will work with more CPUs.BenchmarkBootTimeWithManyCPUs
This PR adds
BenchmarkBootTimeWithManyCPUs
with #1514 stat file which has 80 CPU stat lines. This result seems a significant improvement in performance.TODO
We should add err check on process_linux.go. But it might be break application. So I will open a new PR in order to revert easily.