Commit 4515b322 authored by Quentin Smith's avatar Quentin Smith

storage: use interpolateParams to reduce Cloud SQL roundtrips

The MySQL protocol and database/sql require several round-trips to
execute queries with placeholders. Setting interpolateParams will
cause the mysql client library to interpolate the arguments and issue
a single string query to the server, reducing the number of round
trips. See
https://www.vividcortex.com/blog/2014/11/19/analyzing-prepared-statement-performance-with-vividcortex/

Change-Id: I766d593e9981c7ce2fbb1b48fe919ab46699416c
Reviewed-on: https://go-review.googlesource.com/35264Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent 590fe65c
......@@ -29,7 +29,7 @@ func connectDB() (*db.DB, error) {
dbName = mustGetenv("CLOUDSQL_DATABASE")
)
return db.OpenSQL("mysql", fmt.Sprintf("%s:%s@cloudsql(%s)/%s", user, password, connectionName, dbName))
return db.OpenSQL("mysql", fmt.Sprintf("%s:%s@cloudsql(%s)/%s?interpolateParams=true", user, password, connectionName, dbName))
}
func mustGetenv(k string) string {
......
......@@ -29,7 +29,7 @@ import (
)
var (
dbName = flag.String("db", "root:@cloudsql(golang-org:us-central1:golang-org)/perfdata", "connect to MySQL `database`")
dbName = flag.String("db", "root:@cloudsql(golang-org:us-central1:golang-org)/perfdata?interpolateParams=true", "connect to MySQL `database`")
bucket = flag.String("bucket", "golang-perfdata", "read from Google Cloud Storage `bucket`")
verbose = flag.Bool("v", false, "verbose")
)
......
......@@ -43,7 +43,7 @@ func createEmptyCloudDB(t *testing.T) (dsn string, cleanup func()) {
t.Logf("Using database %q", name)
return prefix + name, func() {
return prefix + name + "?interpolateParams=true", func() {
if _, err := db.Exec(fmt.Sprintf("DROP DATABASE `%s`", name)); err != nil {
t.Error(err)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment