Skip to content

implement SessionResetter. #779

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

Merged

Conversation

shogo82148
Copy link
Contributor

@shogo82148 shogo82148 commented Apr 7, 2018

Description

Conn should implement driver.SessionResetter.

https://golang.org/pkg/database/sql/driver/#SessionResetter

database/sql will not return a bad connection to the connection pool.

Checklist

  • Code compiles correctly
  • Created tests which fail without the change (if possible)
  • All tests passing
  • Extended the README / documentation, if necessary
  • Added myself / the copyright holder to the AUTHORS file

@methane
Copy link
Member

methane commented Apr 10, 2018

It's interesting idea.

I hope database/sql provides better way to close bad connection before return it to pool.
But this can mitigate current situation.

OTOH, it may reduce performance for "massive light query" pattern.
Would you try this benchmark, without compression?

@shogo82148
Copy link
Contributor Author

Here is the result of the benchmark.

# master branch
$ go test -bench . -benchtime 60s
goos: darwin
goarch: amd64
pkg: github.com/go-sql-driver/mysql/bench
BenchmarkSmall-4   	  200000	    385242 ns/op	     482 B/op	      14 allocs/op
BenchmarkPlain-4   	   20000	   5732152 ns/op	  653555 B/op	   20413 allocs/op
PASS
ok  	github.com/go-sql-driver/mysql/bench	254.180s

# this branch
$ go test -bench . -benchtime 60s
goos: darwin
goarch: amd64
pkg: github.com/go-sql-driver/mysql/bench
BenchmarkSmall-4   	  200000	    384629 ns/op	     482 B/op	      14 allocs/op
BenchmarkPlain-4   	   20000	   5830082 ns/op	  653559 B/op	   20413 allocs/op
PASS
ok  	github.com/go-sql-driver/mysql/bench	255.172s

$ benchcmp master.txt pr779.txt
benchmark            old ns/op     new ns/op     delta
BenchmarkSmall-4     385242        384629        -0.16%
BenchmarkPlain-4     5732152       5830082       +1.71%

benchmark            old allocs     new allocs     delta
BenchmarkSmall-4     14             14             +0.00%
BenchmarkPlain-4     20413          20413          +0.00%

benchmark            old bytes     new bytes     delta
BenchmarkSmall-4     482           482           +0.00%
BenchmarkPlain-4     653555        653559        +0.00%

// (From Go 1.10)
func (mc *mysqlConn) ResetSession(ctx context.Context) error {
if mc.closed.IsSet() {
errLog.Print(ErrInvalidConn)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this log helpful?
Are there some scenarios which mc is closed but log is not printed yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it isn't.
I'll remove it.

@julienschmidt julienschmidt merged commit 92a288d into go-sql-driver:master May 19, 2018
@shogo82148 shogo82148 deleted the session-resetter-support branch July 2, 2018 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants