Skip to content

Commit d2b5914

Browse files
yizhenqiangbeiwei30
authored andcommitted
Support multiple shared links (#2457)
* make dubbo support multiple shared links, upgrading RPC throughput * Fix compilation error * Fix compilation error * opti import * if add {} * checkstyle fail * fix getSharedClient referenceCount calculation error bug * 优化 import * Fix the problem that the getSharedClient thread is not safe * Fix the problem that the getSharedClient thread is not safe * Try fixing ci error, https://travis-ci.org/apache/incubator-dubbo/jobs/453185295 * 将DEFAULT_CONNECTIONS_KEY修改成SERVICE_CONNECTIONS_KEY * dubbo.xsd add shareconnections attribute, * Optimize code format * Fix mult connect ghost connect problem * format code * Remove the concept of ghostClientMap and ghost connection. In fact, ghostClient is LazyConnectExchangeClient. At present, the LazyConnectExchangeClient object is added directly in ReferenceCountExchangeClient to realize the mapping relationship with ReferenceCountExchangeClient. The relationship between previous ghostClient and url mapping is not applicable to the current new share. Multiple connections. * Optimize the ReferenceCountExchangeClient and remove the reference to the lazyConnectExchangeClient because it doesn't make much sense; add locks in the close operation of the AbstractClient, because connect, disconnect, and close should not be done at the same time. * format code * try remove close lock * Restore close method * Restore ReferenceCountExchangeClient reference to LazyConnectExchangeClient object * Optimize the logic of using the LazyConnectExchangeClient inside the ReferenceCountExchangeClient; Supplemental shared multi-connected unit test
1 parent c2c9de9 commit d2b5914

File tree

8 files changed

+379
-123
lines changed

8 files changed

+379
-123
lines changed

dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,13 @@ public class Constants {
146146

147147
public static final int DEFAULT_ALIVE = 60 * 1000;
148148

149-
public static final int DEFAULT_CONNECTIONS = 0;
149+
/**
150+
* By default, a consumer JVM instance and a provider JVM instance share a long TCP connection (except when connections are set),
151+
* which can set the number of long TCP connections shared to avoid the bottleneck of sharing a single long TCP connection.
152+
*/
153+
public static final String DEFAULT_SHARE_CONNECTIONS = "1";
154+
155+
public static final String SHARE_CONNECTIONS_KEY = "shareconnections";
150156

151157
public static final int DEFAULT_ACCEPTS = 0;
152158

dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ConsumerConfig.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ public class ConsumerConfig extends AbstractReferenceConfig {
5757
*/
5858
private Integer queues;
5959

60+
/**
61+
* By default, a TCP long-connection communication is shared between the consumer process and the provider process.
62+
* This property can be set to share multiple TCP long-connection communications. Note that only the dubbo protocol takes effect.
63+
*/
64+
private Integer shareconnections;
65+
6066
@Override
6167
public void setTimeout(Integer timeout) {
6268
super.setTimeout(timeout);
@@ -118,4 +124,12 @@ public Integer getQueues() {
118124
public void setQueues(Integer queues) {
119125
this.queues = queues;
120126
}
127+
128+
public Integer getShareconnections() {
129+
return shareconnections;
130+
}
131+
132+
public void setShareconnections(Integer shareconnections) {
133+
this.shareconnections = shareconnections;
134+
}
121135
}

dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,12 @@
891891
<xsd:documentation><![CDATA[ The thread pool queue size. ]]></xsd:documentation>
892892
</xsd:annotation>
893893
</xsd:attribute>
894+
<xsd:attribute name="shareconnections" type="xsd:string">
895+
<xsd:annotation>
896+
<xsd:documentation>
897+
<![CDATA[ The default share connections. default share one connection. ]]></xsd:documentation>
898+
</xsd:annotation>
899+
</xsd:attribute>
894900
<xsd:anyAttribute namespace="##other" processContents="lax"/>
895901
</xsd:extension>
896902
</xsd:complexContent>

dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractClient.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,30 +174,38 @@ public void send(Object message, boolean sent) throws RemotingException {
174174
}
175175

176176
protected void connect() throws RemotingException {
177+
177178
connectLock.lock();
179+
178180
try {
181+
179182
if (isConnected()) {
180183
return;
181184
}
182185

183186
doConnect();
187+
184188
if (!isConnected()) {
185189
throw new RemotingException(this, "Failed connect to server " + getRemoteAddress() + " from " + getClass().getSimpleName() + " "
186190
+ NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion()
187191
+ ", cause: Connect wait timeout: " + getConnectTimeout() + "ms.");
192+
188193
} else {
189194
if (logger.isInfoEnabled()) {
190195
logger.info("Successed connect to server " + getRemoteAddress() + " from " + getClass().getSimpleName() + " "
191196
+ NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion()
192197
+ ", channel is " + this.getChannel());
193198
}
194199
}
200+
195201
} catch (RemotingException e) {
196202
throw e;
203+
197204
} catch (Throwable e) {
198205
throw new RemotingException(this, "Failed connect to server " + getRemoteAddress() + " from " + getClass().getSimpleName() + " "
199206
+ NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion()
200207
+ ", cause: " + e.getMessage(), e);
208+
201209
} finally {
202210
connectLock.unlock();
203211
}
@@ -241,23 +249,27 @@ public void reconnect() throws RemotingException {
241249

242250
@Override
243251
public void close() {
252+
244253
try {
245254
super.close();
246255
} catch (Throwable e) {
247256
logger.warn(e.getMessage(), e);
248257
}
258+
249259
try {
250260
if (executor != null) {
251261
ExecutorUtil.shutdownNow(executor, 100);
252262
}
253263
} catch (Throwable e) {
254264
logger.warn(e.getMessage(), e);
255265
}
266+
256267
try {
257268
disconnect();
258269
} catch (Throwable e) {
259270
logger.warn(e.getMessage(), e);
260271
}
272+
261273
try {
262274
doClose();
263275
} catch (Throwable e) {
@@ -310,5 +322,4 @@ public String toString() {
310322
* @return channel
311323
*/
312324
protected abstract Channel getChannel();
313-
314325
}

0 commit comments

Comments
 (0)