Skip to content

Commit b82b6a7

Browse files
authored
docs: add notes on client connpool idletimeout (#170)
RELEASE NOTES: NONE
1 parent e17e291 commit b82b6a7

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

docs/user_guide/client/connection_mode.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,48 @@ if err != nil {
128128
log.Info("req:%v, rsp:%v, err:%v", req, rsp, err)
129129
```
130130

131+
132+
#### Setting Idle Connection Timeout
133+
134+
For the client's connection pool mode, the framework sets a default idle timeout of 50 seconds.
135+
136+
* For `go-net`, the connection pool maintains a list of idle connections. The idle timeout only affects the connections in this idle list and is only triggered when the connection is retrieved next time, causing idle connections to be closed due to the idle timeout.
137+
* For `tnet`, the idle timeout is implemented by maintaining a timer on each connection. Even if a connection is being used for a client's call, if the downstream does not return a result within the idle timeout period, the connection will still be triggered by the idle timeout and forcibly closed.
138+
139+
The methods to change the idle timeout are as follows:
140+
141+
* `go-net`
142+
143+
```go
144+
import "trpc.group/trpc-go/trpc-go/pool/connpool"
145+
146+
func init() {
147+
connpool.DefaultConnectionPool = connpool.NewConnectionPool(
148+
connpool.WithIdleTimeout(0), // Setting to 0 disables it.
149+
)
150+
}
151+
```
152+
153+
tnet
154+
155+
```go
156+
import (
157+
"trpc.group/trpc-go/trpc-go/pool/connpool"
158+
tnettrans "trpc.group/trpc-go/trpc-go/transport/tnet"
159+
)
160+
161+
func init() {
162+
tnettrans.DefaultConnPool = connpool.NewConnectionPool(
163+
connpool.WithDialFunc(tnettrans.Dial),
164+
connpool.WithIdleTimeout(0), // Setting to 0 disables it.
165+
connpool.WithHealthChecker(tnettrans.HealthChecker),
166+
)
167+
}
168+
```
169+
170+
**Note**: The server also has a default idle timeout, which is 60 seconds. This time is designed to be longer than the 50 seconds, so that under default conditions, it is the client that triggers the idle connection timeout to actively close the connection, rather than the server triggering a forced cleanup. For methods to change the server's idle timeout, see the server usage documentation.
171+
172+
131173
### I/O multiplexing
132174

133175
```go

docs/user_guide/client/connection_mode.zh_CN.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,47 @@ if err != nil {
126126
log.Info("req:%v, rsp:%v, err:%v", req, rsp, err)
127127
```
128128

129-
###连接多路复用
129+
#### 设置空闲连接超时
130+
131+
对于客户端的连接池模式来说,框架会设置一个默认的 50s 的空闲超时时间。
132+
133+
* 对于 `go-net` 而言,连接池中会维持一个空闲连接列表,空闲超时时间只会对空闲连接列表中的连接生效,并且只会在下次获取的时候触发空闲连接触发空闲超时的关闭
134+
* 对于 `tnet` 而言,空闲超时通过在每个连接上维护定时器来实现,即使该连接被用于客户端发起调用,假如下游未在空闲连接超时时间内返回结果的话,该连接仍然会被触发空闲超时并强制被关闭
135+
136+
更改空闲超时时间的方式如下:
137+
138+
* `go-net`
139+
140+
```go
141+
import "trpc.group/trpc-go/trpc-go/pool/connpool"
142+
143+
func init() {
144+
connpool.DefaultConnectionPool = connpool.NewConnectionPool(
145+
connpool.WithIdleTimeout(0), // 设置为 0 是禁用
146+
)
147+
}
148+
```
149+
150+
* `tnet`
151+
152+
```go
153+
import (
154+
"trpc.group/trpc-go/trpc-go/pool/connpool"
155+
tnettrans "trpc.group/trpc-go/trpc-go/transport/tnet"
156+
)
157+
158+
func init() {
159+
tnettrans.DefaultConnPool = connpool.NewConnectionPool(
160+
connpool.WithDialFunc(tnettrans.Dial),
161+
connpool.WithIdleTimeout(0), // 设置为 0 是禁用
162+
connpool.WithHealthChecker(tnettrans.HealthChecker),
163+
)
164+
}
165+
```
166+
167+
****:服务端默认也有一个空闲超时时间,为 60s,该时间设计得比 50s 打,从而在默认情况下是客户端主动触发空闲连接超时以主动关闭连接,而非服务端触发强制清理。服务端空闲超时的更改方法见服务端使用文档。
168+
169+
### 连接多路复用
130170

131171
```go
132172
opts := []client.Option{

0 commit comments

Comments
 (0)