Memory allocation using JAVA_OPTS

This is a Java question, but I’ll ask it here anyway because it also pertains to Scala. I have a program that has recently started bogging down and running much more slowly when I changed a parameter to require more memory usage. When I had this problem in the past, I increased the memory allocated to the JVM on Linux using this line in my .bashrc file:

export JAVA_OPTS="-Xmx8192M -Xms8192M"

I just kept doubling the numbers and testing to see what happened. Is there is a better way to determine the best values for these parameters for my computer. Any suggestions? Thanks.

A heap analysis tool such as jvisualvm will track heap usage over time, which should be useful data for deciding.

in practice, I think a lot of us just bump the number up a gig or two if we notice things taking longer than they should.

I wouldn’t bother with -Xms, just -Xmx is sufficient.

Most of us configure this per-repo, rather than systemwide. sbt will read a .jvmopts file if the repo has one. (Many Scala OSS repos have such a file.)

Just to add to what @SethTisue said - if you don’t want to install jvisualvm you can also use jconsole that is installed with the JDK. Might not be as as full featured though.