Skip to content
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

new ExpressRunner() 导致内存泄漏 #312

Open
picksta opened this issue Jan 30, 2024 · 4 comments
Open

new ExpressRunner() 导致内存泄漏 #312

picksta opened this issue Jan 30, 2024 · 4 comments

Comments

@picksta
Copy link

picksta commented Jan 30, 2024

线上使用时发现执行ql表达式会产生较严重的内存泄漏,老年代一直增长。原因是每次执行都new一次ExpressRunner(),改成全局变量就好了。请问问为什么新建ExpressRunner会出现内存泄漏。

简单demo:
public class ExpressMain {

public static ExpressRunner runner = new ExpressRunner();

public static void demo1() throws Exception {
    ExpressRunner runner = new ExpressRunner();
    runner.setIgnoreConstChar(true);
    DefaultContext<String, Object> context = new DefaultContext<String, Object>();
    context.put("package_order_cnt_json","234");
    context.put("finishOrderDiscountRate",80);
    context.put("c",3);
    String express = " (package_order_cnt_json!= null  and  (package_order_cnt_json like '%269%' or package_order_cnt_json like '%234%' or package_order_cnt_json like '%111%' or package_order_cnt_json like '%333%' or package_order_cnt_json like '%22%' or package_order_cnt_json like '%5564%' or package_order_cnt_json like '%43%'))\n";
    Object execute = runner.execute(express, context, null, true, false);
    System.out.println(execute);
}


public static void main(String[] args) throws Exception {
    while (true) {
        demo1();
    }

}

}
image

@baoxingjie
Copy link
Contributor

baoxingjie commented Feb 1, 2024 via email

@cying314
Copy link

cying314 commented Mar 10, 2024

那需要并行计算多组表达式,但各组间包含不同宏定义、操作符的情况怎么解决?

宏定义不能像上下文那样在执行表达式时传入,必须设置在runner上。

并且这些宏定义分组还是由决策平台客户端决定的,不能初始化为固定数量的runner单例。

如果以分组粒度去动态创建runner的话,又会出现题主所说的内存泄漏问题。

@MoonNigth
Copy link

版本:3.3.2
跑了五个小时,没有发现明显的内存增加

    @Test
    public  void testWhile() throws Exception {
        while (true) {
            ExpressRunner runner = new ExpressRunner();
            runner.setIgnoreConstChar(true);
            DefaultContext<String, Object> context = new DefaultContext<String, Object>();
            context.put("package_order_cnt_json","234");
            context.put("finishOrderDiscountRate",80);
            context.put("c",3);
            String express = " (package_order_cnt_json!= null  and  (package_order_cnt_json like '%269%' or package_order_cnt_json like '%234%' or package_order_cnt_json like '%111%' or package_order_cnt_json like '%333%' or package_order_cnt_json like '%22%' or package_order_cnt_json like '%5564%' or package_order_cnt_json like '%43%'))\n";
            Object execute = runner.execute(express, context, null, true, false);
            System.out.println(execute);
        }
    }

企业微信截图_17102987902473

企业微信截图_17103200022623

@bbenguo
Copy link

bbenguo commented Jun 4, 2024

runner.execute(express, context, null, true, false);

你这个用例,倒数第二个参数应该填false, 或者执行完毕后执行一下这个 runner.clearExpressCache()

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

5 participants