8000 Memory leak in SiriValueTransformer · Issue #165 · entur/anshar · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Memory leak in SiriValueTransformer #165
Open
@taasjord

Description

@taasjord

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0