-
Notifications
You must be signed in to change notification settings - Fork 997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow packet.Conn buffer size to be adjustable #892
Conversation
srv := CreateMockServer(t) | ||
defer srv.Stop() | ||
|
||
SetDSNOptions(map[string]DriverOption{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
our application is already using SetDSNOptions
so we're planning on using the same technique for the BufferSize
. I didn't want to add more configuration to the public README of this project because I felt that the default for most people is probably fine and therefore no need to add more configuration options.
@@ -53,19 +53,23 @@ type Conn struct { | |||
} | |||
|
|||
func NewConn(conn net.Conn) *Conn { | |||
return NewBufferedConn(conn, 65536) // 64kb |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keeping this NewConn
function for compatibility reasons. As of now just the server code and most unit tests use this. The client code will be using NewBufferedConn
.
@@ -94,6 +99,7 @@ type Dialer func(ctx context.Context, network, address string) (net.Conn, error) | |||
func ConnectWithDialer(ctx context.Context, network, addr, user, password, dbName string, dialer Dialer, options ...Option) (*Conn, error) { | |||
c := new(Conn) | |||
|
|||
c.BufferSize = defaultBufferSize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
init the new packet Conn
with the 64kb buffer size
Our usage of this library is in an application that will maintain a few thousand active MySQL connections from a single instance and we've noticed that the application is holding a lot of memory in
packet.Conn
, specifically thebufio.Reader
instances are holding about 500MB of the total 800MB heap.This PR will allow our application to change the hardcoded
65536
buffer size to something more reasonable for our use case (maybe4096
), which should reduce our heap by at least 50%.