How can ZGC avoid to scan the large local cache to reduce the concurrent mark time of GC cycle?

278 views Asked by At

There is a 3GB local cache in my service(the total mem of my server is 16GB), by using ZGC in JDK11, I found out that the concurrent mark time is too long in each cycle(almost 5 seconds if there are 2 concurrent threads).

So I'm wondering if there is a way that ZGC just skips marking this local cache?

I have already tried dividing this local cache into two layers of cache, the first layer is Caffeine, and the second layer is off-heap Cache. But it didn't work.

1

There are 1 answers

0
Stephen C On BEST ANSWER

How can ZGC avoid to scan the large local cache to reduce the concurrent mark time of GC cycle?

It can't. ZGC will mark and collect the entire heap and there's no way to change that.

Since ZGC is not generational, it is technically impossible to do a partial collection safely. Any reachable object in the portion of the heap that you don't mark could reference any of the objects in portion that you are collecting. Including any that are not otherwise reachable. So if ZGC didn't mark the entire heap, reachable objects could be deleted!

If your problem is that GC cycles are taking too long, your options are:

  • Increase the number of concurrent GC threads.
  • Decrease heap size.
  • Find and fix any possible external causes of memory and CPU contention; e.g. making sure that you actually have 16GB of actual RAM ... rather than over-committed RAM provided by a hypervisor.

You could also try using G1GC instead.

Or you could rearchitect your service so that you can run multiple instances; e.g. by sharding the data in the service.