-
Notifications
You must be signed in to change notification settings - Fork 712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
process walker perfs: optimize readLimits and readStats #2491
process walker perfs: optimize readLimits and readStats #2491
Conversation
probe/process/walker_linux.go
Outdated
} | ||
} | ||
for ; pos < len(buf) && buf[pos] != ' '; pos++ { | ||
threads = threads*10 + int(buf[pos]-'0') |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
@alban I don't doubt that the code is much faster now but it's very hard to read. Please try to refactor it. I think that separating the parsing of integers from the space-counting code would already be an improvement. Also, are you sure that parsing ints manually provides an improvement? I would be surprised if the Golang library wasn't optimized in this respect. |
The issue with strconv.Atoi or strconv.ParseInt is that they don't stop parsing when finding a non-digit such as a space and they return an error. The previous code was using strings.Fields to allocate and build a string compatible with strconv.Atoi (containing only the digits without extra spaces). The pprof graphs showed that it was strings.Fields taking the cpu rather than strconv.Atoi but we cannot use Atoi without Fields.
I'll try to refactor this. |
c540424
to
b4b73df
Compare
Code refactored and rebased. Now that #2456 is merged in master, I ran performance tests again to see if this PR was still bringing better perfs. I used the test scenario described in #2461 (comment) Master branchUp to 95660e3 (so #2456 is included) This PRConclusionThe function
Overall, the graphs' titles say respectively:
|
probe/process/walker_linux.go
Outdated
} | ||
|
||
var softLimit uint64 | ||
for ; pos < len(content) && buf[pos] != ' '; pos++ { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
|
||
// parseIntWithSpaces is similar to strconv.ParseInt but stops parsing when | ||
// reading a space instead of returning an error | ||
func parseIntWithSpaces(buf *[]byte, pos *int) (ret int) { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
b4b73df
to
598c6a0
Compare
Fixes #2461