一次 GC overhead limit exceeded 优化

一次 GC overhead limit exceeded 优化

今天讲讲真实案例, 本项目为批量导入导出 批处理程序,spring batch
程序会读取文件的数据到内存,然后获取内存的数据分批处理。
当数据量不大的时候运行很快, 此次文件数据达到50万,内存就吃不消了,PS:内存4G, 由于机器资源有限 此机部署了很多服务,MQ ,ES 等等,
如果对 Spring batch不了解的 可以参考此处:
万事俱备只欠东风,首先检查 大对象, 发现 大量数据会读取到

 ExecutionContext jobExecContext = chunkContext.getStepContext().getStepExecution()
                        .getJobExecution().getExecutionContext();
                jobExecContext.put("data",newResult);
                return RepeatStatus.FINISHED;

newResult 为查询的 所有处理好的数据
然后:

 EabDatabaseShardingAlgorithm shardingAlgorithm = new EabDatabaseShardingAlgorithm();
        String dbKey = shardingAlgorithm.getDataSourceNameByShardingVal(enterpriseId);
        DataSource dataSource = masterDataSourceMap.get(dbKey);
        return stepBuilderFactory.get("CORPNCREXPORTSTEP" + enterpriseId+System.currentTimeMillis())
                .<Map<String, Object>, String[]>chunk(5000)//处理5000个联系人提交一次事务
                .reader(new BuildItemReader())
                .processor(new SingCorpIncrExprotProcessor(dataSource, enterpriseId, iDepartmentBusiness))
                .writer(singleCorpIncrExproWriter)
                .build();

BuildItemReader 为读取 ExecutionContext 里的数据,
singleCorpIncrExproWriter 这里每次处理5000条往文件写入.

-Xms6144m -Xmx6144m -Xss512k -XX:+UseG1GC 启动程序加上

使用G1收集器,观察GC 完美解决。 关于G1 请自行了解。
在这里插入图片描述

发布了3 篇原创文章 · 获赞 6 · 访问量 99

猜你喜欢

转载自blog.csdn.net/weixin_42274449/article/details/105505600