Docker & Nexus - low memory mode for running in containers?

1,864 views
Skip to first unread message

Nicholas Grealy

unread,
May 23, 2018, 10:11:54 PM5/23/18
to Nexus Users
Hi all,

Just a general question, is there anyway to get the Nexus docker image to run in an optimised "low memory" mode?


As you can see from `docker stats`, Nexus is by far the largest memory consumer of my images (fresh install = 10x greater than the 2nd largest by memory, 26x the average).



(Or is this an unavoidable reality?)

Background: I want to run my docker stack in DigitalOcean - pricing is directly related to memory allocated to the machine.

Thanks,

Nick

Łukasz Rżanek

unread,
May 24, 2018, 6:36:40 AM5/24/18
to nickg...@gmail.com, nexus...@glists.sonatype.com
Nexus is a Java-based, so all you can do is to control the memory parameters of JVM. You can adjust that using Docker environment varialble INSTALL4J_ADD_VM_PARAMS, passed to the Install4J startup script. It defaults to pretty reasonable -Xms1200m -Xmx1200m -XX:MaxDirectMemorySize=2g -Djava.util.prefs.userRoot=${NEXUS_DATA}/javaprefs.

To translate that for non-Java people:
  • Use -Xmx to specify the maximum heap size
  • Use -Xms to specify the initial Java heap size
  • Use -Xss to set the Java thread stack size, can be easily skipped
My strong suggestion would be to keep Xmx and Xms values the same as it will optimize memory initialization. As it is currently if you monitor the GC data closely, you will notice that is a relatively short period of time (usually less than an hour), the JVM will eventually increase the heap size to the -Xmx setting. Each time the JVM increases the heap size it must ask the OS for additional memory, which takes time (and thus adds to the response time of any requests that were is process when the GC hit). And, usually, the JVM will never let go of that memory. Therefore, since the JVM will eventually grab the -Xmx memory, you might as well set it to that at the beginning. 
Another point is that with a smaller heap size (starting with -Xms), GCs will happen more often. So by starting with a larger heap initially the GCs will happen not as often.

You can start with those parameters and adjust them as needed. Test often, sometimes Java programs won't run unless you will have a certain amount of memory for them to use...

You can also adjust memory limits of Docker containers, but then we will reach to risky areas. Java, generally speaking, have no clue about your soft-limits of the docker container. There is some work in OpenJDK community to address this, but as far as I know by this time it is still unstable and planned for JDK10 - not sure if they will maintain backward compatibility. 

Now, with Java, it all depends on how the app is initialized and maintain. A very interesting analysis on that you can find here. I will admit I had no time to dig into that, but - in general - what I wrote above is your starting point anyway.

One last thing - it is quite a good idea to experiment with GC config as well AND monitor both GC and memory consumption. For the first I would suggest trying out G1GC with JVM 8 - it might, but not for sure, bring you some optimizations. More details here. For monitoring, any tool that will support remote JMX will do, i.e. DataDog or Prometheus. That will give you an insight into the actual use of the memory, etc.

Hope it helps...

Pozdrawiam serdecznie & Best Regards & Mit freundlichen Grüßen,
-- 
:: Łukasz Rżanek


--
You received this message because you are subscribed to the Google Groups "Nexus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nexus-users...@glists.sonatype.com.
To post to this group, send email to nexus...@glists.sonatype.com.
To view this discussion on the web visit https://groups.google.com/a/glists.sonatype.com/d/msgid/nexus-users/59b03614-fa6e-4564-95aa-6cc834f7e385%40glists.sonatype.com.
For more options, visit https://groups.google.com/a/glists.sonatype.com/d/optout.

Rich Seddon

unread,
May 24, 2018, 8:44:40 AM5/24/18
to Nexus Users
See here for our recommendations:


If you try to run Nexus in a memory constrained environment you will likely run into problems.



To unsubscribe from this group and stop receiving emails from it, send an email to nexus-users+unsubscribe@glists.sonatype.com.

--
You received this message because you are subscribed to the Google Groups "Nexus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nexus-users+unsubscribe@glists.sonatype.com.

To post to this group, send email to nexus...@glists.sonatype.com.
Reply all
Reply to author
Forward
0 new messages