QueryPlanCache is not using SoftReference which could cause memory starvation & OOM
Description
Attachments
1
- 26 Nov 2014, 02:47 PM
Activity
Show:
Philipp Bach May 18, 2018 at 12:11 PMEdited
We also encountered this issue with hibernate-core 5.2.14.Final. (java 1.8, spring 5.0.5.RELEASE, postgresql)
Our application crashed due to OOM multiple times. After investigation we found that QueryPlanCache used roughly 2GB of memory.
Most of the queries saved in the cache were also duplicates of the same query with different collection sizes for the 'in' clause.
We limited the cache size to 100 entries as workaround for this issue by setting 'hibernate.query.plan_cache_max_size=100' in our jpaProperties.
Details
Details
Assignee
Unassigned
UnassignedReporter
Laurent Schoelens
Laurent SchoelensComponents
Priority
Created November 26, 2014 at 2:47 PM
Updated May 18, 2018 at 12:16 PM
Since QueryCachePlan use some cache for HQLQueryPlan optimisation, it should be possible for the JVM to clear the cache on memory starvation.
Default 2048 entries in queryPlanCache could be easily filled with one request but having in clause with different size of the collection used. (Oracle could have 1000 entries, so it could occupied 1000 entries in the queryPlanCache).
Use case encountered lead to almost 50% of the JVM used by the queryPlanCache map (Xmx1G, queryPlanCache used 470Mo.
Patch provided and tested in condition of an OOM. After GC full WITH GC on SR, queryCachePlan continue to work properly