Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve AvoidStandyModeService #4060

Merged
merged 1 commit into from
Apr 1, 2020

Conversation

ghubstan
Copy link
Contributor

This change substitutes use of memory efficient, OS supplied sleep/suspend
inhibitor utilities for the silent audio file player on Linux, merges
OSXStandbyModeDisabler functionality into AvoidStandyModeService, and
removes that class.

This change also stops Bisq from running the audio file on OSX; it is
currently running both caffeinate and the silent audio file, and the avoid
standby mode button in the the OSX settings view is currently toggling
the audio player on and off, but not caffeinate. (The only way to shut
down caffeinate is by shutting down Bisq.)

The OSX avoid standby mode button button has not been hidden so a cached
'do not avoid standby mode' preference does not leave the user stuck without
a caffeinate service the next time they start Bisq. (They can use it to
turn caffeinate on, but it can't be used to turn it off without shutting
down Bisq too.)

The avoid standy mode button is now displayed on Linux because the native
inhibitor can be toggled on and off.

There is no change to the avoid shutdown service on Windows and Unix.

OSX and UI related changes are described in the commit message above. An
explanation of Linux OS related changes follows.

On linux hosts, AvoidStandbyService checks for executables
gnome-session-inhibit and systemd-inhibit in that order, then starts
the first found to prevent suspend or sleep while Bisq is running.

To check if an inhibitor is enabled or disabled in a gnome terminal...

$ dbus-send --session --print-reply --dest=org.gnome.SessionManager \
	/org/gnome/SessionManager org.gnome.SessionManager.GetInhibitors

If Bisq falls back to systemd-inhibit on a non gnome desktop...

$ systemd-inhibit --list
$ systemd-inhibit --list | grep Bisq

If neither gnome-session-inhibit nor systemd-inhibit are found, the
standby service falls back to playing the silent audio file.

This does not cover all linux desktop types, but other inhibitors
exist for desktops I have not set up, such as mate. It should not
be difficult to support them.

Off heap memory use reduction varies from machine to (virtual) machine.
On my Ubuntu 18 laptop, playing the audio file to block sleep/suspend
is allocating about 1 GB of native memory per hour via malloc() calls.
On the same machine after warm-up, Bisq's virtual memory usage goes from
10.4 GB to 10.1 GB. (This figure was tracked before the MaxRAM=4g setting
was merged from PR #4048.)

This has been tested on OSX Catalina 10.15, Ubuntu 18 (gnome) and the following VMs

Debian 10.3 (gnome)
Arch Linux 9.2.1 (gnome)
Fedora 31.1.9 (cinnamon)

However, VMs not running an inhibitor or audio file do not always go into suspend mode
as schedules.

This does not work on Windows Cygwin, but minor changes might make it work if
cygwin inhibitor tools like gnome-session-inhibit.exe and mate-session-inhibit.exe
are installed.

Paritally addresses off-heap memory consumption issues #3128, #3657,
#3918, #3917, #3686, #3677

This PR replaces #4049

This change substitutes use of memory efficient, OS supplied sleep/suspend
inhibitor utilties for the silent audio file player on Linux, merges
OSXStandbyModeDisabler functionality into AvoidStandyModeService, and
removes that class.

This change also stops Bisq from running the audio file on OSX;  it is
currently running both caffeinate and the silent audio file, and the avoid
standby mode button in the the OSX settings view is currently toggling
the audio player on and off, but not caffeinate.  (The only way to shut
down caffeinate is by shutting down Bisq.)

The OSX avoid standby mode button button has not been hidden so a cached
'do not avoid standby mode' preference does not leave the user stuck without
a caffeinate service the next time they start Bisq. (They can use it to
turn caffeinate on, but it can't be used to turn it off without shutting
down Bisq too.)

The avoid standy mode button is now displayed on Linux because the native
inhibitor can be toggled on and off.

There is no change to the avoid shutdown service on Windows and Unix.
@ripcurlx ripcurlx requested review from freimair and wiz March 17, 2020 15:30
@ripcurlx
Copy link
Contributor

@wiz @freimair Could you give this a spin?

Copy link
Contributor

@freimair freimair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here on a freshly upgraded Arch linux with gnome shell desktop.

I can confirm that the inhibitor works, although it seems that at least arch linux relies on the systemd mechanics as a primary tool for inhibiting shutdown/hibernate/sleep/...

I further can confirm that disk I/O has dropped by about 50%, at least the read part. Previously, I have seen that the sound file got read very often, it is gone now.

This is a green from me! Thanks for your efforts!

Copy link
Contributor

@ripcurlx ripcurlx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK - Tested it on macOS 10.15.3 and it worked as well.

@ripcurlx
Copy link
Contributor

@ManfredKarrer Do you remember why you used the audio workaround and not caffeinate on macOS? Or was it just the best cross-platform solution to do it like that?

@ripcurlx
Copy link
Contributor

ripcurlx commented Apr 1, 2020

Checked back with Manfred and he doesn't have specific concerns about this change as he didn't use caffeinate in his original solution.

@ripcurlx ripcurlx merged commit a96bfd4 into bisq-network:master Apr 1, 2020
@ripcurlx ripcurlx added this to the v1.3.0 milestone Apr 1, 2020
@ghubstan ghubstan deleted the avoid-standby-mode branch April 1, 2020 11:56
@ghubstan ghubstan restored the avoid-standby-mode branch April 1, 2020 12:01
@ghubstan
Copy link
Contributor Author

ghubstan commented Apr 1, 2020

Trying to reopen this PR to force a new Travis CI build and see if it fixes JDK12 build failure:
Could not resolve com.google.protobuf:protoc:3.10.0

See https://travis-ci.org/github/bisq-network/bisq/jobs/669606673?utm_medium=notification&utm_source=github_status

The JDK 10 build passed, and it also passed on my own JDK11.

@ripcurlx ripcurlx added the is:priority PR or issue marked with this label is up for compensation label Apr 15, 2020
@ghubstan ghubstan deleted the avoid-standby-mode branch April 15, 2020 15:36
@cbeams
Copy link
Contributor

cbeams commented May 6, 2020

I just reviewed this change now, and was initially wondering why we didn't delete the prevent-app-nap-silent-sound.aiff file. Looking deeper, I see that it's still used on Windows. This is mentioned above:

There is no change to the avoid shutdown service on Windows and Unix.

Just wondering: was any investigation done as to how to inhibit sleep on Windows?

@ghubstan
Copy link
Contributor Author

ghubstan commented May 6, 2020

Just wondering: was any investigation done as to how to inhibit sleep on Windows?

@cbeams, I did not investigate how to suspend sleep on Win because don't have a windows OS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is:priority PR or issue marked with this label is up for compensation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants