mgrpc: decrease size of channel buffers
Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
parent
484a09bfa0
commit
52978c11e8
@ -12,6 +12,8 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const maxMessageSize = 8 << 10 // TODO(stevvooe): Cut these down, since they are pre-alloced.
|
||||||
|
|
||||||
type channel struct {
|
type channel struct {
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
bw *bufio.Writer
|
bw *bufio.Writer
|
||||||
@ -21,13 +23,15 @@ type channel struct {
|
|||||||
func newChannel(conn net.Conn) *channel {
|
func newChannel(conn net.Conn) *channel {
|
||||||
return &channel{
|
return &channel{
|
||||||
conn: conn,
|
conn: conn,
|
||||||
bw: bufio.NewWriter(conn),
|
bw: bufio.NewWriterSize(conn, maxMessageSize),
|
||||||
br: bufio.NewReader(conn),
|
br: bufio.NewReaderSize(conn, maxMessageSize),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch *channel) recv(ctx context.Context, msg interface{}) error {
|
func (ch *channel) recv(ctx context.Context, msg interface{}) error {
|
||||||
defer log.G(ctx).WithField("msg", msg).Info("recv")
|
defer log.G(ctx).WithField("msg", msg).Info("recv")
|
||||||
|
|
||||||
|
// TODO(stevvooe): Use `bufio.Reader.Peek` here to remove this allocation.
|
||||||
var p [maxMessageSize]byte
|
var p [maxMessageSize]byte
|
||||||
n, err := readmsg(ch.br, p[:])
|
n, err := readmsg(ch.br, p[:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -46,8 +46,6 @@ func (s *Server) Serve(l net.Listener) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const maxMessageSize = 1 << 20 // TODO(stevvooe): Cut these down, since they are pre-alloced.
|
|
||||||
|
|
||||||
func (s *Server) handleConn(conn net.Conn) {
|
func (s *Server) handleConn(conn net.Conn) {
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user