zlatinb / muwire

MuWire file sharing client for I2P
GNU General Public License v3.0
191 stars 27 forks source link

[Feature Request] Setting for Process Priority #126

Closed Searinox closed 2 years ago

Searinox commented 2 years ago

As I've continued using MuWire I noticed there are times when it just sporadically uses considerable CPU over bursts of a few seconds.

I've not had time to trace the issue but I noticed it's something I2P also does on its own now and then.

Since some prefer to have MuWire running in the background and sharing non-stop and can slow down other programs you may be focusing on, I figured it would be a good idea to provide an option to set application priority - at least between Normal, Below Normal and Low - would be nice.

I can already do this easily with a VBscript that launches the MuWire exe then sets the process prio to Low but it would be nice if there was a native option to do it.

zlatinb commented 2 years ago

I agree it would be useful, and I will look into adding such ability. It is a bit difficult from Java but in the 0.8.12 beta series MuWire already bundles the JNA library so at least in theory it should be possible to do anything that a native app can do.

zlatinb commented 2 years ago

Looking at the documentation:

"For processes that perform background work such as file I/O, network I/O, or data processing, it is not sufficient to adjust the CPU scheduling priority; even an idle CPU priority process can easily interfere with system responsiveness when it uses the disk and memory. Processes that perform background work should use the PROCESS_MODE_BACKGROUND_BEGIN and PROCESS_MODE_BACKGROUND_END values to adjust their resource scheduling priorities"

So instead of adding an option in the GUI I'm going to make MuWire enter background mode when it gets minimized to the system tray and exit that mode when it gets maximized.

Searinox commented 2 years ago

That sounds like it covers RAM and disk usage priority, but does it also cover CPU priority?

zlatinb commented 2 years ago

Ok, after a lot of digging around it turned that going into background mode reduces the working set of the process to 32MB and does not allow it to grow. As a result, the process starts paging memory like crazy and eats up all CPU.

So, in the latest commit (which is not available on GitHub as of right now because who knows why) I had to manually increase the working set to 512MB and allow it grow. This now works ok on my Windows 10 VM.

Also I'm switching to BELOW_NORMAL when minimized (I don't like IDLE) and restoring to NORMAL when window is restored.

You can see the latest commit here and download a .zip here.

Searinox commented 2 years ago

It's catching it when I minimize the application to the taskbar and setting process prio to Low, but not when I close the window via the X icon and it goes to the system tray.

zlatinb commented 2 years ago

Yeah I just fixed that in the very latest commit ("try 3"). Binary here

Searinox commented 2 years ago

Seems to be fine now.