I am using spring boot with JPA Hibernate.
I am monitoring the service for Heap and found that each of my request is taking around 40-50 MB.
So the memory gets increased, after few requests GC runs, it frees the memory and this goes on forever.
So my first question is that is this memory leak?
Also I am trying to find what is causing this. So, I have used Runtime.getRuntime() freeMemory and totalMemory() to identify that around 15MB is getting used when getting one db call and populating projection with it
public interface RecommendationProjection {
public String getType();
public boolean getIsOK();
public int getId();
public int getTagCount();
public double getQuality() ;
public LocalDateTime getLastActivity();
}
and hibernate returns 567 records, so basically what I am getting from DB is list of 567 above projection, But what i dont understand that how could this object take such high memory? Is hibernate causing this?
When using projection, hibernate queries for specific field or fetches all fields from database?
Then I am mapping this domain to DTO, which again uses 15-20MB memory?
this is my DTO
public class RecommendationInfoDTO {
private String type;
private boolean isOK;
private int id;
private int tagCount;
private double quality ;
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss", timezone="IST")
private LocalDateTime lastActivity;
.. getters and setters
}
FYI : For monitoring I am using VisualVM.
Also, is there any tool that can help in such cases?
Which tool I can use?(I have used VisualVM) Also just to test whether actually hibernate / JPA, is taking memory, I have removed the query from JPA and get the same data(more than 500 rows) using SQL(simple JDBC Connection), the memory gets reduced to 3-4 MB.
So now I am sure that JPA is causing this memory bump. Also I have tried to fire the native query using JPA(with @Query and nativeQuery=true), same amount of memory is used(40MB).
Also I have tried to analyze the heap dump but could not get anything out of it as all my DT0 / Objects are using very less memory?
When I am using projection and fetch data from hibernate, does hibernate first fetch all the data and then map with projection OR it just fetches the specific data.
This is my heap dump diff. I amm unable to find anything which causes memory.
I am firing 6 hibernate queries in a request and 3 simple plain mysql queries(using jdbc call)
Issue is just 1 hibernate call. I think some thing is wrong with my hibernate ?