performance tuning: avoid reflection on the critical path (#4190)
This commit is contained in:
parent
321afae3ea
commit
bfc6202e0d
|
|
@ -21,7 +21,6 @@ import com.alibaba.dubbo.common.URL;
|
|||
import com.alibaba.dubbo.rpc.Invocation;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 2019-04-18
|
||||
|
|
@ -76,8 +75,4 @@ public class RpcUtils extends org.apache.dubbo.rpc.support.RpcUtils {
|
|||
public static boolean isOneway(URL url, Invocation inv) {
|
||||
return org.apache.dubbo.rpc.support.RpcUtils.isOneway(url.getOriginalURL(), inv);
|
||||
}
|
||||
|
||||
public static Map<String, String> getNecessaryAttachments(Invocation inv) {
|
||||
return org.apache.dubbo.rpc.support.RpcUtils.getNecessaryAttachments(inv);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,10 +84,6 @@ public interface Constants {
|
|||
|
||||
String ASYNC_KEY = "async";
|
||||
|
||||
String FUTURE_GENERATED_KEY = "future_generated";
|
||||
|
||||
String FUTURE_RETURNTYPE_KEY = "future_returntype";
|
||||
|
||||
String RETURN_KEY = "return";
|
||||
|
||||
String TOKEN_KEY = "token";
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ public class RpcInvocation implements Invocation, Serializable {
|
|||
}
|
||||
|
||||
public RpcInvocation(Method method, Object[] arguments) {
|
||||
this(method.getName(), method.getParameterTypes(), arguments, null, null);
|
||||
this(method, arguments, null);
|
||||
}
|
||||
|
||||
public RpcInvocation(Method method, Object[] arguments, Map<String, String> attachment) {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ import org.apache.dubbo.rpc.Invoker;
|
|||
import org.apache.dubbo.rpc.Result;
|
||||
import org.apache.dubbo.rpc.RpcContext;
|
||||
import org.apache.dubbo.rpc.RpcException;
|
||||
import org.apache.dubbo.rpc.support.RpcUtils;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
|
@ -112,10 +111,7 @@ public abstract class AbstractProxyInvoker<T> implements Invoker<T> {
|
|||
private CompletableFuture<Object> wrapWithFuture (Object value, Invocation invocation) {
|
||||
if (RpcContext.getContext().isAsyncStarted()) {
|
||||
return ((AsyncContextImpl)(RpcContext.getContext().getAsyncContext())).getInternalFuture();
|
||||
} else if (RpcUtils.isReturnTypeFuture(invocation)) {
|
||||
if (value == null) {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
} else if (value instanceof CompletableFuture) {
|
||||
return (CompletableFuture<Object>) value;
|
||||
}
|
||||
return CompletableFuture.completedFuture(value);
|
||||
|
|
|
|||
|
|
@ -27,8 +27,6 @@ import org.apache.dubbo.rpc.RpcInvocation;
|
|||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
|
|
@ -36,7 +34,6 @@ import static org.apache.dubbo.rpc.Constants.$INVOKE;
|
|||
import static org.apache.dubbo.rpc.Constants.$INVOKE_ASYNC;
|
||||
import static org.apache.dubbo.rpc.Constants.ASYNC_KEY;
|
||||
import static org.apache.dubbo.rpc.Constants.AUTO_ATTACH_INVOCATIONID_KEY;
|
||||
import static org.apache.dubbo.rpc.Constants.FUTURE_GENERATED_KEY;
|
||||
import static org.apache.dubbo.rpc.Constants.ID_KEY;
|
||||
import static org.apache.dubbo.rpc.Constants.RETURN_KEY;
|
||||
/**
|
||||
|
|
@ -171,7 +168,12 @@ public class RpcUtils {
|
|||
}
|
||||
|
||||
public static boolean isReturnTypeFuture(Invocation inv) {
|
||||
Class<?> clazz = getReturnType(inv);
|
||||
Class<?> clazz;
|
||||
if (inv instanceof RpcInvocation) {
|
||||
clazz = ((RpcInvocation) inv).getReturnType();
|
||||
} else {
|
||||
clazz = getReturnType(inv);
|
||||
}
|
||||
return (clazz != null && CompletableFuture.class.isAssignableFrom(clazz)) || isGenericAsync(inv);
|
||||
}
|
||||
|
||||
|
|
@ -198,12 +200,4 @@ public class RpcUtils {
|
|||
}
|
||||
return isOneway;
|
||||
}
|
||||
|
||||
public static Map<String, String> getNecessaryAttachments(Invocation inv) {
|
||||
Map<String, String> attachments = new HashMap<>(inv.getAttachments());
|
||||
attachments.remove(ASYNC_KEY);
|
||||
attachments.remove(FUTURE_GENERATED_KEY);
|
||||
return attachments;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,17 +33,16 @@ import org.apache.dubbo.remoting.transport.CodecSupport;
|
|||
import org.apache.dubbo.rpc.Invocation;
|
||||
import org.apache.dubbo.rpc.Result;
|
||||
import org.apache.dubbo.rpc.RpcInvocation;
|
||||
import org.apache.dubbo.rpc.support.RpcUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
|
||||
import static org.apache.dubbo.remoting.Constants.DUBBO_VERSION_KEY;
|
||||
import static org.apache.dubbo.rpc.protocol.dubbo.CallbackServiceCodec.encodeInvocationArgument;
|
||||
import static org.apache.dubbo.rpc.protocol.dubbo.Constants.DECODE_IN_IO_THREAD_KEY;
|
||||
import static org.apache.dubbo.rpc.protocol.dubbo.Constants.DEFAULT_DECODE_IN_IO_THREAD;
|
||||
import static org.apache.dubbo.remoting.Constants.DUBBO_VERSION_KEY;
|
||||
|
||||
/**
|
||||
* Dubbo codec.
|
||||
|
|
@ -186,7 +185,7 @@ public class DubboCodec extends ExchangeCodec {
|
|||
out.writeObject(encodeInvocationArgument(channel, inv, i));
|
||||
}
|
||||
}
|
||||
out.writeObject(RpcUtils.getNecessaryAttachments(inv));
|
||||
out.writeObject(inv.getAttachments());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue