Set timeout periods for HSF applications

更新时间:
复制 MD 格式

Timeouts prevent a consumer from waiting indefinitely when a provider is slow or unreachable. Without an explicit timeout, in-flight requests hold connections and threads open, which can exhaust resources and degrade the entire service chain.

High-speed Service Framework (HSF) provides two XML attributes for controlling timeouts:

AttributeScopeUnitDescription
clientTimeoutAll methods in an interfaceMillisecondsGlobal timeout applied to every method call on the consumer or provider side
methodSpecials > methodSpecialA single methodMillisecondsPer-method timeout that overrides clientTimeout for the specified method

Priority order

When you configure timeouts at multiple levels, HSF resolves them from the most specific to the least specific:

PriorityConfiguration levelDescription
1 (highest)methodSpecials on the consumerPer-method timeout set by the consumer
2clientTimeout on the consumerGlobal interface timeout set by the consumer
3methodSpecials on the providerPer-method timeout set by the provider
4 (lowest)clientTimeout on the providerGlobal interface timeout set by the provider

A consumer-side setting always overrides the corresponding provider-side setting. A per-method timeout always overrides a global interface timeout at the same level.

Configure a consumer timeout

The following XML sets a global timeout of 3,000 ms for the SimpleService interface, then overrides it with a 2,000 ms timeout for the sum method:

<hsf:consumer id="service" interface="com.taobao.edas.service.SimpleService"
  version="1.1.0" group="test1" clientTimeout="3000"
  target="10.1.6.57:12200?_TIMEOUT=1000" maxWaitTimeForCsAddress="5000">
  <hsf:methodSpecials>
    <hsf:methodSpecial name="sum" timeout="2000" />
  </hsf:methodSpecials>
</hsf:consumer>

In this example:

  • Calls to sum time out after 2,000 ms because methodSpecials overrides clientTimeout.

  • Calls to any other method in SimpleService time out after 3,000 ms, which is the clientTimeout value.