thrift 的每个 client 对象中包裹了一个 transport:
【Go语言 连接池相关总结:HTTP、RPC、Redis 和数据库等】 ... useTransport, err := transportFactory.GetTransport(transport) client := NewEchoClientFactory(useTransport, protocolFactory) if err := transport.Open(); err != nil { fmt.Fprintln(os.Stderr, "Error opening socket to 127.0.0.1:9898", " ", err) os.Exit(1) } defer transport.Close() req := &EchoReq{Msg: "You are welcome."} res, err := client.Echo(context.TODO(), req) ...type EchoClient struct { c thrift.TClient}func NewEchoClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *EchoClient { return &EchoClient{ c: thrift.NewTStandardClient(f.GetProtocol(t), f.GetProtocol(t)), }}
这个包裹的 transport 就是一条单独的 tcp 连接,没有连接池 。
redigoredigo 是个 client 库,没有服务端:
type Pool struct { // Dial is an application supplied function for creating and configuring a // connection. // // The connection returned from Dial must not be in a special state // (subscribed to pubsub channel, transaction started, ...). Dial func() (Conn, error) // DialContext is an application supplied function for creating and configuring a // connection with the given context. // // The connection returned from Dial must not be in a special state // (subscribed to pubsub channel, transaction started, ...). DialContext func(ctx context.Context) (Conn, error) // TestOnBorrow is an optional application supplied function for checking // the health of an idle connection before the connection is used again by // the application. Argument t is the time that the connection was returned // to the pool. If the function returns an error, then the connection is // closed. TestOnBorrow func(c Conn, t time.Time) error // Maximum number of idle connections in the pool. MaxIdle int // Maximum number of connections allocated by the pool at a given time. // When zero, there is no limit on the number of connections in the pool. MaxActive int // Close connections after remaining idle for this duration. If the value // is zero, then idle connections are not closed. Applications should set // the timeout to a value less than the server's timeout. IdleTimeout time.Duration // If Wait is true and the pool is at the MaxActive limit, then Get() waits // for a connection to be returned to the pool before returning. Wait bool // Close connections older than this duration. If the value is zero, then // the pool does not close connections based on age. MaxConnLifetime time.Duration chInitialized uint32 // set to 1 when field ch is initialized mu sync.Mutex // mu protects the following fields closed bool // set to true when the pool is closed. active int // the number of open connections in the pool ch chan struct{} // limits open connections when p.Wait is true idle idleList // idle connections waitCount int64 // total number of connections waited for. waitDuration time.Duration // total time waited for new connections.}
推荐阅读
- 快充|等不及发布会!realme Q5i抢先开售:天玑810+5000mAh电池
- C语言的main函数的三个要点
- C语言的编译机制:分制原则与三种文件
- 微软承认Windows 10新BUG:错误显示没有网络连接
- MySQL 5.6--------SSL连接最佳实战
- GO 切片实力踩坑
- 无线投屏器怎么连接电视和手机?用手机怎么无线投屏到投影仪上?
- 我用 Go语言 生成的随机数为什么不随机?随机数是怎样产生的
- 什么是RPC?RPC有什么用?与语言有关吗?
- 华为b2手环与华为手机的连接方法