需要使用 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 (将#修改为@)