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

Phoenicis Ram Usage #1425

Open
ImperatorS79 opened this issue Oct 16, 2018 · 50 comments
Open

Phoenicis Ram Usage #1425

ImperatorS79 opened this issue Oct 16, 2018 · 50 comments

Comments

@ImperatorS79
Copy link
Contributor

ImperatorS79 commented Oct 16, 2018

Is it normal than phoenicis is using 570 MB or RAM? It seems a lot for me.
2018-10-14-130919_1600x796_scrot

System information

  • software version (git revision) of phoenicis and scripts repositories : a75aee4
  • used lubuntu 18.04
  • used openjdk 8
@qparis
Copy link
Member

qparis commented Oct 16, 2018

Basically you cannot really judge how much memory does it take just by looking at the process: When the OS does not need it, Java will not necesseraly release the memory even if there are free space in the heap. You need to use jmi or visualvm to see how the memory is used.

Also, it seems that there are some garbadge collector that are more likely to release the memory if you want to have a smaller footprint

@plata
Copy link
Collaborator

plata commented Oct 16, 2018

I had a look at Phoenicis with VisualVM once. Didn't really spend too much time with it but @ImperatorS79 if you can figure out that we have unused objects etc. we can try to fix that.

@madoar
Copy link
Collaborator

madoar commented Oct 16, 2018

@ImperatorS79 for how long did you start Phoenicis?
How much RAM does your system have?
In addition to what @qparis mentioned, Java tends to hold onto more RAM if your system has a larger amount of it.

@ImperatorS79
Copy link
Contributor Author

At start phoenicis seems to use 410 MB of memory. This increase if I do to the apps or engine tab and scroll down. This was tested in a VM with 1.5GB of RAM.

@plata
Copy link
Collaborator

plata commented Oct 17, 2018

Probably the miniatures which are created there. Don't know if it makes sense/is possible to lazy load them.

@qparis
Copy link
Member

qparis commented Dec 27, 2018

Same issue here, and even after running several times java.lang.System.gc() in the console, the RAM usage is not reducing. Maybe we should investigate for memory leaks

@qparis
Copy link
Member

qparis commented Dec 27, 2018

After investigation thanks to jconsole, it seems that the RAM usage of Phoenicis always go around 200Mo while the process reserves 700Mo of RAM.

@qparis
Copy link
Member

qparis commented Dec 27, 2018

With -XX:+UseG1GC -XX:MaxHeapFreeRatio=30 -XX:MinHeapFreeRatio=10 -XX:-ShrinkHeapInSteps, the memory seems more stable

@plata
Copy link
Collaborator

plata commented Dec 27, 2018

For me, the real question is why so much memory is reserved even if it is not needed.

@qparis
Copy link
Member

qparis commented Dec 27, 2018

Read this:
https://bugs.openjdk.java.net/browse/JDK-8146436

In fact, with these options, only ~500Mb are reserved and used. So we need to optimize the memory footprint of the app anyway

@qparis
Copy link
Member

qparis commented Dec 27, 2018

If you put MaxHeapFreeRatio and MinHeapFreeRatio to a small value, the memory is almost directly released.

https://nvharikrishna.wordpress.com/2011/08/27/jvm-maxheapfreeratio-minheapfreeratio/

@plata
Copy link
Collaborator

plata commented Dec 27, 2018

If I read it correctly, this happens if there is a lot of fluctuation. I can only imagine the repository loading to be the reason.

@qparis
Copy link
Member

qparis commented Dec 27, 2018

Yes, in fact Java will trade memory to CPU usage. Because it consumes a lot of CPU cycles to release it to the OS

@plata
Copy link
Collaborator

plata commented Dec 27, 2018

We have to profile it (e.g. with VisualVM) to really see what's happening.

@plata
Copy link
Collaborator

plata commented Dec 28, 2018

Check this:
VisualVM

I could also see that these objects are created and destroyed all the time. Without doing anything, the memory usage goes from 20MB to 500MB than back to 20MB and so on.

@qparis
Copy link
Member

qparis commented Dec 28, 2018

What do they contain?

@plata
Copy link
Collaborator

plata commented Dec 28, 2018

I don't know. Also currently know idea where it's coming from.

@madoar
Copy link
Collaborator

madoar commented Dec 28, 2018

It should be a dependency.
Can you find out which one?

@plata
Copy link
Collaborator

plata commented Dec 28, 2018

