Question-: Which of the following is true with regards to the Java garbage collection? A. Garbage collection is responsible for cleaning the heap memory area in Java for the objects which are not being used or referred. B. If you have a bigger size of heap memory area then garbage collection would take more time to clean out the object if that area is filled. C. Number of CPU can also affect the performance D. There is only one algorithm on which garbage collection work which is G1
Answer: A, B, C Exp: If you are not a java guy then this might be little difficult for you to understand the garbage collection. In simple words let me explain you whenever new objects are created in Java that has to be stored somewhere. And in case of Java these objects are stored in in heap area. As and when new objects are created those goes into the heap area. The problem is that heap area is your memory area from the RAM. It has a limited size. So once heap area is full, it has to be cleaned. Garbage collection is an algorithm or process in Java which looks for the objects in the memory area, the objects which are not being used or not being referred anywhere then those are eligible for garbage collection. And it would pick this object and do the garbage collection for that object and create a more space for other or new objects to be created in the same heap area. This garbage collection process should run in the background continuously to clean more memory from the Heap area. Having a bigger size of heap area would help in keeping more Java objects in the heap area, but when garbage collection would run it has to clean the more objects.
Whenever garbage collection happen it uses the CPU from your system only and which can cause CPU is not available for doing other activity for the Cassandra database. And you would see that your Cassandra database is not able to perform the operation it should do, the reason is no CPU is available, because more CPU is being used by the garbage collection process, instead of your database operation. There are various parameter which you need to tune, based on the heap size when it should and when it should run etc.
Question-: To run the Cassandra database smoothly, you wanted to have minimum number of GC pauses as well as frequency of garbage collection? A. True B. False
Answer: A
Explanation: in garbage collection you should understand two important things as below
1. Pause time: In Java Garbage Collection tries to free up the memory from the heap area but when it runs, it stop’s the application (in this case Cassandra database processes would be stopped) Which is not good. 2. Throughput: throughput decides how frequently the garbage collection should run, if garbage collection runs more frequently than throughput would be low.
Overall, we wanted to minimize the length of the pauses as well as a frequency of garbage collection. By tuning various Java JVM parameters.
Question-: Wrong data model design can lead to heavy garbage collection? A. True B. False
Answer: A
Explanation: Yes, it is possible that wrongly designed data model is creating lot of garbage data. Means data is created and then deleted frequently. Which can lead to run major compaction in Cassandra and this runs then in the background it also run the Java GC processes to clean up the data which are residing the Java Heap memory. Cassandra memtables and various caches are created in the Java Heap space.