The theory of

Generally, interfaces have a timeout set, whether HTTP or Dubbo.

Why set a timeout? Because when not set, once high concurrency, the system will be hung.

Concrete is probably part of the trade request is slow, takes a long time, but did not set the timeout, then has accounted for the dubbo thread pool thread resources, this time, will be slow because some transactions, influence and cause the whole system, because other normal trade, now due to dubbo thread pool is full, also may not be able to handle, at this time, The system crashes, and all transactions are slow.

Dubbo timeout dimension

There are two dimensions, one is scope granularity, the other is consumer or producer.

Particle size

There are three comSumer /provider interfaces

Interface level reference/service

3. Method levels are rarely used.


priority

The smaller the granularity, the higher the priority, that is, method > Interface > All services.

Consumer producer

priority

Consumers have priority over producers.

conclusion

If both dimensions are set, the granularity dimension has a higher priority. 2. The consumer/producer dimension has a lower priority than the granularity maintenance


For example 1, the consumer is set to 60s at all interface granularity 2, the provider is set to 15s at the interface level granularity

In this case, the provider is the criterion, because the granularity dimension of the provider is smaller and the granularity priority is higher than that of the consumer producer dimension, so the 15s timeout of the provider is the criterion.


conclusion

Therefore, the priority of dubbo timeout is consumer Method> provider Method> Consumer Reference> Provider Service> Consumer global configuration > provider global configuration provider.

Best practices

It is best to set the timeout at the provider. It’s not just the timeout Settings, it’s the other Settings that consumers and producers have, that should be set in the provider, because the provider is the one who writes the code and knows the code best, so it’s up to you to set the timeout Settings and things like that.

Only in special cases, special scenarios, consumers need to configure, but this is also a customized timeout period.

In actual combat

The current status quo

Comsumer 60s — “unified order: service 15s; Consumer:? — “前置 : provider: none; Consumer: 30s — transaction: Provider: none; Customer: 15s.

To optimize the

Neither the provider of the lead time nor the transaction currently sets a timeout, so it must be set because the best practice is for the provider to set a timeout. Why? Since the provider knows best how long the service provider takes, and you wrote the code, you must be the best person to set the timeout.

How long is the best practice? In fact, 15s is too long. Generally, the interface takes only a few seconds. Now, for gradual optimization, you can set it to 30s first. And then optimize it to 15 seconds.

At present, the company’s transactions are all 15s, with a larger value of 30s and a larger value of 60s, such as the gateway. Therefore, the gateway also needs to be optimized, with a maximum of 15s. But in fact, it can be optimized gradually when it is connected, namely, it can be optimized to 30s first and then to 15s. Otherwise, the system will die in high concurrency.


Nontransactional interface

Marketing, reporting, risk control, 1s, 3s at most. Non-important, non-core interface, that is, the failure of the interface will not affect the transaction, the time is set very short, generally 1s, otherwise, if set very large, the whole transaction link will take too long.

reference

Dubbo.apache.org/zh/docs/v2….