I'm not sure. Any idea how I can see where the Object is created?

@plata
Copy link
Collaborator

plata commented Dec 28, 2018

I increase the allocation trace size:
trace

Any ideas where that thread might be started?

@madoar
Copy link
Collaborator

madoar commented Dec 28, 2018

As far as I know VisualVM communicates via RMI with the JRE

@plata
Copy link
Collaborator

plata commented Dec 28, 2018

So this is only the debugging overhead... I can see 300MB in the sampler (JavaFX Application thread) but not from where.

@qparis
Copy link
Member

qparis commented Dec 28, 2018

Another notice: If we remove bouncycastle and use a system-wide gnupg, we can save up to 40Mb of RAM

@madoar
Copy link
Collaborator

madoar commented Dec 28, 2018

@qparis how would we use gnupg? I mean it isn't a Java library, right?

@qparis
Copy link
Member

qparis commented Dec 28, 2018

System calls

@madoar
Copy link
Collaborator

madoar commented Dec 28, 2018

Is this something we want to do?
I mean previously we tried to remove as many external dependencies as possible (for example git) and instead use java only solutions.
I think we should continue doing so.

@qparis
Copy link
Member

qparis commented Dec 28, 2018

I don't know what we should do. However, once thing is sure: when popping external processes, you are sure that the memory is fully released when the process is finished.
This is one of the reason why POLv4 memory footprint is so small: a lot of things are done in bash or by other processes.

@plata
Copy link
Collaborator

plata commented Dec 28, 2018

This can only be the very last resort. It should be possible to figure out what's going on here. I had a look at the memory usage of the apps tab and it was not critical at all. I just don't understand why I cannot see the basic memory usage in the profiler.

@ImperatorS79
Copy link
Contributor Author

Tested today: 270 MB at start, 540 MB at the end.

@qparis
Copy link
Member

qparis commented Jun 12, 2019

With Java 12?

@ImperatorS79
Copy link
Contributor Author

With Java 11. I will test with Java 12 if you wish.

@qparis
Copy link
Member

qparis commented Jun 12, 2019

With :
-XX:G1PeriodicGCInterval=5000 -XX:G1PeriodicGCSystemLoadThreshold=0 -XX:MaxHeapFreeRatio=2 -XX:MinHeapFreeRatio=1 -XX:-ShrinkHeapInSteps -Xss196k

@ImperatorS79
Copy link
Contributor Author

I have this when launching phoenicis:

Failed to find library. /usr/share/phoenicis/runtime/lib/jli/libjli.so

It is in my jdk from https://download.java.net/java/GA/jdk12.0.1/69cfe15208a647278a19ef0990eea691/12/GPL/openjdk-12.0.1_linux-x64_bin.tar.gz though.

@qparis
Copy link
Member

qparis commented Jun 12, 2019

Yep, the jpackager you use is not the right one. I have created a script but it does not work yet on Linux

@ImperatorS79
Copy link
Contributor Author

Java12 only: 226-413 MB

Java12 + CL: 230-434 MB

@qparis
Copy link
Member

qparis commented Jun 12, 2019

CL?

@ImperatorS79
Copy link
Contributor Author

With the command line arguments you gave me.

@plata
Copy link
Collaborator

plata commented Jun 12, 2019

So worse?

@ImperatorS79
Copy link
Contributor Author

Well, this is not statistically significant (only 1 test) ^^.

@ImperatorS79
Copy link
Contributor Author

It is weird to start with 270 MB though. And I do not see how the 200 MB more could come from, I mean even 1000 .png's are not that much.

@qparis
Copy link
Member

qparis commented Jun 12, 2019

If you run jvisualvmn you'll see that you have (basically)

  • 70Mo for the heap (i.e. the program itself)
  • 50Mo for the metaspace (I think we can optimize this one)
  • about ~100Mo (maybe a little less) reserved for the JIT compiler so that it can store compiled code to accelerate the program. This can be disabled if you want to try.

and you add a little extra for the JVM itself.

I don't have the exact calculation, we need to dig a little bit further.

@ImperatorS79
Copy link
Contributor Author

ImperatorS79 commented Jun 12, 2019

Well, I think dropping 100 MB would be great (and never go above 200 MB). What is strange is the increase of the ram as I am just displaying miniatures (nothing to do with JIT).

@qparis
Copy link
Member

qparis commented Jun 12, 2019

