You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2021/11/25 06:19:56 UTC
[dubbo] 10/45: improve:内存优化
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch release/3.0.14-rpccontext-bugfix
in repository https://gitbox.apache.org/repos/asf/dubbo.git
commit 0426e01a4bed9623cf98c9daafe461dc382caf5d
Author: 未宇 <li...@alibaba-inc.com>
AuthorDate: Tue Sep 22 14:40:45 2020 +0800
improve:内存优化
---
compiler/pom.xml | 2 +-
dubbo-build-tools/pom.xml | 2 +-
.../src/main/java/org/apache/dubbo/common/URL.java | 45 +++++++++++--------
dubbo-dependencies-bom/pom.xml | 2 +-
.../dubbo-dependencies-zookeeper/pom.xml | 2 +-
.../registry/integration/RegistryDirectory.java | 50 +++++++++++-----------
.../registry/dubbo/RegistryDirectoryTest.java | 2 +-
.../dubbo/rpc/listener/ListenerInvokerWrapper.java | 5 ++-
pom.xml | 4 +-
9 files changed, 62 insertions(+), 52 deletions(-)
diff --git a/compiler/pom.xml b/compiler/pom.xml
index e47b575..5ec07c7 100644
--- a/compiler/pom.xml
+++ b/compiler/pom.xml
@@ -26,7 +26,7 @@
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-compiler</artifactId>
- <version>2.7.8-hsf3-3</version>
+ <version>2.7.8-hsf3-4</version>
<packaging>jar</packaging>
diff --git a/dubbo-build-tools/pom.xml b/dubbo-build-tools/pom.xml
index 495e7ac..3e08ebf 100644
--- a/dubbo-build-tools/pom.xml
+++ b/dubbo-build-tools/pom.xml
@@ -20,7 +20,7 @@
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-build-tools</artifactId>
- <version>2.7.8-hsf3-3</version>
+ <version>2.7.8-hsf3-4</version>
<packaging>jar</packaging>
<properties>
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java b/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
index 25d43f6..e1891a3 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
@@ -93,45 +93,45 @@ class URL implements Serializable {
private static final long serialVersionUID = -1985165475234910535L;
- private final String protocol;
+ protected String protocol;
- private final String username;
+ protected String username;
- private final String password;
+ protected String password;
// by default, host to registry
- private final String host;
+ protected String host;
// by default, port to registry
- private final int port;
+ protected int port;
- private final String path;
+ protected String path;
- private final Map<String, String> parameters;
+ protected Map<String, String> parameters;
- private final Map<String, Map<String, String>> methodParameters;
+ protected Map<String, Map<String, String>> methodParameters;
// ==== cache ====
- private volatile transient Map<String, Number> numbers;
+ protected volatile transient Map<String, Number> numbers;
- private volatile transient Map<String, Map<String, Number>> methodNumbers;
+ protected volatile transient Map<String, Map<String, Number>> methodNumbers;
- private volatile transient Map<String, URL> urls;
+ protected volatile transient Map<String, URL> urls;
- private volatile transient String ip;
+ protected volatile transient String ip;
- private volatile transient String full;
+ protected volatile transient String full;
- private volatile transient String identity;
+ protected volatile transient String identity;
- private volatile transient String parameter;
+ protected volatile transient String parameter;
- private volatile transient String string;
+ protected volatile transient String string;
- private transient String serviceKey;
+ protected transient String serviceKey;
- private transient String address;
+ protected transient String address;
protected URL() {
this.protocol = null;
@@ -1635,4 +1635,13 @@ class URL implements Serializable {
subParameter.put(key, value);
}
+ protected void setParameters(Map<String, String> parameters) {
+ this.parameters = parameters;
+ }
+
+ protected void setMethodParameters(Map<String, Map<String, String>> methodParameters) {
+ this.methodParameters = methodParameters;
+ }
+
+
}
diff --git a/dubbo-dependencies-bom/pom.xml b/dubbo-dependencies-bom/pom.xml
index e81552b..5cdb530 100644
--- a/dubbo-dependencies-bom/pom.xml
+++ b/dubbo-dependencies-bom/pom.xml
@@ -163,7 +163,7 @@
<mortbay_jetty_version>6.1.26</mortbay_jetty_version>
<portlet_version>2.0</portlet_version>
<maven_flatten_version>1.1.0</maven_flatten_version>
- <revision>2.7.8-hsf3-3</revision>
+ <revision>2.7.8-hsf3-4</revision>
</properties>
<dependencyManagement>
diff --git a/dubbo-dependencies/dubbo-dependencies-zookeeper/pom.xml b/dubbo-dependencies/dubbo-dependencies-zookeeper/pom.xml
index fa0bba7..658ce35 100644
--- a/dubbo-dependencies/dubbo-dependencies-zookeeper/pom.xml
+++ b/dubbo-dependencies/dubbo-dependencies-zookeeper/pom.xml
@@ -32,7 +32,7 @@
<packaging>pom</packaging>
<properties>
- <revision>2.7.8-hsf3-3</revision>
+ <revision>2.7.8-hsf3-4</revision>
<maven_flatten_version>1.1.0</maven_flatten_version>
</properties>
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java
index 1d33779..e54da94 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java
@@ -124,11 +124,11 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify
private volatile List<Configurator> configurators; // The initial value is null and the midway may be assigned to null, please use the local variable reference
// Map<url, Invoker> cache service url to invoker mapping.
- private volatile Map<String, Invoker<T>> urlInvokerMap; // The initial value is null and the midway may be assigned to null, please use the local variable reference
+ private volatile Map<URL, Invoker<T>> urlInvokerMap; // The initial value is null and the midway may be assigned to null, please use the local variable reference
private volatile List<Invoker<T>> invokers;
// Set<invokerUrls> cache invokeUrls to invokers mapping.
- private volatile Set<URL> cachedInvokerUrls; // The initial value is null and the midway may be assigned to null, please use the local variable reference
+ private volatile List<URL> cachedInvokerUrls; // The initial value is null and the midway may be assigned to null, please use the local variable reference
private static final ConsumerConfigurationListener CONSUMER_CONFIGURATION_LISTENER = new ConsumerConfigurationListener();
private ReferenceConfigurationListener serviceConfigurationListener;
@@ -296,20 +296,20 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify
destroyAllInvokers(); // Close all invokers
} else {
this.forbidden = false; // Allow to access
- Map<String, Invoker<T>> oldUrlInvokerMap = this.urlInvokerMap; // local reference
+ Map<URL, Invoker<T>> oldUrlInvokerMap = this.urlInvokerMap; // local reference
if (invokerUrls == Collections.<URL>emptyList()) {
invokerUrls = new ArrayList<>();
}
if (invokerUrls.isEmpty() && this.cachedInvokerUrls != null) {
invokerUrls.addAll(this.cachedInvokerUrls);
} else {
- this.cachedInvokerUrls = new HashSet<>();
+ this.cachedInvokerUrls = new ArrayList<>(invokerUrls.size());
this.cachedInvokerUrls.addAll(invokerUrls);//Cached invoker urls, convenient for comparison
}
if (invokerUrls.isEmpty()) {
return;
}
- Map<String, Invoker<T>> newUrlInvokerMap = toInvokers(invokerUrls);// Translate url list to Invoker map
+ Map<URL, Invoker<T>> newUrlInvokerMap = toInvokers(invokerUrls);// Translate url list to Invoker map
/**
* If the calculation is wrong, it is not processed.
@@ -401,12 +401,12 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify
* @param urls
* @return invokers
*/
- private Map<String, Invoker<T>> toInvokers(List<URL> urls) {
- Map<String, Invoker<T>> newUrlInvokerMap = new HashMap<>();
+ private Map<URL, Invoker<T>> toInvokers(List<URL> urls) {
+ Map<URL, Invoker<T>> newUrlInvokerMap = new HashMap<>();
if (urls == null || urls.isEmpty()) {
return newUrlInvokerMap;
}
- Set<String> keys = new HashSet<>();
+ Set<URL> keys = new HashSet<>();
String queryProtocols = this.queryMap.get(PROTOCOL_KEY);
for (URL providerUrl : urls) {
// If protocol is configured at the reference side, only the matching protocol is selected
@@ -435,14 +435,14 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify
}
URL url = mergeUrl(providerUrl);
- String key = url.toFullString(); // The parameter urls are sorted
- if (keys.contains(key)) { // Repeated url
+ //String key = url.toFullString(); // The parameter urls are sorted
+ if (keys.contains(url)) { // Repeated url
continue;
}
- keys.add(key);
+ keys.add(url);
// Cache key is url that does not merge with consumer side parameters, regardless of how the consumer combines parameters, if the server url changes, then refer again
- Map<String, Invoker<T>> localUrlInvokerMap = this.urlInvokerMap; // local reference
- Invoker<T> invoker = localUrlInvokerMap == null ? null : localUrlInvokerMap.get(key);
+ Map<URL, Invoker<T>> localUrlInvokerMap = this.urlInvokerMap; // local reference
+ Invoker<T> invoker = localUrlInvokerMap == null ? null : localUrlInvokerMap.get(url);
if (invoker == null) { // Not in the cache, refer again
try {
boolean enabled = true;
@@ -458,13 +458,13 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify
logger.error("Failed to refer invoker for interface:" + serviceType + ",url:(" + url + ")" + t.getMessage(), t);
}
if (invoker != null) { // Put new invoker in cache
- newUrlInvokerMap.put(key, invoker);
+ newUrlInvokerMap.put(url, invoker);
}
} else {
- newUrlInvokerMap.put(key, invoker);
+ newUrlInvokerMap.put(url, invoker);
}
}
- keys.clear();
+ //keys.clear();
return newUrlInvokerMap;
}
@@ -479,7 +479,7 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify
providerUrl = overrideWithConfigurator(providerUrl);
- providerUrl = providerUrl.addParameter(Constants.CHECK_KEY, String.valueOf(false)); // Do not check whether the connection is successful or not, always create Invoker!
+// providerUrl = providerUrl.addParameter(Constants.CHECK_KEY, String.valueOf(false)); // Do not check whether the connection is successful or not, always create Invoker!
// The combination of directoryUrl and override is at the end of notify, which can't be handled here
this.overrideDirectoryUrl = this.overrideDirectoryUrl.addParametersIfAbsent(providerUrl.getParameters()); // Merge the provider side parameters
@@ -531,7 +531,7 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify
* Close all invokers
*/
private void destroyAllInvokers() {
- Map<String, Invoker<T>> localUrlInvokerMap = this.urlInvokerMap; // local reference
+ Map<URL, Invoker<T>> localUrlInvokerMap = this.urlInvokerMap; // local reference
if (localUrlInvokerMap != null) {
for (Invoker<T> invoker : new ArrayList<>(localUrlInvokerMap.values())) {
try {
@@ -552,16 +552,16 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify
* @param oldUrlInvokerMap
* @param newUrlInvokerMap
*/
- private void destroyUnusedInvokers(Map<String, Invoker<T>> oldUrlInvokerMap, Map<String, Invoker<T>> newUrlInvokerMap) {
+ private void destroyUnusedInvokers(Map<URL, Invoker<T>> oldUrlInvokerMap, Map<URL, Invoker<T>> newUrlInvokerMap) {
if (newUrlInvokerMap == null || newUrlInvokerMap.size() == 0) {
destroyAllInvokers();
return;
}
// check deleted invoker
- List<String> deleted = null;
+ List<URL> deleted = null;
if (oldUrlInvokerMap != null) {
Collection<Invoker<T>> newInvokers = newUrlInvokerMap.values();
- for (Map.Entry<String, Invoker<T>> entry : oldUrlInvokerMap.entrySet()) {
+ for (Map.Entry<URL, Invoker<T>> entry : oldUrlInvokerMap.entrySet()) {
if (!newInvokers.contains(entry.getValue())) {
if (deleted == null) {
deleted = new ArrayList<>();
@@ -572,7 +572,7 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify
}
if (deleted != null) {
- for (String url : deleted) {
+ for (URL url : deleted) {
if (url != null) {
Invoker<T> invoker = oldUrlInvokerMap.remove(url);
if (invoker != null) {
@@ -649,7 +649,7 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify
if (isDestroyed()) {
return false;
}
- Map<String, Invoker<T>> localUrlInvokerMap = urlInvokerMap;
+ Map<URL, Invoker<T>> localUrlInvokerMap = urlInvokerMap;
if (localUrlInvokerMap != null && localUrlInvokerMap.size() > 0) {
for (Invoker<T> invoker : new ArrayList<>(localUrlInvokerMap.values())) {
if (invoker.isAvailable()) {
@@ -667,7 +667,7 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify
/**
* Haomin: added for test purpose
*/
- public Map<String, Invoker<T>> getUrlInvokerMap() {
+ public Map<URL, Invoker<T>> getUrlInvokerMap() {
return urlInvokerMap;
}
@@ -723,7 +723,7 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify
public InvokerDelegate(Invoker<T> invoker, URL url, URL providerUrl) {
super(invoker, url);
- this.providerUrl = providerUrl;
+ //this.providerUrl = providerUrl;
}
public URL getProviderUrl() {
diff --git a/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryDirectoryTest.java b/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryDirectoryTest.java
index f8925be..82a81f8 100644
--- a/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryDirectoryTest.java
+++ b/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryDirectoryTest.java
@@ -440,7 +440,7 @@ public class RegistryDirectoryTest {
registryDirectory.destroy();
List<Invoker<RegistryDirectoryTest>> cachedInvokers = registryDirectory.getInvokers();
- Map<String, Invoker<RegistryDirectoryTest>> urlInvokerMap = registryDirectory.getUrlInvokerMap();
+ Map<URL, Invoker<RegistryDirectoryTest>> urlInvokerMap = registryDirectory.getUrlInvokerMap();
Assertions.assertNull(cachedInvokers);
Assertions.assertEquals(0, urlInvokerMap.size());
diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/listener/ListenerInvokerWrapper.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/listener/ListenerInvokerWrapper.java
index a0fea10..64d913e 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/listener/ListenerInvokerWrapper.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/listener/ListenerInvokerWrapper.java
@@ -37,15 +37,16 @@ public class ListenerInvokerWrapper<T> implements Invoker<T> {
private final Invoker<T> invoker;
- private final List<InvokerListener> listeners;
+ private List<InvokerListener> listeners;
public ListenerInvokerWrapper(Invoker<T> invoker, List<InvokerListener> listeners) {
if (invoker == null) {
throw new IllegalArgumentException("invoker == null");
}
this.invoker = invoker;
- this.listeners = listeners;
+
if (CollectionUtils.isNotEmpty(listeners)) {
+ this.listeners = listeners;
for (InvokerListener listener : listeners) {
if (listener != null) {
try {
diff --git a/pom.xml b/pom.xml
index dcfd90c..73153ca 100644
--- a/pom.xml
+++ b/pom.xml
@@ -126,7 +126,7 @@
<arguments />
<checkstyle.skip>true</checkstyle.skip>
<rat.skip>true</rat.skip>
- <revision>2.7.8-hsf3-3</revision>
+ <revision>2.7.8-hsf3-4</revision>
</properties>
<modules>
@@ -257,7 +257,7 @@
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-build-tools</artifactId>
- <version>2.7.8-hsf3-3</version>
+ <version>2.7.8-hsf3-4</version>
</dependency>
</dependencies>
<executions>