Enable oppportunistic fd counting fast path#486
Merged
discordianfish merged 2 commits intoprometheus:masterfrom Mar 7, 2023
Merged
Enable oppportunistic fd counting fast path#486discordianfish merged 2 commits intoprometheus:masterfrom
discordianfish merged 2 commits intoprometheus:masterfrom
Conversation
Existing slow path takes ~725ms of CPU time on my laptopto count 1 million open files. Compare this to just 0.25ms for the baseline, when no extra files are open by a Go program: ``` Open files reported: 7 Gathered metrics in 0.26ms Open files reported: 1000007 Gathered metrics in 724.50ms ``` Adding fastpath from Linux v6.2 makes it fast: ``` Open files reported: 6 Gathered metrics in 0.29ms Open files reported: 1000006 Gathered metrics in 0.31ms ``` This is before taking in account any lock contention effects in the kernel if you try to count files from multiple threads concurrently, which makes the slow path even slower, burning a lot more CPU in the process. See: * torvalds/linux@f1f1f2569901 Signed-off-by: Ivan Babrou <[email protected]>
56693c8 to
0c0aed6
Compare
Contributor
Author
|
Tests are unhappy: That's because they make |
Member
|
No clear recommendation for the tests.. Might need to restructure this to fix it. |
For some behaviors there is no substitution for real `/proc`. One example is `stat()` for `/proc/<pid>/fd` returning the number of open files for `procfs`. The field has a different meaning on regular filesystems and we need to check for it in tests. Work around this by carrying the fact that `FS` is real in the `FS` struct itself, so that it can be checked where it matters. The realness is determined once per `FS` creation by doing `statfs()` and checking for the `PROC_SUPER_MAGIC` match in the returned fs type. Signed-off-by: Ivan Babrou <[email protected]>
0b5c8ec to
e1da5db
Compare
Contributor
Author
|
I added a commit with a possible solution. I'm not sure if it's a good one, but I can't think of anything better. Initially I hoped for a |
SuperQ
approved these changes
Mar 6, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Existing slow path takes ~725ms of CPU time on my laptopto count 1 million open files. Compare this to just 0.25ms for the baseline, when no extra files are open by a Go program:
Adding fastpath from Linux v6.2 makes it fast:
This is before taking in account any lock contention effects in the kernel if you try to count files from multiple threads concurrently, which makes the slow path even slower, burning a lot more CPU in the process. See:
The code I used