Never go above 200MB is not possible. Keep in mind that we extract big archives and download big files. Other programs (like POLv4) usually spawn a subprocess to do this, so the memory is allocated but not seen in the task manager.

Have you tried to have a look with visualvm?

@ImperatorS79
Copy link
Contributor Author

ImperatorS79 commented Jun 12, 2019

I meant for regular use (like doing nothing but looking at the available apps ^^).

I am not a java developer and I have never try to look at that.

@Kreyren
Copy link
Contributor

Kreyren commented Jun 12, 2019

like in theory you can make symlinks in /tmp that links to (swap) file for things that doesn't need the processing speed of RAM. 🤔

that's how i usually hotfix running some apps on powerless devices (raspberry Pi, etc..).

EDIT: sorry that i'm trying to help then -.-

@ImperatorS79
Copy link
Contributor Author

What ?

@qparis
Copy link
Member

qparis commented Jun 12, 2019

@ImperatorS79 I think we have clearly something with the miniature. I suspect that the wine miniatures are allocated 1000 times

@PhoenicisOrg PhoenicisOrg deleted a comment from Kreyren Jun 12, 2019
@qparis
Copy link
Member

qparis commented Jun 12, 2019

@ImperatorS79 For your info, with Java 12, the memory is given back to the OS much much more easily:

image

As you can see, the heap is quite optimized (75Mb used)

However, we have to make some progress here:

image

@qparis
Copy link
Member

qparis commented Jun 12, 2019

Also: $ jcmd 76844 VM.native_memory

76844:

Native Memory Tracking:

Total: reserved=5831446KB, committed=292406KB

  •             Java Heap (reserved=4194304KB, committed=76800KB)
                          (mmap: reserved=4194304KB, committed=76800KB) 
    
  •                 Class (reserved=1104088KB, committed=63576KB)
                          (classes #12246)
                          (  instance classes #11404, array classes #842)
                          (malloc=2264KB #29921) 
                          (mmap: reserved=1101824KB, committed=61312KB) 
                          (  Metadata:   )
                          (    reserved=53248KB, committed=52736KB)
                          (    used=51154KB)
                          (    free=1582KB)
                          (    waste=0KB =0.00%)
                          (  Class space:)
                          (    reserved=1048576KB, committed=8576KB)
                          (    used=7610KB)
                          (    free=966KB)
                          (    waste=0KB =0.00%)
    
  •                Thread (reserved=33443KB, committed=33443KB)
                          (thread #43)
                          (stack: reserved=33248KB, committed=33248KB)
                          (malloc=142KB #235) 
                          (arena=53KB #85)
    
  •                  Code (reserved=249002KB, committed=20734KB)
                          (malloc=1314KB #8079) 
                          (mmap: reserved=247688KB, committed=19420KB) 
    
  •                    GC (reserved=212771KB, committed=60015KB)
                          (malloc=23295KB #13959) 
                          (mmap: reserved=189476KB, committed=36720KB) 
    
  •              Compiler (reserved=284KB, committed=284KB)
                          (malloc=155KB #656) 
                          (arena=129KB #5)
    
  •              Internal (reserved=1018KB, committed=1018KB)
                          (malloc=986KB #3615) 
                          (mmap: reserved=32KB, committed=32KB) 
    
  •                 Other (reserved=185KB, committed=185KB)
                          (malloc=185KB #14) 
    
  •                Symbol (reserved=10109KB, committed=10109KB)
                          (malloc=8822KB #270786) 
                          (arena=1287KB #1)
    
  • Native Memory Tracking (reserved=5432KB, committed=5432KB)
    (malloc=216KB #3062)
    (tracking overhead=5216KB)

  •    Shared class space (reserved=17384KB, committed=17384KB)
                          (mmap: reserved=17384KB, committed=17384KB) 
    
  •           Arena Chunk (reserved=3129KB, committed=3129KB)
                          (malloc=3129KB) 
    
  •               Logging (reserved=4KB, committed=4KB)
                          (malloc=4KB #189) 
    
  •             Arguments (reserved=26KB, committed=26KB)
                          (malloc=26KB #496) 
    
  •                Module (reserved=260KB, committed=260KB)
                          (malloc=260KB #2559) 
    
  •             Safepoint (reserved=8KB, committed=8KB)
                          (mmap: reserved=8KB, committed=8KB) 
    

@qparis
Copy link
Member

qparis commented Jun 12, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants