Skip to content

perf improvement in get_process_info for Linux#322

Open
ZhidongPeng wants to merge 2 commits intoAzure:devfrom
ZhidongPeng:linux
Open

perf improvement in get_process_info for Linux#322
ZhidongPeng wants to merge 2 commits intoAzure:devfrom
ZhidongPeng:linux

Conversation

@ZhidongPeng
Copy link
Collaborator

The get_process_info function creates a brand new System::new_with_specifics for every single process lookup. This is extremely inefficient because:

  • System::new_with_specifics with RefreshKind::new().with_processes(...) scans the entire proc filesystem to enumerate ALL processes
  • This happens for every network connection that needs to be authorized
  • The perf profile shows this is spending ~80% of CPU time on syscalls related to proc access

The fix is to replace the sysinfo::System approach with direct /proc/{pid}/ reads, which is much more efficient since we only need to read information for a specific PID, not scan all processes.

Improvement:
Before fix: Captured 3493 samples (0.590 MB)
After fix: Captured 121 samples (0.049 MB)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants