bisq-network / bisq2

GNU Affero General Public License v3.0
167 stars 62 forks source link

Consider switching to ZGC #2224

Open UtilFunction opened 3 months ago

UtilFunction commented 3 months ago

Bisq users have been reporting high RAM usage numbers in their task managers. Currently, Bisq and Bisq2 use G1GC, which is currently the default setting of the JVM. Unlike G1GC, ZGC promptly returns memory to the operating system. In addition, ZGC ensures low latency, which could potentially be beneficial in any GUI application.

ZGC has been stable and production-ready since Java 15 and can simply be enabled by adding -XX:+UseZGC to the VM arguments. Since Bisq runs on Java 17, there is no reason not to switch to ZGC and other GUI applications like Bitwig Studio have been successfully running it in production. One could even consider switching to Java 21 in order to benefit from generational ZGC.

I have created a video demonstrating the memory consumption in the OS when using Bisq with G1GC and ZGC in a 4GB VM.

G1GC:

https://github.com/bisq-network/bisq2/assets/81699220/1fb6bf04-b6ee-4df8-a263-1bf37a1117bc

ZGC:

https://github.com/bisq-network/bisq2/assets/81699220/f2a10f6f-b362-464a-983c-b07590eedec5

HenrikJannsen commented 3 months ago

Thanks for the input. It sounded like very good news but on my test environment (M3 macbook) it does not provide good results.

I also tried a setup with java 21 (have not tweaked/updated more than needed to get it running - so there might be headroom for improvements) but it felt considerable slower when switching between a heavy UI screen (offerbook). Here the draft PR: https://github.com/bisq-network/bisq2/pull/2225

Test setup: Animations disabled in Preferences. Fast switching between USD offerbook with about 30 offers and Getting started. With java 21 it feels about double the time for the switching. In the below results there is the log output from the `MemoryReport.logReport' call.

Here are my test results:

Alice - PID 21225, Java 21 with ZGC: Total memory: 2.564 GB; Used memory: 314 MB; Free memory: 2.258 GB; Max memory: 9 GB; No. of threads: 84
Alice2 - PID 21677, Java 21 with ZGC + ZGenerational: Total memory: 3.619 GB; Used memory: 738 MB; Free memory: 2.898 GB; Max memory: 9 GB; No. of threads: 48
Carol - PID 21087, Java 21 with default GC: Total memory: 1.148 GB; Used memory: 393.133 MB; Free memory: 782.867 MB; Max memory: 9 GB; No. of threads: 81

Bob - PID 21246, Java 17 with ZGC: Total memory: 1.967 GB; Used memory: 1.045 GB; Free memory: 944 MB; Max memory: 9 GB; No. of threads: 85
Dave - PID 21080, Java 17 with default GC: Total memory: 1.016 GB; Used memory: 550.426 MB; Free memory: 489.574 MB; Max memory: 9 GB; No. of threads: 82

Screenshot 2024-05-25 at 13 38 56

UtilFunction commented 3 months ago

Thank you, this is an interesting observation. I have performed the same test on a Linux 6.8-based OS and the results were similar to the first test I performed on Windows. I assume this is an issue with ZGC's ARM implementation although it might also be a MacOS issue, can't tell because I do not own a Mac. If the former is the case, I would suggest enabling ZGC on x86 builds only.

Edit: Could you try repeating your test on Java 21 with -XX:+UseZGC -XX:+ZGenerational ?

HenrikJannsen commented 3 months ago

Alice2 in the above results was using ZGenerational.

Yes I can imagine there are OS specific differences.

We are investigating to switch to Java 21 or 22 (https://github.com/bisq-network/bisq2/pull/2225, https://github.com/bisq-network/bisq2/pull/2227) so if we do that we should then run more extensive tests on all major systems to see if ZGC brings improvements.