Problem Statement:
Work encountered a problem, service one through the Dubbo call service 2, the problem is the end result is the service one finally succeeded, but the service two were executed two times.
Problem Analysis
Through the analysis of the message can be found that service two was called two times, two access time interval of 3 seconds, and all successful.
The log on the side of the service shows that there is an exception that Dubbo the service call timeout, and then although it timed out, it returned the result in more than 3 seconds, prompting warn and then following the normal process.
Finally, the service was successfully executed once, although the intermediate reported a timeout exception, service two was called two times.
problem-Solving principle-dubbo timeout-connection mechanism
Dubbo there are several mechanisms
1, if the timeout, but eventually returned the correct results, just warn, still follow the normal process.
2, Dubbo:provider can set the timeout time timout, and if the timeout allowed to be connected to the number of times retries
3, Dubbo:reference can set the time-out period, and if the timeout timout, allow the number of retries to connect the service
4, the default value of Dubbo:reference retries is the same as consumer, and consumer defaults to 2 times
| <dubbo:consumer> |
Retries |
Default.retries |
Int |
Optional |
2 |
5, the client's configuration priority is higher than the service-side priority.
problem-solving practices-Reconfigure yourself
1, my Dubbo:provider timeout is 3000 or 3 seconds, and the actual adjustment time more than 3 seconds, so extend this to 60000, of course longer also can, retries= "0", remain unchanged.
2, my dubbo:reference timeout is not configured, retries is not configured, now these two properties are also configured to timout= "60000" retries= "0"
Dubbo is Ali Open source distributed remote invocation scheme (RPC), which can cause an indeterminate intermediate state (timeout) due to the unreliable network or server. In order to avoid a timeout causing the client resource (thread) to suspend exhaustion, you must set the timeout time.
The main properties of the consumer side that provider can configure are timeout, retries, loadbalance, actives, and cluster. Provider should be configured as much as possible consumer end of the property, so that provider to start thinking about provider service characteristics and quality of service. There is an overlay between configurations, as follows:
1. Method-level configuration is superior to the interface level, that is, small scope first
2. Consumer end configuration is superior to provider configuration, better than global configuration
3. Dubbo Hard Code configuration value ( default )
According to Rule 2, although the consumer-side configuration is superior to the server-side configuration, the consumer-side configuration timeout cannot be arbitrary and needs to be set according to the business reality. If the timeout period is set too short, the complex business will take a long time to complete, the server cannot complete the business process within the set timeout, and if the timeout setting is too long, a large number of client resource threads are suspended due to server-side or network problems. Timeout Configuration
Dubbo consumption End
Global Timeout configuration
<dubbo:consumer timeout= "5000"/>
specify interface and specific method timeout configuration
<dubbo:reference interface= "Com.foo.BarService" timeout= "> <dubbo:method" name=
"SayHello" timeout = "3000"/>
</dubbo:reference>
Dubbo Service Side
Global Timeout configuration
<dubbo:provider timeout= "5000"/>
specify interface and specific method timeout configuration
<dubbo:provider interface= "Com.foo.BarService" timeout= "> <dubbo:method" name=
"SayHello" timeout = "3000"/>
</dubbo:provider> Dubbo Protocol Timeout Implementation
The Dubbo protocol timeout implementation uses the future mode, which mainly involves class dubboinvoker,responsefuture, defaultfuture.
Responsefuture.get () is a wait state until the request has been processed or not timed out, and the response is reached, the request status is set, and the Notify is awakened.
Public Object get () throws RemotingException {return get (timeout); Public Object get (int timeout) throws RemotingException {if (timeout <= 0) {timeout = Cons Tants.
Default_timeout;
} if (! Isdone ()) {Long start = System.currenttimemillis ();
Lock.lock ();
try {while (! Isdone ()) {done.await (timeout, timeunit.milliseconds); if (Isdone () | |
System.currenttimemillis ()-Start > Timeout) {break;
The catch (Interruptedexception e) {throw new RuntimeException (e);
finally {Lock.unlock (); } if (! Isdone ()) {throw new TimeoutException (Sent > 0, Channel, Gettimeoutmessage (false))
;
} return Returnfromresponse (); }
public static void received (Channel Channel, Response Response) {try {defaultfuture future = FUT
Ures.remove (Response.getid ());
if (future!= null) {future.doreceived (response); else {Logger.warn ("The timeout response finally returned at" + (new Simpl Edateformat ("Yyyy-mm-dd HH:mm:ss.") SSS "). Format (new Date ()) +", response "+ Response + (channel = null? "": ", Channel:" + channel.getlocaladdress () + "->" + channel.getremoteaddress ())
;
finally {Channels.remove (Response.getid ());
} private void Doreceived (Response res) {lock.lock ();
try {response = res;
if (done!= null) {done.signal ();
finally {Lock.unlock ();
} if (callback!= null) {Invokecallback (callback); }
}
Reference article: http://blog.csdn.net/bestcxx/article/details/72782981;
http://blog.csdn.net/peerless_hero/article/details/68922880