Created
September 18, 2020 03:09
-
-
Save bohutang/4762af73bac65b20043e3564ee1c7ee0 to your computer and use it in GitHub Desktop.
bench.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "log" | |
| "time" | |
| "context" | |
| "database/sql" | |
| _ "github.com/go-sql-driver/mysql" | |
| ) | |
| func main() { | |
| db, err := sql.Open("mysql", "root:123@tcp(172.17.0.3:3306)/") | |
| if err != nil { | |
| panic(err.Error()) | |
| } | |
| defer db.Close() | |
| insert, err := db.Query("create database if not exists sbtest") | |
| if err != nil { | |
| panic(err.Error()) | |
| } | |
| insert, err = db.Query("CREATE TABLE if not exists sbtest.`timestamp` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `timestamp` int(11) DEFAULT NULL, `content` varchar(9000) DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB") | |
| if err != nil { | |
| panic(err.Error()) | |
| } | |
| insert.Close() | |
| for k:=0; k < 100000; k++{ | |
| ctx := context.Background() | |
| tx, err := db.BeginTx(ctx, nil) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| for i := 0; i < 10; i++ { | |
| _, err = tx.ExecContext(ctx, "insert into sbtest.timestamp (timestamp, content) values (111222333, 'The default location for binary log files is the data directory. You can use the --log-bin option to specify an alternative location, by adding a leading absolute path name to the base name to specify a different directory. When the server reads an entry from the binary log index file, which tracks the binary log files that have been used, it checks whether the entry contains a relative path. If it does, the relative part of the path is replaced with the absolute path set using the --log-bin option. An absolute path recorded in the binary log index file remains unchanged; in such a case, the index file must be edited manually to enable a new path or paths to be used. The binary log file base name and any specified path are available as the log_bin_basename system variable. In earlier MySQL versions, binary logging was disabled by default')") | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| } | |
| err = tx.Commit() | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| time.Sleep(10 * time.Millisecond) | |
| log.Print("----\n") | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sudo docker network create --subnet=172.18.0.0/16 selnet
sudo docker run --net selnet --ip 172.18.0.3 -d -e MYSQL_ROOT_PASSWORD=123 mysql:5.7 mysqld --datadir=/var/lib/mysql --server-id=3 --log-bin=/var/lib/mysql/mysql-bin.log --gtid-mode=ON --enforce-gtid-consistency --disable-ssl --ssl=0 --log_slave_updates=on
sudo docker run --net selnet --ip 172.18.0.4 -d -e MYSQL_ROOT_PASSWORD=123 mysql:5.7 mysqld --datadir=/var/lib/mysql --server-id=4 --log-bin=/var/lib/mysql/mysql-bin.log --gtid-mode=ON --enforce-gtid-consistency --disable-ssl --ssl=0 --log_slave_updates=on
change master to master_host='172.18.0.3', master_user='root', master_password='123', master_auto_position=1;
create database sbtest engine=MaterializeMySQL('172.18.0.4:3306', 'sbtest', 'root', '123');