xorm查询com_stmt_prepare exec close 一样多的情况 #1496

Open
opened 2019-12-18 06:54:20 +00:00 by ONG-YA · 2 comments

如下图,
代码:

var XormDb *xorm.Engine

func init() error {
var err error

XormDb, err = xorm.NewEngine(conf.DbDriverName, conf.DbUserName+":"+conf.DbPwd+conf.DbUrl)
if err != nil {
	return err
}

XormDb.SetMaxIdleConns(1000)
XormDb.SetMaxOpenConns(200)

return nil

}

result,err := XormDb.Where("user_bind_status = ? " ,1).Where("code = ? " ,deviceCode).Get(&info)

简单的查询压测,使用200个线程,发现go操作数据库是每次查询都会做一次com_stmt_prepare exec close ,并没有预处理语句复用的效果,请问这是go的设计如此吗?

如下图, 代码: var XormDb *xorm.Engine func init() error { var err error XormDb, err = xorm.NewEngine(conf.DbDriverName, conf.DbUserName+":"+conf.DbPwd+conf.DbUrl) if err != nil { return err } XormDb.SetMaxIdleConns(1000) XormDb.SetMaxOpenConns(200) return nil } -------------------- result,err := XormDb.Where("user_bind_status = ? " ,1).Where("code = ? " ,deviceCode).Get(&info) 简单的查询压测,使用200个线程,发现go操作数据库是每次查询都会做一次com_stmt_prepare exec close ,并没有预处理语句复用的效果,请问这是go的设计如此吗?
18 KiB
ONG-YA started working 2019-12-18 06:55:07 +00:00
ONG-YA canceled time tracking 2019-12-18 06:55:14 +00:00
ONG-YA started working 2019-12-18 08:48:47 +00:00
Owner

You could use Prepare() and with session to do that.

You could use `Prepare()` and with `session` to do that.
lunny added the
kind
question
label 2019-12-20 02:33:04 +00:00
Author

我加了下prepare,看压测的情况依旧是还有很多prepare,close。。。是我写错了吗
result,err := XormDb.Prepare().Where(“user_bind_status = ? ” ,1).Where(“code = ? ” ,deviceCode).Get(&info)

我加了下prepare,看压测的情况依旧是还有很多prepare,close。。。是我写错了吗 result,err := XormDb.Prepare().Where(“user_bind_status = ? ” ,1).Where(“code = ? ” ,deviceCode).Get(&info)
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#1496
No description provided.