Skip to content

会大量加载类吗?java8 用g1,很快就会导致metaspace满了,然后fullgc #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ryan-shi opened this issue Nov 22, 2018 · 3 comments

Comments

@ryan-shi
Copy link

exp="(cityLevel<4?double(0):cityLevel*-5)+cityFlightNum0.1+cityTrainNum0.4-(totalDist/directDist>1.2?(totalDist/directDist-1.2)*10000:double(0))"
会大量加载类吗?java8 用g1,很快就会导致metaspace满了,然后fullgc,jmap前几名如下:
、、、
5: 19409 1707992 java.lang.reflect.Method
6: 11704 1288432 java.lang.Class
7: 38961 1246752 java.util.concurrent.ConcurrentHashMap$Node
、、、

@killme2008
Copy link
Owner

每个表达式都会生成一个匿名类(java lambda 对应的匿名类),因此如果你的表达式都是动态生成的,那么可能会生成大量的匿名类,占满 metaspace 就会触发 full gc。

如果你的表达式的规模是可控的,建议用 cache 模式或者预编译,参见

https://github.com/killme2008/aviator/wiki#%E7%BC%96%E8%AF%91%E8%A1%A8%E8%BE%BE%E5%BC%8F

@Noodles-Buddy
Copy link

您好,请问我写的AviatorUtil如下:
public static Double doExecute(Integer key, String express,HashMap<String , Object> param)throws CompileExpressionErrorException,ExpressionRuntimeException { Expression expression = AviatorEvaluator.compile(express); if(expression ==null){ throw new CompileExpressionErrorException(String.format("[%s]解析失败", ProdFormulaEnum.getNameByIndex(key))); } Object result = expression.execute(param); return (Double) result; }
其中,每一次试算,会连续调用此doExecute方法30次,举例如下:
//……(30次计算) calcDownPaymentRefundAmt(paramDTO, formulaMap,envMap); //贷款金额 calcLoanAmt(paramDTO, formulaMap,envMap); //手续费基数、保证金基数、管理费基数 calcBaseAmt(paramDTO,envMap); //保证金 calcDepositAmt(paramDTO, formulaMap,envMap); //手续费 calcServiceFeeAmt(paramDTO, formulaMap,envMap); //管理费 calcManageAmt(paramDTO, formulaMap,envMap); //分期的其他金额 calcStageOtherAmt(paramDTO, formulaMap,envMap); //贷款总额 calcLoanTotalAmt(paramDTO, formulaMap,envMap);

  在做压测时,每秒20次试算,老年代垃圾回收很频繁,但是当我每次仅仅计算1个公式,而非30个时,老年代垃圾回收次数为0.
  已经使用了预编译,请问还有什么办法优化一下吗?

@killme2008
Copy link
Owner

请参见上面回复

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants