如何解决需要使用 rxjava 和 hystrix 提高以下代码的性能
我需要帮助以使用 rxjava、hystrix 和 jdbctemplate 提高以下代码的性能。下面的代码需要 20 分钟才能处理 8000 条记录,并且也有内存问题。 我正在尝试从表中获取 100k 产品 ID 并点击其余 api 以获取产品的最新价格信息并将记录插入数据库中的临时表并调用 oracle 程序对最新价格值执行一些操作。 注意:所有以命令结尾的函数都是 hystrix 并返回 Observable 对象,该作业预计每天运行一次。
List<Price> PriceList = new ArrayList<>();
Map<String,String> errorSkus = new HashMap<>();
return Observable.zip(getErrProductsCommands,// error products from prevIoUs run
getEligibleProductsCommands,// expected to return 100k product ids and returns List<String>
(errProduct,eligiableProduct) -> {
LOGGER.info("inside zip ");
eligiableProduct.addAll(errProduct);
updateErrProductCommand(errProduct);// jdbctemplate batchupdate update as processed in error table.
LOGGER.info("eligiableProduct-->{}",eligiableProduct.size());
eligiableProduct.parallelStream().distinct().forEach( // using parallenStream but no improvement
Product -> {
LOGGER.info("Product->{}",Product);
Price Price = priceExternalAPICommand(Product).queue().get();//each external API calls takes 2 secs
if (Price != null) {
PriceList.add(Price);
} else {
errorProduct.put(Product,"Not Found");
}
}
)
return PriceList;
})//zip ends
.flatMap(i -> Observable.zip(insertErrTableCommand(errorSkus),// insert error product in error table of current run,jdbctemplate batchupdate
insertTmpTableCommand(PriceList),(err,stg) -> true))// insert in Temp table as jdbctemplate batchupdate expected products 1 lakh. returns true always
.flatMap(callProc -> callOracleProcCommand)
.doOnError(i -> {
LOGGER.info("doOnError -{0}",i.getCause());
(..send mail);
}).subscribeOn(Schedulers.newThread()).subscribe();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。