4 ms·
> I have always ended up tuning GC parameters and looking for stray references. I've been doing java for years and the key I've learned about the JVM is to sto
by cogman10 5y ago
> I have always ended up tuning GC parameters and looking for stray references.
I've been doing java for years and the key I've learned about the JVM is to stop tuning GC parameters.
The JVM has incredibly good heuristics provided you let them work. The most you should generally do is pick the algorithm and the heap size (maybe the pause time) doing more should only be done if you've got a large amount of evidence (GClogs) to support such changes. Way too many people shoot themselves in the foot trying to hand craft GC settings.
Beyond that, I've found that application changes are almost always more effective than GC changes. Use the JVMs fantastic telemetry tools (Java flight recorder) and find out what's really going on with your application. Again, grab the data first, optimize, and then remeasure to see what's next.
I've managed plenty of apps with 30+gb heaps and 0 tuning.
- deleted 5y ago[deleted]
- oriolid 5y agoI wish I could say the same. Most times it ended up one of two ways: Either the app is stuck doing GC, or it crashes with OutOfMemoryError: too many this or that handles, open pipes or something else.
- Tainnor 5y agoI don't know what kinds of things you're doing on the JVM, but the only situations where I've seen these kinds of errors were either a) batch jobs on massive amounts of data (which yeah... it figures that they could OOM, not sure how you'd prevent that), or b) a serious error in application logic. In general, I don't really encounter these problems and neither do most other people who write for the JVM.
- pjmlp 5y agoSame here, usually you get that from code that uses new everywhere without any kind of thought regarding proper use of algorithms and data structures.
- smrtinsert 5y agoYou have to work very poorly to get these types of errors.
- cogman10 5y ago> too many this or that handles, open pipes or something else. I'm sorry, but that sort of message is a pretty strong indicator of programmer error. Are you using try-with-resources to properly close out things? Are you creating threads in an unbounded fashion? (new Thread) Are you keeping references to objects for longer than needs be? Have you used Java flight recorder to identify the root cause of you memory pressure or used eclipse MAT to find large long lubed allocations? (Or both?). Are you using finalizes? Those have been STRONGLY discouraged (and for good reason) for decades now.
- oriolid 5y agoNo. I am the poor programmer whose manager forced me to use a library their nephew's dog or someone wrote that does all of those. Except using finalize for closing pipes for subprocesses, that was by Java standard library itself. And keeping references longer than needed, that is every library that implements clever caching, ever. Regarding try-with-resources, RAII was invented for a reason. Java did not copy it, because they seemed to seriously believe that GC is a good substitute. One of the many features of Java is that it is advertised as being easy enough that any idiot can write it, and managers then hire idiots.
- vips7L 5y agoHow do you expect RAII to work in any GC language? It would be non-deterministic. The point of try-with-resources is that it is deterministic and you know when something is closed out. Every GC language has implemented this.
- oriolid 5y agoI would say that RAII is enforced try-with-resources without the extra syntax and releasing memory when resources are released instead of having a garbage collector is a nice performance optimization. C# with "using var" is on the right track, though. Just make RAII default and explicit close/dispose the special case and add syntax for type-deduced immutable values, and I'd be happy.
- 5y ago