Predix Cloud Foundry应用程序堆内存不足问题



我有一个Spring Boot应用程序,它每两分钟有一个调度任务,从时间序列中提取数据,并通过HTTP请求对其进行一些计算,然后将结果存储回时间序列中。

问题是,每次迭代的内存消耗都在增加。我为此尝试了2 GB和4 GB的内存,但一段时间后内存耗尽,出现堆出内存错误。下面是一个示例代码,让您大致了解我正在做的事情。

@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-我如何检查我在哪里泄漏内存,以及如何在云铸造中进行检查2-任何替代/更好的方法

在查看了代码并尝试了不同的东西之后,用于将数据摄取到时间序列的代码似乎正在泄漏内存。我在每次迭代中都初始化租户,出于某种原因,它没有被垃圾收集。所以,我尝试了单例方法,现在内存似乎得到了控制;解决。自上周以来,它还没有超过1.3 GB

最新更新