Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I wanna do empirical time complexity analysis to a java program. But how do I remove the garbage collection time?
You can disable the garbage collector in Java 11+ using the Epsilon No-Op Garbage Collector, introduced in 'JEP 318: Epsilon: A No-Op Garbage Collector (Experimental)'.
Add the following flag to your java command:
java -XX:+UseEpsilonGC ...
Ensure you understand the limitations of this garbage collector flag (explained in the linked JEP). There is one major caveat:
Once the available Java heap is exhausted, the JVM will shut down.
You could try running with the Epsilon GC; see #concision's answer.
But the empirical complexity for a Java program should include the GC overheads. So maybe a better approach is to make your measurements by running your program repeatedly in the same JVM and averaging the times so that the GC overheads are amortized. Consider using a benchmarking framework like JMH.
See the other answers which directly answer your question, but in general if you want to check performance characteristics, the garbage collector is just one of half a billion things that can mess with your timings.
Use JMH, which will try to mitigate or outright eliminate most of those things, and it will take care of waiting out hotspot warmup and the like. Any benchmark not based around JMH or similar is unlikely to mean much.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
If a distributed computing framework spins up nodes for running Java/ Scala operations then it has to include the JVM in every container. E.g. every Map and Reduce step spawns its own JVM.
How does the efficiency of this instantiation compare to spinning up containers for languages like Python? Is it a question of milliseconds, few seconds, 30 seconds? Does this cost add up in frameworks like Kubernetes where you need to spin up many containers?
I've heard that, much like Alpine Linux is just a few MB, there are stripped down JVMs, but still, there must be a cost. Yet, Scala is the first class citizen in Spark and MR is written in Java.
Linux container technology uses layered filesystems so bigger container images don't generally have a ton of runtime overhead, though you do have to download the image the first time it is used on a node which can potentially add up on truly massive clusters. In general this is not usually a thing to worry about, aside from the well known issues of most JVMs being a bit slow to start up. Spark, however, does not spin up a new container for every operation as you describe. It creates a set of executor containers (pods) which are used for the whole Spark execution run.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Recently, i have noticed some unsual OutOfMemoryError exceptions in the customer logs and a performance issues. It comes probably from JVM (Heap or stack) that using java 8.
My questions are as follows :
1. how can i get the source of the exception?
2. What's the JVM options should i use (in production)?
3. Should i configure the garbage collector's cycle?
Chasing the source of the exception down can be tough in the case where there is a memory leak. You can configure java to do a heap dump when an OutOfMemoryException happens by adding the -XX:+HeapDumpOnOutOfMemoryError flag to your java command. More details about where the heapdump is stored can be found on this question Using HeapDumpOnOutOfMemoryError parameter for heap dump for JBoss. Then the customer can give you the heapdump next time things crash and you can use a tool like Eclipse MAT to see what objects are consuming memory. This will give you a hint as to what is going on.
It's pretty common to use custom heap sizes. How to do this is described in this question What are the Xms and Xmx parameters when starting JVMs? .
Configuring garbage collection should only be done when you are encountering a performance issue. Since the issue is running out of memory and not performance, I would not recommend changing anything here.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am trying to understand the multi-threading concepts. Does the support of multi-threading comes from:
1) From Operating system? (OR)
2) Language itself? (like Java if I am correct)
What is the role of CPU, does multi-threading capability is also due to CPU (not considering the multi-core processors)?
Can there be a scenario where OS or CPU isn't supporting the multi-threading but still possible with language itself?
Can anyone help me understand this?
Understanding java's native threads and the jvm has some information.
Basically, multithreading support comes from both the OS and Java in Java's case. This does not happen for, for instance, Python (the standard CPython has just a wrapper around Linux's threads).
https://superuser.com/questions/740611/what-is-the-difference-between-multithreading-and-hyperthreading details what a CPU does in order to multithread.
In theory, yes, a language can be the implementor of the threading. Depending on how you look at it, C doesn't count on the OS, it does it's own threading (mostly because the OS is written in C). The above link also says this.
The language doing its own threading may not be as efficient as OS-level threading, so OS-threading is preferred and commonly present.
A thread is a sequence of instructions that can be managed independently from other such sequences by a scheduler.
Usually, the scheduler is part of the operating system (for example, Linux's Completely Fair Scheduler).
In some approaches (for example, green threads, stackless Python), the scheduler is part of the language or the runtime environment.
In modern computing environments it is usually the case that the number of threads exceeds the number of CPU cores. This is usually handled through time slicing, when threads take turns running on the available hardware. It is the job of the scheduler to manage that.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
As of Java 8, is G1 a better garbage collector than CMS? Is it advisable to make the switch? What kinds of tuning and testing is needed for such a switch?
As of Java 8, is G1 a better garbage collector than CMS?
Possibly depending on your use case and requirements. In Java 9, G1 will be the default. Whether this is a good idea is a matter of opinion.
Is it advisable to make the switch?
Not unless you have a reason to do so.
What kinds of tuning and testing is needed for such a switch?
I would look to your standard load and stress testing you do now. If you don't have such tests, I would write some to reflect what is important to your application.
In terms of tuning, there is lots of options, which ones are best will depend on your use case.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Or will it be possible in the near future? Can they optimize JVM further and implement even gentler garbage collectors, maybe with some support for lower-level interference?
I could have asked the question if it's possible to develop AAA games, but since AAA games use highly advanced game engines, I thought the barrier to overcome here is to have similarly advanced game engines written to the JVM.
Is it likely that in 5 years we will see games like Assassin's Creed, that are optimized to infinity with the help of C/C++ libraries by necessity, written in Java?
For the most part, the intensive work is done on the GPU and these are getting more powerful all the time.
You can use the GPU from Java already and JavaFX does this as well as a number of CV libraries.
A simple way to get gentiler garbage pauses is to create less garbage. You program will run faster as well.
Another effective technique is to move the bulk of your data off heap. For minecraft server this can reduce the heap size by 80% and significantly reduce the frequency and pause time of collections.
http://vanillajava.blogspot.co.uk/2014/06/minecraft-and-off-heap-memory.html?m=1