为什么对每个客户端都需要建立独立的 tcp链路 到后端服务器?出于什么考量吗?
wilsonloo opened this issue · comments
Wilson-Loo commented
https://github.com/ejoy/goscon/blob/master/upstream/upstream.go#L257
// NewConn creates a new connection to target server, pair with remoteConn
func (u *upstreams) NewConn(remoteConn *scp.Conn) (conn net.Conn, err error) {
tserver := remoteConn.TargetServer()
host := u.GetHost(tserver) // TODO: handle name resolve
if host == nil {
err = ErrNoHost
glog.Errorf("get host <%s> failed: %s", tserver, err.Error())
return
}
addr := host.addrs[rand.Intn(len(host.addrs))]
**tcpConn, err := net.DialTCP("tcp", nil, addr)**
if err != nil {
glog.Errorf("connect to <%s> failed: %s", host.Addr, err.Error())
return
}
option := u.option.Load().(*Option)
conn, err = upgradeConn(option.Net, tcpConn, remoteConn)
if err != nil {
conn.Close()
return
}
err = OnAfterConnected(conn, remoteConn)
return
}
Wilson-Loo commented
每个tcp连接都有一定的发送窗口,多个tcp连接就能更好的占领带宽吗?
xjdrew commented
把多个tcp连接的数据合并到一个连接上,比较复杂;现在这样比较简单清晰,不易出错;
Wilson-Loo commented
把多个tcp连接的数据合并到一个连接上,比较复杂;现在这样比较简单清晰,不易出错;
好吧~~