You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Summary
- Expand the timeout example into a client -> forward server -> backend
server call chain.
- Add generated public Chat proto stubs for the timeout flow.
- Document full-link timeout scenarios without relying on internal
services.
## Tests
- `go test ./features/timeout/... -count=1` from `examples/`
- `go test ./... -count=1` from `examples/`
- `git diff --check main...HEAD`
- Scanned changed files for internal-only links and local paths
Copy file name to clipboardExpand all lines: examples/features/timeout/README.md
+83-46Lines changed: 83 additions & 46 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,49 +1,94 @@
1
1
# Timeout
2
+
2
3
The following are some brief introductions and usage examples of trpc-go timeout feature. You can understand how the timeout mechanism of trpc-go works from these examples.
4
+
3
5
## Usage
6
+
4
7
Steps to use the feature. Typically:
8
+
5
9
* start the server
6
-
```
10
+
11
+
```shell
7
12
cd server && go build -v && ./server
8
13
```
9
14
10
-
* start the client
15
+
* open another terminal, and start the forward server
16
+
11
17
12
-
open another terminal.
18
+
```shell
19
+
cd forwardserver && go build -v && ./forwardserver
13
20
```
21
+
22
+
23
+
* open another terminal, start the client
24
+
25
+
26
+
```shell
14
27
cd client && go build -v && ./client
15
28
```
16
-
In the demo, there are two RPC calls, SayHello and SayHi.
17
-
You have set different client timeout values for the TestSayHello and TestSayHi interfaces. The client timeout value for TestSayHi is 1000ms.
18
-
19
-
```go
20
-
opts:= []client.Option{
21
-
client.WithTarget(addr),
22
-
client.WithTimeout(time.Millisecond * 1000),
23
-
}
24
-
````
25
-
26
-
The TestSayHellointerface will call the SayHiRPC. You have set the timeout value for this call to 2000ms.
27
-
```go
28
-
opts := []client.Option{
29
-
client.WithTarget(addr),
30
-
client.WithTimeout(time.Millisecond * 2000),
31
-
}
32
-
```
33
29
34
-
In the SayHi method of the server, you have set a sleep time of 1100ms for the thread.
30
+
The above example shows the "ForwardServer Full-Link Timeout".
31
+
For more timeout scenarios, see the table in the next section.
32
+
You can modify the timeout configuration to simulate other timeout scenarios.
33
+
34
+
35
+
## Timeout Scenarios Explanation
36
+
37
+
### Call Chain
35
38
```
36
-
time.Sleep(time.Millisecond * 1100ms)
39
+
Client -> ForwardServer -> Server
37
40
```
38
41
39
-
When executing `./client`, you found that the TestSayHi interface timed out, while the TestSayHello interface returned normally.
- ForwardServer->Server timeout(1s) < Server processing time(2s)
69
+
- Results in simple client timeout
70
+
- Both receive RetClientTimeout
71
+
72
+
5.**ForwardServer Normal Timeout**
73
+
- ForwardServer timeout(2s) < processing time(3s)
74
+
- Client receives RetServerTimeout
75
+
- ForwardServer receives RetClientFullLinkTimeout
76
+
77
+
6.**ForwardServer Full-Link Timeout**
78
+
- ForwardServer processing time(6s) exceeds all timeouts
79
+
- ForwardServer detects timeout but doesn't send response as Client already abandoned request
80
+
- ForwardServer reports RetServerFullLinkTimeout to monitoring system
81
+
- Results in RetClientTimeout and RetClientFullLinkTimeout
82
+
83
+
84
+
### Note
85
+
All times are in seconds, and errors indicate where in the chain the timeout occurred and how it propagated through the system.
86
+
87
+
## timeout mechanism in trpc-go
43
88
44
89
The timeout mechanism of trpc-go is as follows:
45
90
46
-
```
91
+
```raw
47
92
+------------------+-----------------------+
48
93
| server B | single timeout |
49
94
| | +------------> |
@@ -74,16 +119,15 @@ The timeout mechanism of trpc-go is as follows:
74
119
75
120
```
76
121
122
+
* Client configuration
77
123
78
-
- Client configuration
79
-
80
-
- The total timeout time of the downstream link
124
+
* The total timeout time of the downstream link
81
125
82
126
When the client initiates a request, it needs to specify the timeout period reserved for the downstream in the business agreement. After the timeout period is exceeded, the request will be canceled to avoid invalid waiting.
83
-
127
+
84
128
The total timeout time of the downstream link is configured as follows, timeout: 1000 means that the maximum processing time of all backend requests invoked by the client is 1000ms
85
-
86
-
```
129
+
130
+
```yaml
87
131
client: # Backend configuration for client calls.
88
132
timeout: 1000# The total timeout time of the downstream link, the longest request processing time for all backends.
89
133
namespace: development # Environments for all backends.
@@ -95,21 +139,18 @@ The timeout mechanism of trpc-go is as follows:
95
139
timeout: 800# Maximum request processing time.
96
140
```
97
141
98
-
- Single service timeout
99
-
142
+
* Single service timeout
143
+
100
144
The client may request multiple backend services at the same time. You can set the timeout period of the client call for each backend service separately. For example, the timeout: 800 configured under service above means that the timeout period for a single backend service is 800ms
101
-
102
-
- server configuration
145
+
146
+
* server configuration
103
147
104
148
A server can provide one or more service services, and supports setting the timeout period for each service. As follows, timeout: 1000 means that the server processing time of trpc.test.helloworld.Greeter service is up to 1000ms, and if it exceeds 1000ms, it will return a timeout.
105
-
106
-
```
149
+
150
+
```yaml
107
151
server: # server configuration.
108
152
app: test # Business application name.
109
153
server: Greeter # process service name.
110
-
bin_path: /usr/local/trpc/bin/ # The path where the binary executable and framework configuration files are located.
111
-
conf_path: /usr/local/trpc/conf/ # The path where the business configuration file is located.
112
-
data_path: /usr/local/trpc/data/ # The path where the business data file is located.
113
154
service: # The service provided by the business service can have multiple.
114
155
- name: trpc.test.helloworld.Greeter # service route name.
115
156
ip: 127.0.0.1 # The service listens to the ip address. You can use the placeholder ${ip}, choose one of ip and nic, and give priority to ip.
@@ -119,13 +160,9 @@ The timeout mechanism of trpc-go is as follows:
119
160
timeout: 1000# Request maximum processing time unit milliseconds.
120
161
idletime: 300000# Connection idle time unit milliseconds.
121
162
```
122
-
123
-
- specified in the code
163
+
164
+
* specified in the code
124
165
125
166
It supports setting the timeout period in the code. In this example, the client timeout period is set to 1000ms through the `client.WithTimeout(time.Millisecond * 1000)` method.
126
167
127
168
It is worth noting that the priority of code specification > the configuration file, set the timeout in the configuration file and the code at the same time, and finally adopt the configuration of the code specification, that is, the configuration takes precedence.
0 commit comments