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

dubbo 脚本路由性能问题 #363

Closed
lushiquan opened this issue Dec 30, 2016 · 1 comment
Closed

dubbo 脚本路由性能问题 #363

lushiquan opened this issue Dec 30, 2016 · 1 comment

Comments

@lushiquan
Copy link

lushiquan commented Dec 30, 2016

hi all
小弟有个问题,dubbo的脚本路由ScriptRouter,里面每一个请求都会compile javascripte脚本(在下面@符合处) 这样是不是性能损耗更大,是否可以只需要compile一次就可以了(放在构造方法里面complile),不知道当初作者是怎么考虑的,哪位大哥能解答下么?,下面是dubbo的源码

 @SuppressWarnings("unchecked")
    public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException {
        try {
            List<Invoker<T>> invokersCopy = new ArrayList<Invoker<T>>(invokers);
            Compilable compilable = (Compilable) engine;
            Bindings bindings = engine.createBindings();
            bindings.put("invokers", invokersCopy);
            bindings.put("invocation", invocation);
            bindings.put("context", RpcContext.getContext());
         @   CompiledScript function = compilable.compile(rule);
            Object obj = function.eval(bindings);
            if (obj instanceof Invoker[]) {
                invokersCopy = Arrays.asList((Invoker<T>[]) obj);
            } else if (obj instanceof Object[]) {
                invokersCopy = new ArrayList<Invoker<T>>();
                for (Object inv : (Object[]) obj) {
                    invokersCopy.add((Invoker<T>)inv);
                }
            } else {
                invokersCopy = (List<Invoker<T>>) obj;
            }
            return invokersCopy;
        
    }
@ralf0131
Copy link
Contributor

dup with #390

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

2 participants