Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust客户端延时很大,比其他客户端差了10倍数量级 #381

Open
mmc-98 opened this issue Nov 24, 2024 · 5 comments
Open

rust客户端延时很大,比其他客户端差了10倍数量级 #381

mmc-98 opened this issue Nov 24, 2024 · 5 comments

Comments

@mmc-98
Copy link

mmc-98 commented Nov 24, 2024

  1. 新建库
create database power;

  1. 新建超级表
CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)

3 插入表数据(rust)

use taos::*;
use tokio::time::Instant;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let now = Instant::now();
    let dsn = "ws://192.168.0.253:6041";
    let taos = TaosBuilder::from_dsn(dsn)?.build().await?;

    let inserted = taos.exec("INSERT INTO
    power.d1001 USING power.meters TAGS('California.SanFrancisco', 2)
     VALUES (NOW, 10.30000, 219, 0.31000)").await?;

    // assert_eq!(inserted, 8);
    println!("===   rust 程序运行了 {:?} ms  ===",  now.elapsed().as_millis());

    Ok(())
}
  1. 结果:
    === rust 程序运行了 220 ms ===

运行简单的一条sql插入要200ms, 但自测go-sdk和restful 方式插入20ms左右, 速度整整差了10倍.麻烦看下

@mmc-98
Copy link
Author

mmc-98 commented Nov 26, 2024

3 插入表数据(go)

package main

import (
	"database/sql"
	"fmt"
	"log"
	"time"

	_ "github.com/taosdata/driver-go/v3/taosWS"
)

func main() {
	bT := time.Now()
	var taosDSN = "root:taosdata@ws(192.168.0.253:6041)/"
	db, err := sql.Open("taosWS", taosDSN)
	if err != nil {
		log.Fatalln("Failed to connect to " + taosDSN + ", ErrMessage: " + err.Error())
	}
	defer db.Close()

	insertQuery := "INSERT INTO " +
		"power.d1001 USING power.meters TAGS('California.SanFrancisco',2) " +
		"VALUES " +
		"(NOW, 10.30000, 219, 0.31000)"
	res, err := db.Exec(insertQuery)
	if err != nil {
		log.Fatalf("Failed to insert data to power.meters, sql: %s, ErrMessage: %s\n", insertQuery, err.Error())
	}
	rowsAffected, err := res.RowsAffected()
	if err != nil {
		log.Fatalf("Failed to get insert rowsAffected, sql: %s, ErrMessage: %s\n", insertQuery, err.Error())
	}
	// you can check affectedRows here
	fmt.Printf("Successfully inserted %d rows to power.meters.\n", rowsAffected)

	// 从开始到当前所消耗的时间
	fmt.Println("=== go 程序运行了 ===: ", time.Since(bT))
	// ANCHOR_END: select_data
}

4.结果
=== go 程序运行了 ===: 20.527167ms

@mmc-98
Copy link
Author

mmc-98 commented Nov 26, 2024

3.插入表数据(restful)

time curl --location -uroot:taosdata 'http://192.168.0.253:6041/rest/sql' -d "INSERT INTO
    power.d1001 USING power.meters TAGS('California.SanFrancisco', 2)
     VALUES (NOW, 10.30000, 219, 0.31000)"
  1. 结果
    === restful 程序运行了 ===: 38.527167ms

@mmc-98
Copy link
Author

mmc-98 commented Nov 26, 2024

在同等硬件条件下,rust客户端延时很大,比其他客户端差了10倍数量级

@mmc-98 mmc-98 changed the title rust sdk插入很慢 rust客户端延时很大,比其他客户端差了10倍数量级 Nov 26, 2024
@mmc-98
Copy link
Author

mmc-98 commented Dec 17, 2024

@qevolg @sheyanjie-qq sh @zitsen zi 几位大大,有空能帮忙看看是我使用方式不对吗

@qevolg
Copy link
Contributor

qevolg commented Dec 25, 2024

@qevolg @sheyanjie-qq sh @zitsen zi 几位大大,有空能帮忙看看是我使用方式不对吗

I'll take a look this weekend if I have time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants