bvaisvil / zenith

Zenith - sort of like top or htop but with zoom-able charts, CPU, GPU, network, and disk usage

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

high cpu usage

fkm3 opened this issue · comments

commented

On a Intel i7-9850H (6 core), zenith is using 1-2% CPU according to itself. On a AMD 3995WX (64 core), it is at a steady 30-35% + has a perceptible lag when starting/stopping. It seems like something scaling badly with the CPU count.

Hi there, thanks for reporting your experience.

If you could answer a few questions, it would be helpful to track down what's going on.

  • What OS/version are you running zenith on?
  • What version of zenith are you running and how did you build it? Debug builds could easily cause the issue you're seeing.
  • What --refresh-rate are you using? Smaller ones will use more CPU.
  • Have you tried running with --disable-history? During startup and shutdown reads and writes to the history database. If you have a long history (many hours) this could take a second before shutdown.
  • Another thing to consider is the clock difference on both CPUs. Slower clock speed would make the CPU usage higher though there isn't actually a difference in operation.

I run zenith 24/7 on multiple linux (ubuntu/centos) servers with a similar number of cores, so well tested in that sort of environment. I do think it is unlikely the the number of CPUs is an issue. For example - on linux, reading /proc/cpu is the same no matter how many CPUs there are and on mac it's a single syscall.

Another factor is that the larger number of cores on the machine probably means you're running more processes than the 6 core machine. More processes means more work for zenith to do, so this will definitely increase CPU usage.

commented

What OS/version are you running zenith on?

A debian testing derivative with a 5.18.16 kernel (sorry can't be more specific)

What version of zenith are you running and how did you build it? Debug builds could easily cause the issue you're seeing.

cargo install --git https://github.com/bvaisvil/zenith.git

What --refresh-rate are you using? Smaller ones will use more CPU.

The default (2000ms)

Have you tried running with --disable-history? During startup and shutdown reads and writes to the history database. If you have a long history (many hours) this could take a second before shutdown.

Doesn't seem to help

For example - on linux, reading /proc/cpu is the same no matter how many CPUs there are and on mac it's a single syscall.

Seems like there is some work that scales based on the number of cores, e.g. when reading the frequencies. I'd agree that it doesn't seem to be the issue though.

Another factor is that the larger number of cores on the machine probably means you're running more processes than the 6 core machine. More processes means more work for zenith to do, so this will definitely increase CPU usage.

That's true, it is 432 processes vs 1193. FWIW, the load on both machines is very low while I'm testing this.


I ran perf on zenith and most of the time was spent in on spin locks in the kernel (e.g. native_queued_spin_lock_slowpath). The following patch to the sysinfo crate got me down from 30% to 5%:

--- a/src/linux/system.rs
+++ b/src/linux/system.rs
@@ -559,7 +559,7 @@ fn refresh_procs(
         if pid == 0 {
             let proc_list = Wrap(UnsafeCell::new(proc_list));
             folders
-                .par_iter()
+                .iter()
                 .filter_map(|e| {
                     if let Ok((p, _)) = _get_process_data(
                         e.as_path(),

Thank you very much for looking into this. I ran with your patch and can confirm the improvement in performance!

Okay, I added the patch to my fork of sysinfo. Please let confirm if you see the performance improvements. Did this change a difference for startup/shutdown times for you?

commented

Confirmed, thanks! Shutdown feels fast now. Startup feels faster, but still multiple seconds.

Thanks for your contribution! Feel free to open up another issue for the startup time, it's also worth working on.

Hello,
I am using Zenith v0.13.1 and seeing the same high CPU usage behavior. Is this patch already included in the latest released version of Zenith?
Thanks for this great software =)

I've got to make a new release, which I haven't got around to doing in a while. I'll try to make one soon. The master branch does have the patch, however.