mysql
select ip, active from (select * from %s where p_id = %d order by create_time desc) as tb group by ip having active = 1
一些命令:
show create teble table_name \G;
create table user2(userid int(4) primary key not null auto_increment, id int);
测试运行5000次查询 mysqlslap -h127.0.0.1 -uroot -pyourpassword --concurrency=1 --iterations=1 --create-schema=vimi --query='select * from vimi.user2;' --engine=innodb --number-of-queries=5000
自定义插入
mysqlslap -h127.0.0.1 -uroot -pyourpassword --concurrency=500 --iterations=1 --create-schema=vimi --query='insert into vimi.user2(id) value(1)' --engine=innodb --number-of-queries=5000
package main import ( "database/sql" "fmt" "time" //"time" _ "github.com/go-sql-driver/mysql" ) func main() { source := fmt.Sprintf("%s:%s@(%s:%s)/%s?parseTime=true&sql_mode=ansi", "root", "yourpassword", "127.0.0.1", "3306", "transaction") db, err := sql.Open("mysql", source) defer db.Close() fmt.Println(db, err) fmt.Println() // rows, err := db.Query("select * from user") // checkErr(err) // for rows.Next() { // var userid, id int // err = rows.Scan(&userid, &id) // checkErr(err) // fmt.Println(userid, id) // } ch := make(chan bool, 1) stop := false go func() { time.Sleep(time.Second) ch <- true }() go func() { stop = <-ch }() count := 0 sql := `insert user set id = 444` for { count++ stmt, err := db.Prepare(sql) checkErr(err) _, err = stmt.Exec() checkErr(err) if stop { break } } fmt.Println(count) } func checkErr(err error) { if err != nil { fmt.Println(err) } }
----------------------------------------------------------最终版mysql效率测试--------------------------------------------------------------------------------------
环境:
golang:1s大概309条
mysqlslap插入5000条,大概需要15s
golang:1s大概也是241---347条左右
mysqlslap插入5000条,大概需要16--20s可能表格变大了,但是删除后还是需要15s左右,看来表格大小不影响
golang:还是350左右,但是350--429的偏多
mysqlslap插入5000条,大概需要13s
golang:343
mysqlslap插入5000条,大概需要14s,,,,,有点坑了哈,怎么这样的
我生气了
还是一样的数据,我要买个云MYSQL服务器了。
买了一个云服务器
golang:还是380条,不过还是快了一丢丢,感觉自己写错了
mysqlslap插入5000条,大概需要2.02s,,,,,太快了
既然选择了远方,就要风雨兼程~
posted on 2018-08-14 12:58 stupid_one 阅读(145) 评论(0) 编辑 收藏 举报