google / guava

Google core libraries for Java
Apache License 2.0
49.75k stars 10.8k forks source link

Guava cache memory leak #1410

Open gissuebot opened 9 years ago

gissuebot commented 9 years ago

Original issue created by rakesh.pulipati on 2013-05-13 at 09:06 AM


I am using guava library 14.0.1 to implement caching service (a web application containing a servlet to put and get values). The web application is deployed on a machine containing 1GB RAM (google backend). The number of write and read operations is huge (50 queries per second).

The amount of RAM used on the machine keeps on increasing even after hitting the maximumSize limit. I suspect memory leak.

Following is the code I am using to create cache

Cache cache = CacheBuilder.newBuilder()
                .expireAfterWrite(1, TimeUnit.DAYS)
                .initialCapacity(2000000)
                .maximumSize(3800000)
                .concurrencyLevel(50)
                .recordStats()
                .build();

Retrieving the values using

Map result = cache.getAllPresent(keys);

Putting values in the cache using

cache.put(key, value);
srain2010 commented 3 years ago

@cpovirk Hi,I find the same problem on guava version 23.0. Does the latest version 30.1.1 solve this? Can I upgrade 23.0 to 30.1.1 to solve it,is 30.1.1 compatible with 23.0?

srain2010 commented 3 years ago

Original issue created by rakesh.pulipati on 2013-05-13 at 09:06 AM

I am using guava library 14.0.1 to implement caching service (a web application containing a servlet to put and get values). The web application is deployed on a machine containing 1GB RAM (google backend). The number of write and read operations is huge (50 queries per second).

The amount of RAM used on the machine keeps on increasing even after hitting the maximumSize limit. I suspect memory leak.

Following is the code I am using to create cache

Cache cache = CacheBuilder.newBuilder()
                .expireAfterWrite(1, TimeUnit.DAYS)
                .initialCapacity(2000000)
                .maximumSize(3800000)
                .concurrencyLevel(50)
                .recordStats()
                .build();

Retrieving the values using

Map result = cache.getAllPresent(keys);

Putting values in the cache using

cache.put(key, value);

Have you solved this now?

srirama-rayaprolu commented 3 years ago

Am also facing the same issue. Is this an understanding issue?

As per the below link, it seems we need to use soft reference. Is this correct, but it affect application performance.

https://jessitron.com/2011/10/06/keeping-your-cache-down-to-size/

Is this correct?

In my case, the cache size is fixed however the HEAP size is increasing and leading OutOfMemory Error.

How to resolve this?

a-omy commented 2 weeks ago

JVM heap size after GC runs may keep grow if keys/values have tendency to grow.

If it still grow, there might be occurrence of Guava cache internal structures growing regardless of data stored. See https://github.com/google/guava/issues/3511#issuecomment-2186500157