去掉多余的括号和分号 (#5656)
* Update taosdemo.go 去掉多用的括号和分号 格式化代码 * Update taosdemo.go 地址改回127.0.0.1
This commit is contained in:
parent
1e85026615
commit
0bc3fddad0
|
@ -16,21 +16,23 @@ package main
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
"flag"
|
||||
"fmt"
|
||||
_ "github.com/taosdata/driver-go/taosSql"
|
||||
"math/rand"
|
||||
"os"
|
||||
"sync"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
"flag"
|
||||
"math/rand"
|
||||
|
||||
_ "github.com/taosdata/driver-go/taosSql"
|
||||
|
||||
//"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
const (
|
||||
maxLocationSize = 32
|
||||
maxSqlBufSize = 65480
|
||||
//maxSqlBufSize = 65480
|
||||
)
|
||||
|
||||
var locations = [maxLocationSize]string{
|
||||
|
@ -104,7 +106,7 @@ func printAllArgs() {
|
|||
func main() {
|
||||
printAllArgs()
|
||||
fmt.Printf("Please press enter key to continue....\n")
|
||||
fmt.Scanln()
|
||||
_, _ = fmt.Scanln()
|
||||
|
||||
url = "root:taosdata@/tcp(" + configPara.hostName + ":" + strconv.Itoa(configPara.serverPort) + ")/"
|
||||
//url = fmt.Sprintf("%s:%s@/tcp(%s:%d)/%s?interpolateParams=true", configPara.user, configPara.password, configPara.hostName, configPara.serverPort, configPara.dbName)
|
||||
|
@ -138,7 +140,7 @@ func main() {
|
|||
func createDatabase(dbName string, supTblName string) {
|
||||
db, err := sql.Open(taosDriverName, url)
|
||||
if err != nil {
|
||||
fmt.Println("Open database error: %s\n", err)
|
||||
fmt.Printf("Open database error: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer db.Close()
|
||||
|
@ -165,27 +167,27 @@ func createDatabase(dbName string, supTblName string) {
|
|||
checkErr(err, sqlStr)
|
||||
}
|
||||
|
||||
func multiThreadCreateTable(threads int, ntables int, dbName string, tablePrefix string) {
|
||||
func multiThreadCreateTable(threads int, nTables int, dbName string, tablePrefix string) {
|
||||
st := time.Now().UnixNano()
|
||||
|
||||
if (threads < 1) {
|
||||
threads = 1;
|
||||
if threads < 1 {
|
||||
threads = 1
|
||||
}
|
||||
|
||||
a := ntables / threads;
|
||||
if (a < 1) {
|
||||
threads = ntables;
|
||||
a = 1;
|
||||
a := nTables / threads
|
||||
if a < 1 {
|
||||
threads = nTables
|
||||
a = 1
|
||||
}
|
||||
|
||||
b := ntables % threads;
|
||||
b := nTables % threads
|
||||
|
||||
last := 0;
|
||||
last := 0
|
||||
endTblId := 0
|
||||
wg := sync.WaitGroup{}
|
||||
for i := 0; i < threads; i++ {
|
||||
startTblId := last
|
||||
if (i < b ) {
|
||||
if i < b {
|
||||
endTblId = last + a
|
||||
} else {
|
||||
endTblId = last + a - 1
|
||||
|
@ -206,7 +208,7 @@ func createTable(dbName string, childTblPrefix string, startTblId int, endTblId
|
|||
|
||||
db, err := sql.Open(taosDriverName, url)
|
||||
if err != nil {
|
||||
fmt.Println("Open database error: %s\n", err)
|
||||
fmt.Printf("Open database error: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer db.Close()
|
||||
|
@ -228,18 +230,19 @@ func generateRowData(ts int64) string {
|
|||
values := "( " + strconv.FormatInt(ts, 10) + ", " + strconv.FormatFloat(float64(current), 'f', 6, 64) + ", " + strconv.Itoa(voltage) + ", " + strconv.FormatFloat(float64(phase), 'f', 6, 64) + " ) "
|
||||
return values
|
||||
}
|
||||
|
||||
func insertData(dbName string, childTblPrefix string, startTblId int, endTblId int, wg *sync.WaitGroup) {
|
||||
//fmt.Printf("subThread[%d]: insert data to table from %d to %d \n", unix.Gettid(), startTblId, endTblId)
|
||||
// windows.GetCurrentThreadId()
|
||||
|
||||
db, err := sql.Open(taosDriverName, url)
|
||||
if err != nil {
|
||||
fmt.Println("Open database error: %s\n", err)
|
||||
fmt.Printf("Open database error: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
tmpTs := configPara.startTs;
|
||||
tmpTs := configPara.startTs
|
||||
//rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
for tID := startTblId; tID <= endTblId; tID++ {
|
||||
totalNum := 0
|
||||
|
@ -254,7 +257,7 @@ func insertData(dbName string, childTblPrefix string, startTblId int, endTblId i
|
|||
|
||||
sqlStr = fmt.Sprintf("%s %s", sqlStr, valuesOfRow)
|
||||
|
||||
if (currRowNum >= configPara.numOfRecordsPerReq || totalNum >= configPara.numOfRecordsPerTable) {
|
||||
if currRowNum >= configPara.numOfRecordsPerReq || totalNum >= configPara.numOfRecordsPerTable {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -265,12 +268,12 @@ func insertData(dbName string, childTblPrefix string, startTblId int, endTblId i
|
|||
count, err := res.RowsAffected()
|
||||
checkErr(err, "rows affected")
|
||||
|
||||
if (count != int64(currRowNum)) {
|
||||
if count != int64(currRowNum) {
|
||||
fmt.Printf("insert data, expect affected:%d, actual:%d\n", currRowNum, count)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if (totalNum >= configPara.numOfRecordsPerTable) {
|
||||
if totalNum >= configPara.numOfRecordsPerTable {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -279,27 +282,28 @@ func insertData(dbName string, childTblPrefix string, startTblId int, endTblId i
|
|||
wg.Done()
|
||||
runtime.Goexit()
|
||||
}
|
||||
func multiThreadInsertData(threads int, ntables int, dbName string, tablePrefix string) {
|
||||
|
||||
func multiThreadInsertData(threads int, nTables int, dbName string, tablePrefix string) {
|
||||
st := time.Now().UnixNano()
|
||||
|
||||
if (threads < 1) {
|
||||
threads = 1;
|
||||
if threads < 1 {
|
||||
threads = 1
|
||||
}
|
||||
|
||||
a := ntables / threads;
|
||||
if (a < 1) {
|
||||
threads = ntables;
|
||||
a = 1;
|
||||
a := nTables / threads
|
||||
if a < 1 {
|
||||
threads = nTables
|
||||
a = 1
|
||||
}
|
||||
|
||||
b := ntables % threads;
|
||||
b := nTables % threads
|
||||
|
||||
last := 0;
|
||||
last := 0
|
||||
endTblId := 0
|
||||
wg := sync.WaitGroup{}
|
||||
for i := 0; i < threads; i++ {
|
||||
startTblId := last
|
||||
if (i < b ) {
|
||||
if i < b {
|
||||
endTblId = last + a
|
||||
} else {
|
||||
endTblId = last + a - 1
|
||||
|
@ -313,10 +317,11 @@ func multiThreadInsertData(threads int, ntables int, dbName string, tablePrefix
|
|||
et := time.Now().UnixNano()
|
||||
fmt.Printf("insert data spent duration: %6.6fs\n", (float32(et-st))/1e9)
|
||||
}
|
||||
|
||||
func selectTest(dbName string, tbPrefix string, supTblName string) {
|
||||
db, err := sql.Open(taosDriverName, url)
|
||||
if err != nil {
|
||||
fmt.Println("Open database error: %s\n", err)
|
||||
fmt.Printf("Open database error: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer db.Close()
|
||||
|
|
Loading…
Reference in New Issue