Skip to content

Memory leak in WebHandler.AFFORDANCES_CACHE #1405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ravishrathod opened this issue Dec 8, 2020 · 5 comments
Closed

Memory leak in WebHandler.AFFORDANCES_CACHE #1405

ravishrathod opened this issue Dec 8, 2020 · 5 comments
Assignees
Labels
in: core Core parts of the project type: bug
Milestone

Comments

@ravishrathod
Copy link

ravishrathod commented Dec 8, 2020

I recently upgrade my app from a very old version of spring-boot (and hateoas) to the latest boot and hateoas v1.1.2.RELEASE. After this I am seeing a spike in memory usage. Heap dump points to WebHandler.AFFORDANCES_CACHE consuming most of memory. Looking at WebHandler it seems that the cache is never cleared and is unbounded... has anyone faced this issue ?

Here is the link to a simple project which exposes a /users/{id}. If we call this api with enough distinct id values, it causes AFFORDANCES_CACHE to fill up. https://github.com/ravishrathod/spring-hateoas-memory

@odrotbohm odrotbohm changed the title [Question] High memory usage for WebHandler.AFFORDANCES_CACHE Memory leak in WebHandler.AFFORDANCES_CACHE Jan 20, 2021
@odrotbohm odrotbohm self-assigned this Jan 20, 2021
@odrotbohm odrotbohm added this to the 1.3 M2 milestone Jan 20, 2021
@odrotbohm odrotbohm added in: core Core parts of the project type: bug labels Jan 20, 2021
@odrotbohm
Copy link
Member

While technically we're using a ConcurrentReferenceHashMap, which means that it will eventually wipe entries on GC, I'll change the cache to rather be a ConcurrentLruCache limited to 256 entries.

odrotbohm added a commit that referenced this issue Jan 20, 2021
We now use a ConcurrentLruCache limited to 256 entries instead of a ConcurrentReferenceHashMap to cache Affordance instances to prevent the cache from growing unboundedly before GC kicks in.
@wyhasany
Copy link

wyhasany commented Mar 5, 2021

Hi! It looks like this PR makes big performance regression for my project. As there is a contention on LRU cache locks. We're creating thousands of links concurrently and threads have to wait for each other. @odrotbohm could you revert that PR?

Here you can see part of profiling my app:
image

Before that change there is no wall-clock time on that locks.

The reason of that is the ConcurrentReferenceHashMap. It doesn't lock on get() method while ConcurrentLruCache$get uses ReentrantReadWriteLock.

@mprzeor
Copy link

mprzeor commented Mar 5, 2021

@odrotbohm just to show you the scale of the problem that @wyhasany described - we had to downgrade Spring Boot from 2.4.3 to 2.4.1 because average response time in our project increased 10 times, from 7ms to 70ms

Screenshot 2021-03-05 at 21 40 091

@odrotbohm
Copy link
Member

Would you mind opening a new ticket to properly keep track of the problem?

@wyhasany
Copy link

wyhasany commented Mar 8, 2021

@odrotbohm ofc, I'm just doing it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Core parts of the project type: bug
Projects
None yet
Development

No branches or pull requests

4 participants