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:
| Attribute | Scope | Unit | Description |
|---|---|---|---|
clientTimeout | All methods in an interface | Milliseconds | Global timeout applied to every method call on the consumer or provider side |
methodSpecials > methodSpecial | A single method | Milliseconds | Per-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:
| Priority | Configuration level | Description |
|---|---|---|
| 1 (highest) | methodSpecials on the consumer | Per-method timeout set by the consumer |
| 2 | clientTimeout on the consumer | Global interface timeout set by the consumer |
| 3 | methodSpecials on the provider | Per-method timeout set by the provider |
| 4 (lowest) | clientTimeout on the provider | Global 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
sumtime out after 2,000 ms becausemethodSpecialsoverridesclientTimeout.Calls to any other method in
SimpleServicetime out after 3,000 ms, which is theclientTimeoutvalue.