<!---The client connection is then established. For how to write data and query data, please refer to [Insert Data](https://docs.tdengine.com/cloud/develop/insert-data#connector-examples) and [Query Data](https://docs.tdengine.com/cloud/develop/query-data/#connector-examples).--->
<!---The client connection is then established. For how to write data and query data, please refer to [Insert Data](https://docs.tdengine.com/cloud/develop/insert-data#connector-examples) and [Query Data](https://docs.tdengine.com/cloud/develop/query-data/#connector-examples).--->
taosBenchmark (formerly taosdemo ) is a tool for testing the performance of TDengine products. taosBenchmark can test the performance of TDengine's insert, query, and subscription functions and simulate large amounts of data generated by many devices. taosBenchmark can be configured to generate user defined databases, supertables, subtables, and the time series data to populate these for performance benchmarking. taosBenchark is highly configurable and some of the configurations include the time interval for inserting data, the number of working threads and the capability to insert disordered data. The installer provides taosdemo as a soft link to taosBenchmark for compatibility with past users.
## Introduction
taosBenchmark (formerly taosdemo ) is a tool for testing the performance of TDengine products. taosBenchmark can test the performance of TDengine's insert, query, and subscription functions and simulate large amounts of data generated by many devices. taosBenchmark can be configured to generate user defined databases, supertables, subtables, and the time series data to populate these for performance benchmarking. taosBenchmark is highly configurable and some of the configurations include the time interval for inserting data, the number of working threads and the capability to insert disordered data. The installer provides taosdemo as a soft link to taosBenchmark for compatibility with past users.
## Installation
## Installation
...
@@ -14,9 +19,9 @@ There are two ways to install taosBenchmark:
...
@@ -14,9 +19,9 @@ There are two ways to install taosBenchmark:
### Configuration and running methods
### Configuration and running methods
TaosBenchmark needs to be executed on the terminal of the operating system, it supports two configuration methods: [Command-line arguments](#Command-line arguments in detailed) and [JSON configuration file](#Configuration file arguments in detailed). These two methods are mutually exclusive. Users can use `-f <json file>` to specify a configuration file. When running taosBenchmark with command-line arguments to control its behavior, users should use other parameters for configuration, but not the `-f` parameter. In addition, taosBenchmark offers a special way of running without parameters.
TaosBenchmark needs to be executed on the terminal of the operating system, it supports two configuration methods: [Command-line arguments](#command-line-arguments-in-detail) and [JSON configuration file](#configuration-file-parameters-in-detail). These two methods are mutually exclusive. Users can use `-f <json file>` to specify a configuration file. When running taosBenchmark with command-line arguments to control its behavior, users should use other parameters for configuration, but not the `-f` parameter. In addition, taosBenchmark offers a special way of running without parameters.
taosBenchmark supports the complete performance testing of TDengine by providing functionaly to write, query, and subscribe. These three functions are mutually exclusive, users can only select one of them each time taosBenchmark runs. The query and subscribe functionalities are only configurable using a json configuration file by specifying the parameter `filetype`, while write can be performed through both the command-line and a configuration file.
taosBenchmark supports the complete performance testing of TDengine by providing functionally to write, query, and subscribe. These three functions are mutually exclusive, users can only select one of them each time taosBenchmark runs. The query and subscribe functionalities are only configurable using a json configuration file by specifying the parameter `filetype`, while write can be performed through both the command-line and a configuration file.
**Make sure that the TDengine cluster is running correctly before running taosBenchmark. **
**Make sure that the TDengine cluster is running correctly before running taosBenchmark. **
...
@@ -50,9 +55,8 @@ Use the following command-line to run taosBenchmark and control its behavior via
...
@@ -50,9 +55,8 @@ Use the following command-line to run taosBenchmark and control its behavior via
taosBenchmark -f <json file>
taosBenchmark -f <json file>
```
```
**Here are a few examples of configuration files:**
#### Configuration file examples
##### Example of inserting a scenario JSON configuration file
#### Example of inserting a scenario JSON configuration file
<details>
<details>
<summary>insert.json</summary>
<summary>insert.json</summary>
...
@@ -63,7 +67,7 @@ taosBenchmark -f <json file>
...
@@ -63,7 +67,7 @@ taosBenchmark -f <json file>
</details>
</details>
#### Query Scenario JSON Profile Example
##### Query Scenario JSON Profile Example
<details>
<details>
<summary>query.json</summary>
<summary>query.json</summary>
...
@@ -74,7 +78,7 @@ taosBenchmark -f <json file>
...
@@ -74,7 +78,7 @@ taosBenchmark -f <json file>
</details>
</details>
#### Subscription JSON configuration example
##### Subscription JSON configuration example
<details>
<details>
<summary>subscribe.json</summary>
<summary>subscribe.json</summary>
...
@@ -165,7 +169,7 @@ taosBenchmark -A INT,DOUBLE,NCHAR,BINARY\(16\)
...
@@ -165,7 +169,7 @@ taosBenchmark -A INT,DOUBLE,NCHAR,BINARY\(16\)
specify whether to use escape characters in the super table and sub-table names, the default is no.
specify whether to use escape characters in the super table and sub-table names, the default is no.
-**-C/--chinese** :
-**-C/--chinese** :
specify whether to use Unicode Chinese characters in nchar and binary, the deault is no.
specify whether to use Unicode Chinese characters in nchar and binary, the default is no.
-**-N/--normal-table** :
-**-N/--normal-table** :
specify whether taosBenchmark will create only normal tables instead of super tables. The default value is false. It can be used if the insert mode is taosc, stmt, and rest.
specify whether taosBenchmark will create only normal tables instead of super tables. The default value is false. It can be used if the insert mode is taosc, stmt, and rest.
...
@@ -366,7 +370,7 @@ The configuration parameters for querying the sub-tables or the normal tables ar
...
@@ -366,7 +370,7 @@ The configuration parameters for querying the sub-tables or the normal tables ar
-**sqls**.
-**sqls**.
-**sql**: the SQL command to be executed.
-**sql**: the SQL command to be executed.
-**result**: the file to save the query result. If it is unspecified, taosBenchark will not save the result.
-**result**: the file to save the query result. If it is unspecified, taosBenchmark will not save the result.
#### Configuration parameters of query super table
#### Configuration parameters of query super table
`driver-go` is the official Go language connector for TDengine. It implements the [database/sql](https://golang.org/pkg/database/sql/) package, the generic Go language interface to SQL databases. Go developers can use it to develop applications that access TDengine cluster data.
This article describes how to install `driver-go` and connect to TDengine clusters and perform basic operations such as data query and data writing through `driver-go`.
The source code of `driver-go` is hosted on [GitHub](https://github.com/taosdata/driver-go).
## Installation steps
### Use go get to install
```
go get -u github.com/taosdata/driver-go/v2@develop
```
### Manage with go mod
1. Initialize the project with the `go mod` command.
```text
go mod init taos-demo
```
2. Introduce taosSql
```go
import(
"database/sql"
_"github.com/taosdata/driver-go/v2/taosSql"
)
```
3. Update the dependency packages with `go mod tidy`.
```text
go mod tidy
```
4. Run the program with `go run taos-demo` or compile the binary with the `go build` command.
```text
go run taos-demo
go build
```
## Create a connection
### Data source name (DSN)
Data source names have a standard format, e.g. [PEAR DB](http://pear.php.net/manual/en/package.database.db.intro-dsn.php), but no type prefix (square brackets indicate optionally):
_taosRestful_ implements Go's `database/sql/driver` interface via `http client`. You can use the [`database/sql`](https://golang.org/pkg/database/sql/) interface by simply introducing the driver.
Use `taosRestful` as `driverName` and use a correct [DSN](#DSN) as `dataSourceName` with the following parameters supported by the DSN.
*`disableCompression` whether to accept compressed data, default is true do not accept compressed data, set to false if transferring data using gzip compression.
*`readBufferSize` The default size of the buffer for reading data is 4K (4096), which can be adjusted upwards when the query result has a lot of data.
Since the REST API is stateless, the `use db` syntax will not work. You need to put the db name into the SQL command, e.g. `create table if not exists tb1 (ts timestamp, a int)` to `create table if not exists test.tb1 (ts timestamp, a int)` otherwise it will report the error `[0x217] Database not specified or available`.
You can also put the db name in the DSN by changing `root:taosdata@http(localhost:6041)/` to `root:taosdata@http(localhost:6041)/test`. This method is supported by taosAdapter since TDengine 2.4.0.5. Executing the `create database` statement when the specified db does not exist will not report an error while executing other queries or writing against that db will report an error.
fmt.Println("failed to connect TDengine, err:",err)
return
}
defertaos.Close()
taos.Exec("create database if not exists test")
taos.Exec("create table if not exists tb1 (ts timestamp, a int)")
_,err=taos.Exec("insert into tb1 values(now, 0)(now+1s,1)(now+2s,2)(now+3s,3)")
iferr!=nil{
fmt.Println("failed to insert, err:",err)
return
}
rows,err:=taos.Query("select * from tb1")
iferr!=nil{
fmt.Println("failed to select from table, err:",err)
return
}
deferrows.Close()
forrows.Next(){
varrstruct{
tstime.Time
aint
}
err:=rows.Scan(&r.ts,&r.a)
iferr!=nil{
fmt.Println("scan error:\n",err)
return
}
fmt.Println(r.ts,r.a)
}
}
```
## Frequently Asked Questions
1. Cannot find the package `github.com/taosdata/driver-go/v2/taosRestful`
Change the `github.com/taosdata/driver-go/v2` line in the require block of the `go.mod` file to `github.com/taosdata/driver-go/v2 develop`, then execute `go mod tidy`.
2. bind interface in database/sql crashes
REST API does not support parameter binding related interface. It is recommended to use `db.Exec` and `db.Query`.
3. error `[0x217] Database not specified or available` after executing other statements with `use db` statement
The execution of SQL command in the REST interface is not contextual, so using `use db` statement will not work, see the usage restrictions section above.
4. use `taosSql` without error but use `taosRestful` with error `[0x217] Database not specified or available`
Because the REST API is stateless, using the `use db` statement will not take effect. See the usage restrictions section above.
Change the `github.com/taosdata/driver-go/v2` line in the `go.mod` file to `github.com/taosdata/driver-go/v2 develop`, then execute `go mod tidy`.
6.`readBufferSize` parameter has no significant effect after being increased
Increasing `readBufferSize` will reduce the number of `syscall` calls when fetching results. If the query result is smaller, modifying this parameter will not improve performance significantly. If you increase the parameter value too much, the bottleneck will be parsing JSON data. If you need to optimize the query speed, you must adjust the value based on the actual situation to achieve the best query performance.
7.`disableCompression` parameter is set to `false` when the query efficiency is reduced
When set `disableCompression` parameter to `false`, the query result will be compressed by `gzip` and then transmitted, so you have to decompress the data by `gzip` after getting it.
8.`go get` command can't get the package, or timeout to get the package
Set Go proxy `go env -w GOPROXY=https://goproxy.cn,direct`.
Use This API to open a DB, returning an object of type \*DB.
:::info
This API is created successfully without checking permissions, but only when you execute a Query or Exec, and check if user/password/host/port is legal.