I have a Spring Boot Application that has a scheduled task every two minutes to fetch data from time series and perform some calculations on it via an HTTP request and then store the result back in to time series.
The problem is that with each iteration the memory consumption is increasing. I have tried 2 GB and 4 GB memory for this but its runs out of memory after some time giving heap out memory error. Below is a sample code to give you a general idea of what I am doing.
@Scheduled(cron = "0 0/2 * * * ?")
public void run() {
try {
log.info(new Timestamp(System.currentTimeMillis()).toString() + " -- Starting analytics execution.");
AnalyticResponseModel timeseriesResponse = null;
//Get input for Analytics Execution
timeseriesResponse = retrieveDataPointsCurrent(TagsDataBuffer.TAGS);
//Prepare payload for model execution request
String payload = mapper.writeValueAsString(timeseriesResponse);
RequestBody requestBody = RequestBody.create(JSON, payload);
Request request = new Request.Builder().url(analyticModelURL).header("Content-Type", "application/json")
.header("Accept", "application/json").post(requestBody).build();
if( timeseriesResponse.getData().getTime_series().get("time_stamp").isEmpty()) {
log.error("No Recent Data");
return;
}
dataTimestamp = (long) timeseriesResponse.getData().getTime_series().get("time_stamp").get(0);
log.info(new Timestamp(System.currentTimeMillis()).toString() + " -- Fetching Input data.");
//Execute request
Response response = client.newCall(request).execute();
parseAndSaveOutput( response);
} catch (Exception e) {
log.error(e.getMessage());
}
}
1- How can I inspect where I am leaking the memory and how to do it in cloud foundry 2- Any alternate/better approach