You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
User reported that our process is causing high CPU consumption, up to 500% on a linux machine with 128 CPU cores.
Profiling the process (see below image) shows that over 51% of the CPU time used by the process was spent in gopsutil, mainly executing the BootTimeWithContext func
The main issue is in the fact that BootTimeWithContext (which ends up calling ReadLinesOffsetN ) gets executed for every running process on the system! gopsutil/process_linux.go at master · shirou/gopsutil and we have hundreds of processes running on the system.
Moreover, because this is running on a host with 128 cpu cores, the /proc/stat file is larger than normal, causing ReadLinesOffsetN to be significant
The boot time does not change, so the code should NOT recalculate it and call BootTimeWithContext for every process, especially that the ReadLinesOffsetN is proven to be expensive. Instead, we should cache it and reuse it.
To Reproduce
On a host with 128 cpus and hundreds of running , run this 3-5 times in parallel procs, err := process.Processes()
Expected behavior
CPU usage should not exceed 20-30%, instead we are seeing CPU usage reaching 500%
Environment (please complete the following information):
Windows: [paste the result of ver]
Linux: [paste contents of /etc/os-release and the result of uname -a]
Mac OS: [paste the result of sw_vers and uname -a
FreeBSD: [paste the result of freebsd-version -k -r -u and uname -a]
OpenBSD: [paste the result of uname -a]
Additional context
[Cross-compiling? Paste the command you are using to cross-compile and the result of the corresponding go env]
The text was updated successfully, but these errors were encountered:
See #1070 (comment) for why we can't cache BootTimeWithContext. Yes it can change.
In this case, can't we just call it once for each call ProcessesWithContext instead of calling it for each process , this will drastically improve performance, besides, if the clock has changed while ProcessesWithContext is running, then regardless of how it's been called, part of the results will have wrong create time.
In addition , can we have another method that gets the process info, but excludes the create time?
@Lomanic I saw you have suggested unix.Sysinfo why this was not accepted?
Description
User reported that our process is causing high CPU consumption, up to 500% on a linux machine with 128 CPU cores.
Profiling the process (see below image) shows that over 51% of the CPU time used by the process was spent in
gopsutil
, mainly executing theBootTimeWithContext
funcAlthough I was able to slightly optimize ReadLinesOffsetN gopsutil/common.go at master · shirou/gopsutil
From this:
To this:
The main issue is in the fact that
BootTimeWithContext
(which ends up callingReadLinesOffsetN
) gets executed for every running process on the system! gopsutil/process_linux.go at master · shirou/gopsutil and we have hundreds of processes running on the system.Moreover, because this is running on a host with 128 cpu cores, the
/proc/stat
file is larger than normal, causingReadLinesOffsetN
to be significantThe boot time does not change, so the code should NOT recalculate it and call
BootTimeWithContext
for every process, especially that theReadLinesOffsetN
is proven to be expensive. Instead, we should cache it and reuse it.To Reproduce
On a host with 128 cpus and hundreds of running , run this 3-5 times in parallel
procs, err := process.Processes()
Expected behavior
CPU usage should not exceed 20-30%, instead we are seeing CPU usage reaching 500%
Environment (please complete the following information):
ver
]/etc/os-release
and the result ofuname -a
]sw_vers
anduname -a
freebsd-version -k -r -u
anduname -a
]uname -a
]Additional context
[Cross-compiling? Paste the command you are using to cross-compile and the result of the corresponding
go env
]The text was updated successfully, but these errors were encountered: