设计图片素材网站有哪些,wordpress全功能主题,wordpress 图片链接下载,wordpress做中文官网内容#xff1a;
rpc调用外部服务时#xff0c;需要将req和resp的信息打印出来#xff0c;以便于排查问题。但是有的rpc服务的resp信息过于庞大#xff0c;比如resp中有List信息#xff0c;list很大很大时会导致log.info打印信息时#xff0c;产生GC#xff0c…内容
rpc调用外部服务时需要将req和resp的信息打印出来以便于排查问题。但是有的rpc服务的resp信息过于庞大比如resp中有List信息list很大很大时会导致log.info打印信息时产生GC影响业务
通过将大对象拆分为小对象解决GC耗时过长问题进而解决GC过长对业务的影响TP999过长导致超时、慢sql等
1、背景
正常情况下2M、3M就为大对象。会直接被分配至old region。如果此大对象为日志对象被频繁的加入老年代会引起Full Gc影响接口性能或db性能。
2、解决
将大对象part拆分为小对象再打印这样young gc更快影响更小
3、code实现以List的拆分为例
Slf4j
Component
public class PartLogUtils {public V void partLog(ListV info,int count,Logger logger,String format) {ListListV result splitInfo(info, count);logInfo(result, logger, format);}private V ListListV splitInfo(ListV info, int count) {ListListV result Lists.newArrayList();if (CollectionUtils.isEmpty(info) || info.size() count) {result.add(info);return result;}ListV temp Lists.newArrayList();int index 0;for (V item : info) {index;temp.add(item);if (index % count 0) {result.add(temp);temp Lists.newArrayList();}}if (temp.size() 0) {result.add(temp);}return result;}private V void logInfo(ListV infoList, Logger logger, String format) {for (V item : infoList) {logger.info(format, GsonUtils.toJsonStr(item));}}}类A中使用
private final static Logger logger LoggerFactory.getLogger(A.class);PartLogUtils.partLog(resp, 2000, logger,queryUserInfo:[{}]);4、打印Map对象的优化同理