Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

guidance on jvm options in idiomatic scala

OK, I understand that I should benchmark my specific application and blah blah blah, but:

The default JVM settings for -Xmx, the default garbage collector, etc, are defaults that are reasonable defaults for most typical Java programs, and may not be as appropriate for idiomatic Scala code (in part because idiomatic Scala will tend to generate more "garbage").

So I'm looking for recommendations of options to start with. Does the typical Scala program need a higher -Xmx setting? Are certain JVMs better for scala than others? Is a different garbage collector (-XX:+UseParallelGC vs XX:+UseConcMarkSweepGC) usually a safer/better/faster guess/bet/default for Scala than what's usually default in Java? Are there any other options I should think about specifically with regard to Scala code, and in what way?

Since more temporary objects are generated, should more space usually be given to the "young" generation by default? Or should less space usually be given to the young generation to force more frequent garbage collection? What about the other generations?

Of course I'll still need to tweak these things for my specific app, but generally I'm guessing that for a typical Scala program my starting point might be different than what it is in Java.

I do find myself running into out of memory errors and "GC overhead limit reached" in some particular applications, or just having an app spend way too much time in garbage collection pauses. To some extent I'm able to work around these issues by tweaking options, but I'd like to hear about other experiences, general principals, and starting points.

like image 700
nairbv Avatar asked Sep 13 '12 00:09

nairbv


1 Answers

This is coming from a scala user, so purely based on personal experience. In short: I tend to do quite a bit of JVM optimization as I have found that a little effort can get you a long way, but I have not found anything specific to scala.

The JVM defaults are, as you said, reasonable at best. Setting a proper heap size, choosing the correct GC, using the server VM, sizing generations etc. all increases performance for scala applications as much as it will for plain java apps. That is not to say that the profiles for java and scala are identical, just that your actual application will likely have a far larger impact.

The only thing I would expect to matter from the theoretical side would be the size of the new generation, as scala may produce more short-lived garbage, and a larger new generation could help the VM a bit here.

like image 190
sarcan Avatar answered Sep 19 '22 06:09

sarcan