I am using ConcurrentHashMap
to cache some short-lived data. That is, there are not many entries in the cache, but insertion and deletion often occur. The problem is that when working under load, GC does not delete java.util.concurrent.ConcurrentHashMap$Node
and they accumulate in heap. Even after the end of the load, they are not cleaned.
My singleton cache-manager
@Component
public class ZipkinTraceCacheManager {
private final Map<String, ZipkinTraceCache> threadCaches = new ConcurrentHashMap<>();
public ZipkinTraceCache getCache(String mainSpanId) {
return threadCaches.get(mainSpanId);
}
public void removeCache(String mainSpanId) {
threadCaches.remove(mainSpanId);
}
public String initNewCache(Span mainSpan) {
ZipkinTraceCache zipkinTraceCache = new ZipkinTraceCache();
zipkinTraceCache.setMainSpan(mainSpan);
String mainSpanId = mainSpan.context().spanId();
threadCaches.put(mainSpanId, zipkinTraceCache);
return mainSpanId;
}
}
As u can see on graph, the minimal value of used heap is growing
After working under load ended, all java.util.concurrent.ConcurrentHashMap$Node
instances still alive