我有一个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-如何检查内存泄漏的位置以及如何在cloud foundry 2中执行此操作-任何替代/更好的方法
发布于 2018-11-07 13:06:51
在检查了代码并尝试了不同的东西之后,似乎用于将数据摄取到时间序列的代码正在泄漏内存。我在每次迭代中初始化租户,但由于某种原因,租户没有被垃圾回收。因此,我尝试了单例方法,现在内存似乎得到了控制和解决。从上周到现在还没有超过1.3 GB
https://stackoverflow.com/questions/53045358
复制相似问题