You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We think we found a memory leak in Anshar, as we saw heap usage kept growing over time. With profiling we identified SiriValueTransformer.cachedGettersForAdapter map to contain abnormal number of entries (millions of entries and several GB of data). The key in the map is of type GetterKey and this calculates its hashCode() from its two member variables, ValueAdapter.hashCode() and Class.hashCode().
The problem seems to be: ValueAdapter subclasses, including OutboundIdAdapter which is the most used, does not implement hashCode() so it uses the default Object.hashCode(), which usually is unique per object instance. Secondly, every call to MappingAdapterPresets.getOutboundAdapters creates new instances of several ValueAdapters, usually with same values, and this is sometimes called inline in Camel routes. Result of that is that cachedGettersForAdapter map will insert GetterKey on identical adapter instances but with different hash codes, so the map will continously grow and no entries are ever evicted.
The apparent fix could be to implement hashCode() in all ValueAdapter subclasses. But in addition it seems unnecessary to create new instances of these adapters all the time, so MappingAdapterPresets.getOutboundAdapters could either return a kind of singleton list per variation or make sure it is called outside the scope of the message flow and storing it, so that the same instances are always reused.
On a side request, are these adapters always required to run by internal processing, or could there be a way to disable them altogether or at least have configurable which ones to include?
The text was updated successfully, but these errors were encountered:
We think we found a memory leak in Anshar, as we saw heap usage kept growing over time. With profiling we identified
SiriValueTransformer.cachedGettersForAdapter
map to contain abnormal number of entries (millions of entries and several GB of data). The key in the map is of typeGetterKey
and this calculates itshashCode()
from its two member variables,ValueAdapter.hashCode()
andClass.hashCode()
.The problem seems to be:
ValueAdapter
subclasses, includingOutboundIdAdapter
which is the most used, does not implementhashCode()
so it uses the defaultObject.hashCode()
, which usually is unique per object instance. Secondly, every call toMappingAdapterPresets.getOutboundAdapters
creates new instances of severalValueAdapter
s, usually with same values, and this is sometimes called inline in Camel routes. Result of that is thatcachedGettersForAdapter
map will insertGetterKey
on identical adapter instances but with different hash codes, so the map will continously grow and no entries are ever evicted.The apparent fix could be to implement
hashCode()
in allValueAdapter
subclasses. But in addition it seems unnecessary to create new instances of these adapters all the time, soMappingAdapterPresets.getOutboundAdapters
could either return a kind of singleton list per variation or make sure it is called outside the scope of the message flow and storing it, so that the same instances are always reused.On a side request, are these adapters always required to run by internal processing, or could there be a way to disable them altogether or at least have configurable which ones to include?
The text was updated successfully, but these errors were encountered: