mgrpc: decrease size of channel buffers

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day 2017-11-15 17:01:30 -08:00
parent 484a09bfa0
commit 52978c11e8
No known key found for this signature in database
GPG Key ID: 67B3DED84EDC823F
2 changed files with 6 additions and 4 deletions

View File

@ -12,6 +12,8 @@ import (
"github.com/pkg/errors"
)
const maxMessageSize = 8 << 10 // TODO(stevvooe): Cut these down, since they are pre-alloced.
type channel struct {
conn net.Conn
bw *bufio.Writer
@ -21,13 +23,15 @@ type channel struct {
func newChannel(conn net.Conn) *channel {
return &channel{
conn: conn,
bw: bufio.NewWriter(conn),
br: bufio.NewReader(conn),
bw: bufio.NewWriterSize(conn, maxMessageSize),
br: bufio.NewReaderSize(conn, maxMessageSize),
}
}
func (ch *channel) recv(ctx context.Context, msg interface{}) error {
defer log.G(ctx).WithField("msg", msg).Info("recv")
// TODO(stevvooe): Use `bufio.Reader.Peek` here to remove this allocation.
var p [maxMessageSize]byte
n, err := readmsg(ch.br, p[:])
if err != nil {

View File

@ -46,8 +46,6 @@ func (s *Server) Serve(l net.Listener) error {
return nil
}
const maxMessageSize = 1 << 20 // TODO(stevvooe): Cut these down, since they are pre-alloced.
func (s *Server) handleConn(conn net.Conn) {
defer conn.Close()