Search code examples
javajvmgarbage-collectiong1gcsession-cache

what happens when javax.net.ssl.sessionCacheSize becomes full?


I am trying to analyse one of our applications running in production, and currently the value of javax.net.ssl.sessionCacheSize is set to 10000.

we are using java 17 in production, and by default in Java 17, value of javax.net.ssl.sessionCacheSize is set to 20480.

I wanted to understand what happens when this sessionCacheSize becomes full? Does it trigger a GC event (We use G1GC in Prod)? Or application response times would go high? or application won't accept new connect until the existing connections get dropped and cache has some space to create the session?


Solution

  • In Adoptium OpenJDK 17.0.7 (and thus also other OpenJDK derivatives), the session cache is implemented in sun.security.util.MemoryCache, which you should be able to inspect in your IDE. This class uses a LinkedHashMap as an LRU (Least Recently Used) style cache, together with expiration and - optionally - reference tracking . When any method is invoked, it will expunge any cache items which are only softly reachable, and for some methods it will expunge expired entries.

    If after adding new items in the cache, the size exceeds the configured maximum (even after expunging expired entries), it will remove the least recently used items until the cache size is within bounds.

    This by itself does not trigger any GC, but will produce some garbage which will eventually be collected. It will also not prevent new sessions from being created.