Search code examples
javamemory-leaksopensymphony

How to find memory leak with com.opensymphony.oscache on legacy java application


I have an old legacy Java application that several times per week just starts to be very slow and I have to restart Tomcat.

I checked New Relic Top Transactions and Error logs but I can't find the source of the problem, it seems the top transactions are more a consequence than a source of the problem.

So, I suppose it could be a memory leak and I did a heap dump and tried to analyze it on Eclipse Memory Analyser but I'm having difficulties in identifying the memory leak and if it is really a memory leak.

It seams the problem suspect 1 is com.opensymphony.oscache.web.ServletCache.

These are some of the results of Memory Analyser:

Summary

Histogram

Problem Suspect 1

Also, this is VisualVM monitor:

VisualVM Monitor

Thank you! Any help or guidance with this would be very helpful!

This is oscache.properties file:

cache.memory=true
cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.HashDiskPersistenceListener
cache.path=/home/oscache/tb

Solution

  • Few things that I would suggest to get way with the issue.

    Use disk caching instead of memory cache if your use cases lets you to:

    In the configuration file for oscache

    cache.memory=false
    cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.DiskPersistenceListener
    cache.path=/opt/myapp/cache
    cache.capacity=1000
    

    If the disk cache is not recommended try reducing the cache capacity

    cache.capacity=1000
    

    Please provide the configuration details of the oscache for a better review if possible.

    Update

    The HashDiskPersistenceListener is used when the property cahce.memory=false

    We have two options to try out

    1) provide a value for cache capacity

    cache.capacity=1000 #or a value that covers the usecase
    

    2) make the cache use the disk persistance

    cache.memory=false