我有一个api,用于在DynamoDB中存储数据,我使用谷歌的ListeningExecutorService提交作业,最终将数据发送给DB。但是cpu利用率很高,我无法调试其中的原因。
以下是代码:
@Timed(AuditConstants.CRITICAL_TIMER_PREFIX + "sendMessage")
public void save(Audit audit) {
Callable callable = new CallableResult(auditRepository,auditDataUtils,audit);
ListenableFuture<Result> future = executorService.submit(callable);
Futures.addCallback(future, new FutureCallback<Result>() {
@Override
public void onSuccess(@Nullable Result result) {
log.info("Successfully sent audit with uuid {} to Dynamo DB", audit.getAuditId());
}
@Override
public void onFailure(Throwable throwable) {
log.info(ERROR_WHILE_SENDING_THE_MESSAGE, throwable);
handleException(audit, throwable);
}
});
}
private void handleException(Audit audit, Throwable ex) {
log.info("Failed talking to Dynamo DB, writing audit with uuid {} to file", audit.getAuditId(), ex);
producerAuditEventsLogger.logToFile(audit);
}CallableResult作业
@Override
public Result call() throws Exception {
try {
AuditData auditData = auditDataUtils.getAuditData(audit);
auditRepository.saveAuditData(auditData);
return new Result(SUCCESS);
} catch (Exception e) {
throw new Exception("There was an error while writing to DB",e);
}
}1300TPS的3个节点(c4x大)的CPU利用率高达70%。
响应时间很短~20 is。
请指导我如何调试,以及建议降低cpu的方法是什么。
谢谢
发布于 2019-11-07 07:33:34
您可以尝试以下方向:
在我看来,您的DB操作导致了这种情况。
https://stackoverflow.com/questions/58743199
复制相似问题