Expunge stale entries in InternalLoggerRegistry
#3430
Labels
enhancement
Additions or updates to features
performance
Issues or PRs that affect performance, throughput, latency, etc.
InternalLoggerRegistry
is essentially aMap<MessageFactory, Map<String, WeakReference<Logger>>>
. As reported by @tristantarrant in #3399, stale entries are not expunged in its current form. That is, the inner map does not get compacted for entries whose associatedWeakReference
s are reclaimed by the garbage collector. This might cause high memory usage if an excessive amount of ephemeral loggers get registered.Reclaimed references can be tracked by a
ReferenceQueue
passed to theWeakReference::new
and processed as follows:When to run
expungeStaleEntries()
should be decided with care, sinceremoveLogger()
mutates the registry map.On method invocation
All
ILR
methods (getLogger()
,computeIfAbsent()
, etc.) can first try to expunge stale entries.This approach is exercised by
WeakHashMap
itself and in #3427.Pros:
ILR
Cons:
ILR
is not accessed, stale entries will still be kept. Consider an application where allLogger
s are assigned, and a temporary operation creates excessive amount of loggers and completes. All created temporaryLogger
instances will be reclaimed by GC, yet will continue taking space for the associatedMap.Entry<String, WeakReference<Logger>>
.By a janitor thread
ILR
can start a janitor thread listening on theReferenceQueue<Logger>
.Cons:
ILR
must have a life cycle (to start/stop the janitor thread) managed byLoggerContext
.The text was updated successfully, but these errors were encountered: