go-sql-driver / mysql

Go MySQL Driver is a MySQL driver for Go's (golang) database/sql package
https://pkg.go.dev/github.com/go-sql-driver/mysql
Mozilla Public License 2.0
14.49k stars 2.31k forks source link

GC Optimize #523

Closed BohuTANG closed 7 years ago

BohuTANG commented 7 years ago

Issue description

From this benchmark: https://github.com/XeLabs/go-mysqlstack/blob/master/benchmarks/main.go go-sql-driver may has some GC problems:

$go run benchmarks/main.go
go-mysqlstack:  records read 100        HEAP 10         time 517.087µs
mysqldriver-go: records read 100        HEAP 83         time 1.346706ms
go-sql-driver:  records read 100        HEAP 292        time 1.416546ms

go-mysqlstack:  records read 1000       HEAP 9          time 774.07µs
mysqldriver-go: records read 1000       HEAP 514        time 810.645µs
go-sql-driver:  records read 1000       HEAP 2510       time 1.151545ms

go-mysqlstack:  records read 2000       HEAP 6          time 990.627µs
mysqldriver-go: records read 2000       HEAP 1023       time 1.150353ms
go-sql-driver:  records read 2000       HEAP 5007       time 1.437157ms

go-mysqlstack:  records read 4000       HEAP 7          time 1.787648ms
mysqldriver-go: records read 4000       HEAP 2037       time 1.882848ms
go-sql-driver:  records read 4000       HEAP 10007      time 2.248269ms

go-mysqlstack:  records read 10000      HEAP 6          time 3.376725ms
mysqldriver-go: records read 10000      HEAP 5090       time 3.638042ms
go-sql-driver:  records read 10000      HEAP 25007      time 4.089699ms

go-mysqlstack:  records read 50000      HEAP 6          time 14.705967ms
mysqldriver-go: records read 50000      HEAP 45463      time 16.029054ms
go-sql-driver:  records read 50000      HEAP 145007     time 19.108608ms

go-mysqlstak does well for GC, the heap is almost constant even the reads very often. https://github.com/XeLabs/go-mysqlstack

julienschmidt commented 7 years ago

It seems like you are comparing apples to oranges in the benchmark as you are comparing a single connection vs a connection pool.

But I totally get your point. Unfortunately I don't think there is much we can do about it in this driver as most of the overhead is probably caused by database/sql itself or the driver interface forces us to introduce a lot of overhead. E.g. the type conversion is extremely inefficient but there is nothing we can do about it in the driver. Thus I worked on an alternative for a while about 2 years ago (I still haven't buried that idea).

We put a lot of effort in to optimizing this driver in the past, if you can still find possible optimizations, please report them / send pull requests.

julienschmidt commented 7 years ago

And a side note: It seems like you reused some code, which is completely fine. But please attribute the authors correctly and respect this drivers license (e.g. redistribution under a BSD license is not allowed).

BohuTANG commented 7 years ago

Got, the sql/database is a pain. Thanks for reminding the license. go-mysqlstack is based on mysqlproto-go and go-sql-driver, we have great respect for them, we will remove this repo, since he is the experiment.

On Sunday, 27 November 2016, Julien Schmidt notifications@github.com wrote:

And a side note: It seems like you reused some code, which is completely fine. But please attribute the authors correctly and respect this drivers license https://github.com/go-sql-driver/mysql/blob/master/LICENSE (e.g. redistribution under a BSD license is not allowed).

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/go-sql-driver/mysql/issues/523#issuecomment-263127337, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKgrNSFlnOEb9b6vFUHaR3Ck0r12kifks5rCZ1ugaJpZM4K9Ki4 .

-- BohuTANG

"The great artist is the simplifier."--- Vincent Van Gogh

julienschmidt commented 7 years ago

In case of any specific findings, please open a new issue / pull-request instead.