add separate variables for connection window update for fine tunning the performance of flow control; set initial connection window size to 1MB which is used in Java and C also

This commit is contained in:
iamqizhao 2015-03-25 16:27:29 -07:00
Родитель 2d13f82261
Коммит 16b34adb64
3 изменённых файлов: 10 добавлений и 8 удалений

Просмотреть файл

@ -42,10 +42,12 @@ import (
// TODO(zhaoq): Make the following configurable.
const (
// The initial window size for flow control.
initialWindowSize = 65535
initialWindowSize = 65535 // for an RPC
initialConnWindowSize = 1024 * 1024 // for a connection
// Window update is only sent when the inbound quota reaches
// this threshold. Used to reduce the flow control traffic.
windowUpdateThreshold = 16384
windowUpdateThreshold = 16384 // for an RPC
connWindowUpdateThreshold = 1024 * 256 // for a connection
)
// The following defines various control items which could flow through

Просмотреть файл

@ -149,7 +149,7 @@ func newHTTP2Client(addr string, opts *DialOptions) (_ ClientTransport, err erro
hBuf: &buf,
hEnc: hpack.NewEncoder(&buf),
controlBuf: newRecvBuffer(),
sendQuotaPool: newQuotaPool(initialWindowSize),
sendQuotaPool: newQuotaPool(initialConnWindowSize),
scheme: scheme,
state: reachable,
activeStreams: make(map[uint32]*Stream),
@ -457,11 +457,11 @@ func (t *http2Client) getStream(f http2.Frame) (*Stream, bool) {
// addRecvQuota adjusts the inbound quota for the stream and the transport.
// Window updates will deliver to the controller for sending when
// the cumulative quota exceeds windowUpdateThreshold.
// the cumulative quota exceeds the corresponding threshold.
func (t *http2Client) addRecvQuota(s *Stream, n int) {
t.mu.Lock()
t.recvQuota += n
if t.recvQuota >= windowUpdateThreshold {
if t.recvQuota >= connWindowUpdateThreshold {
t.controlBuf.put(&windowUpdate{0, uint32(t.recvQuota)})
t.recvQuota = 0
}

Просмотреть файл

@ -109,7 +109,7 @@ func newHTTP2Server(conn net.Conn, maxStreams uint32) (_ ServerTransport, err er
hEnc: hpack.NewEncoder(&buf),
maxStreams: maxStreams,
controlBuf: newRecvBuffer(),
sendQuotaPool: newQuotaPool(initialWindowSize),
sendQuotaPool: newQuotaPool(initialConnWindowSize),
state: reachable,
writableChan: make(chan int, 1),
shutdownChan: make(chan struct{}),
@ -284,11 +284,11 @@ func (t *http2Server) getStream(f http2.Frame) (*Stream, bool) {
// addRecvQuota adjusts the inbound quota for the stream and the transport.
// Window updates will deliver to the controller for sending when
// the cumulative quota exceeds windowUpdateThreshold.
// the cumulative quota exceeds the corresponding threshold.
func (t *http2Server) addRecvQuota(s *Stream, n int) {
t.mu.Lock()
t.recvQuota += n
if t.recvQuota >= windowUpdateThreshold {
if t.recvQuota >= connWindowUpdateThreshold {
t.controlBuf.put(&windowUpdate{0, uint32(t.recvQuota)})
t.recvQuota = 0
}