未验证 提交 1bd435f4 编写于 作者: sangshuduo's avatar sangshuduo 提交者: GitHub

Hotfix/sangshuduo/td 5872 taosdemo stmt improve (#7839)

* [TD-5872]<fix>: taosdemo stmt improve.

* refactor stmt functions.

* [TD-5872]<fix>: taosdemo stmt csv perf improve.

* rand func back to early impl.

* fix windows/mac compile error.

* fix empty tag sample.

* [TD-5873]<test>add stmt’performance taosdemo testcase

* add data_type enum and stmt_batch framework.

* use data type enum and fix test case limit/offset.

* revert thread number.

* rename MAX_SAMPLES_ONCE_FROM_FILE to reflect reality.
Co-authored-by: NShuduo Sang <sdsang@taosdata.com>
Co-authored-by: haoranc's avatartomchon <haoran920c@163.com>
上级 bb3b0a6f
...@@ -88,7 +88,7 @@ extern char configDir[]; ...@@ -88,7 +88,7 @@ extern char configDir[];
#define DOUBLE_BUFF_LEN 42 #define DOUBLE_BUFF_LEN 42
#define TIMESTAMP_BUFF_LEN 21 #define TIMESTAMP_BUFF_LEN 21
#define MAX_SAMPLES_ONCE_FROM_FILE 10000 #define MAX_SAMPLES 10000
#define MAX_NUM_COLUMNS (TSDB_MAX_COLUMNS - 1) // exclude first column timestamp #define MAX_NUM_COLUMNS (TSDB_MAX_COLUMNS - 1) // exclude first column timestamp
#define MAX_DB_COUNT 8 #define MAX_DB_COUNT 8
...@@ -4500,7 +4500,7 @@ static int generateSampleFromCsvForStb( ...@@ -4500,7 +4500,7 @@ static int generateSampleFromCsvForStb(
assert(stbInfo->sampleDataBuf); assert(stbInfo->sampleDataBuf);
memset(stbInfo->sampleDataBuf, 0, memset(stbInfo->sampleDataBuf, 0,
MAX_SAMPLES_ONCE_FROM_FILE * stbInfo->lenOfOneRow); MAX_SAMPLES * stbInfo->lenOfOneRow);
while(1) { while(1) {
readLen = tgetline(&line, &n, fp); readLen = tgetline(&line, &n, fp);
if (-1 == readLen) { if (-1 == readLen) {
...@@ -4531,7 +4531,7 @@ static int generateSampleFromCsvForStb( ...@@ -4531,7 +4531,7 @@ static int generateSampleFromCsvForStb(
line, readLen); line, readLen);
getRows++; getRows++;
if (getRows == MAX_SAMPLES_ONCE_FROM_FILE) { if (getRows == MAX_SAMPLES) {
break; break;
} }
} }
...@@ -6105,7 +6105,7 @@ static int getRowDataFromSample( ...@@ -6105,7 +6105,7 @@ static int getRowDataFromSample(
char* dataBuf, int64_t maxLen, int64_t timestamp, char* dataBuf, int64_t maxLen, int64_t timestamp,
SSuperTable* stbInfo, int64_t* sampleUsePos) SSuperTable* stbInfo, int64_t* sampleUsePos)
{ {
if ((*sampleUsePos) == MAX_SAMPLES_ONCE_FROM_FILE) { if ((*sampleUsePos) == MAX_SAMPLES) {
*sampleUsePos = 0; *sampleUsePos = 0;
} }
...@@ -6361,7 +6361,7 @@ static int generateSampleFromRand( ...@@ -6361,7 +6361,7 @@ static int generateSampleFromRand(
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
for (int i=0; i < MAX_SAMPLES_ONCE_FROM_FILE; i++) { for (int i=0; i < MAX_SAMPLES; i++) {
uint64_t pos = 0; uint64_t pos = 0;
memset(buff, 0, lenOfOneRow); memset(buff, 0, lenOfOneRow);
...@@ -6468,11 +6468,11 @@ static int generateSampleFromRandForStb(SSuperTable *stbInfo) ...@@ -6468,11 +6468,11 @@ static int generateSampleFromRandForStb(SSuperTable *stbInfo)
} }
static int prepareSampleForNtb() { static int prepareSampleForNtb() {
g_sampleDataBuf = calloc(g_args.lenOfOneRow * MAX_SAMPLES_ONCE_FROM_FILE, 1); g_sampleDataBuf = calloc(g_args.lenOfOneRow * MAX_SAMPLES, 1);
if (NULL == g_sampleDataBuf) { if (NULL == g_sampleDataBuf) {
errorPrint2("%s() LN%d, Failed to calloc %"PRIu64" Bytes, reason:%s\n", errorPrint2("%s() LN%d, Failed to calloc %"PRIu64" Bytes, reason:%s\n",
__func__, __LINE__, __func__, __LINE__,
g_args.lenOfOneRow * MAX_SAMPLES_ONCE_FROM_FILE, g_args.lenOfOneRow * MAX_SAMPLES,
strerror(errno)); strerror(errno));
return -1; return -1;
} }
...@@ -6483,11 +6483,11 @@ static int prepareSampleForNtb() { ...@@ -6483,11 +6483,11 @@ static int prepareSampleForNtb() {
static int prepareSampleForStb(SSuperTable *stbInfo) { static int prepareSampleForStb(SSuperTable *stbInfo) {
stbInfo->sampleDataBuf = calloc( stbInfo->sampleDataBuf = calloc(
stbInfo->lenOfOneRow * MAX_SAMPLES_ONCE_FROM_FILE, 1); stbInfo->lenOfOneRow * MAX_SAMPLES, 1);
if (NULL == stbInfo->sampleDataBuf) { if (NULL == stbInfo->sampleDataBuf) {
errorPrint2("%s() LN%d, Failed to calloc %"PRIu64" Bytes, reason:%s\n", errorPrint2("%s() LN%d, Failed to calloc %"PRIu64" Bytes, reason:%s\n",
__func__, __LINE__, __func__, __LINE__,
stbInfo->lenOfOneRow * MAX_SAMPLES_ONCE_FROM_FILE, stbInfo->lenOfOneRow * MAX_SAMPLES,
strerror(errno)); strerror(errno));
return -1; return -1;
} }
...@@ -7675,7 +7675,7 @@ static int execBindParamBatch( ...@@ -7675,7 +7675,7 @@ static int execBindParamBatch(
SSuperTable *stbInfo = pThreadInfo->stbInfo; SSuperTable *stbInfo = pThreadInfo->stbInfo;
uint32_t columnCount = (stbInfo)?pThreadInfo->stbInfo->columnCount:g_args.columnCount; uint32_t columnCount = (stbInfo)?pThreadInfo->stbInfo->columnCount:g_args.columnCount;
uint32_t thisBatch = MAX_SAMPLES_ONCE_FROM_FILE - (*pSamplePos); uint32_t thisBatch = MAX_SAMPLES - (*pSamplePos);
if (thisBatch > batch) { if (thisBatch > batch) {
thisBatch = batch; thisBatch = batch;
...@@ -7845,7 +7845,7 @@ static int execBindParamBatch( ...@@ -7845,7 +7845,7 @@ static int execBindParamBatch(
recordFrom ++; recordFrom ++;
(*pSamplePos) ++; (*pSamplePos) ++;
if ((*pSamplePos) == MAX_SAMPLES_ONCE_FROM_FILE) { if ((*pSamplePos) == MAX_SAMPLES) {
*pSamplePos = 0; *pSamplePos = 0;
} }
...@@ -7900,57 +7900,57 @@ static int parseSamplefileToStmtBatch( ...@@ -7900,57 +7900,57 @@ static int parseSamplefileToStmtBatch(
switch(data_type) { switch(data_type) {
case TSDB_DATA_TYPE_INT: case TSDB_DATA_TYPE_INT:
tmpP = calloc(1, sizeof(int) * MAX_SAMPLES_ONCE_FROM_FILE); tmpP = calloc(1, sizeof(int) * MAX_SAMPLES);
assert(tmpP); assert(tmpP);
*(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP; *(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP;
break; break;
case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_TINYINT:
tmpP = calloc(1, sizeof(int8_t) * MAX_SAMPLES_ONCE_FROM_FILE); tmpP = calloc(1, sizeof(int8_t) * MAX_SAMPLES);
assert(tmpP); assert(tmpP);
*(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP; *(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP;
break; break;
case TSDB_DATA_TYPE_SMALLINT: case TSDB_DATA_TYPE_SMALLINT:
tmpP = calloc(1, sizeof(int16_t) * MAX_SAMPLES_ONCE_FROM_FILE); tmpP = calloc(1, sizeof(int16_t) * MAX_SAMPLES);
assert(tmpP); assert(tmpP);
*(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP; *(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP;
break; break;
case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_BIGINT:
tmpP = calloc(1, sizeof(int64_t) * MAX_SAMPLES_ONCE_FROM_FILE); tmpP = calloc(1, sizeof(int64_t) * MAX_SAMPLES);
assert(tmpP); assert(tmpP);
*(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP; *(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP;
break; break;
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
tmpP = calloc(1, sizeof(int8_t) * MAX_SAMPLES_ONCE_FROM_FILE); tmpP = calloc(1, sizeof(int8_t) * MAX_SAMPLES);
assert(tmpP); assert(tmpP);
*(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP; *(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP;
break; break;
case TSDB_DATA_TYPE_FLOAT: case TSDB_DATA_TYPE_FLOAT:
tmpP = calloc(1, sizeof(float) * MAX_SAMPLES_ONCE_FROM_FILE); tmpP = calloc(1, sizeof(float) * MAX_SAMPLES);
assert(tmpP); assert(tmpP);
*(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP; *(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP;
break; break;
case TSDB_DATA_TYPE_DOUBLE: case TSDB_DATA_TYPE_DOUBLE:
tmpP = calloc(1, sizeof(double) * MAX_SAMPLES_ONCE_FROM_FILE); tmpP = calloc(1, sizeof(double) * MAX_SAMPLES);
assert(tmpP); assert(tmpP);
*(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP; *(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP;
break; break;
case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_NCHAR:
tmpP = calloc(1, MAX_SAMPLES_ONCE_FROM_FILE * tmpP = calloc(1, MAX_SAMPLES *
(((stbInfo)?stbInfo->columns[c].dataLen:g_args.binwidth))); (((stbInfo)?stbInfo->columns[c].dataLen:g_args.binwidth)));
assert(tmpP); assert(tmpP);
*(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP; *(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP;
break; break;
case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_TIMESTAMP:
tmpP = calloc(1, sizeof(int64_t) * MAX_SAMPLES_ONCE_FROM_FILE); tmpP = calloc(1, sizeof(int64_t) * MAX_SAMPLES);
assert(tmpP); assert(tmpP);
*(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP; *(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP;
break; break;
...@@ -7965,7 +7965,7 @@ static int parseSamplefileToStmtBatch( ...@@ -7965,7 +7965,7 @@ static int parseSamplefileToStmtBatch(
char *sampleDataBuf = (stbInfo)?stbInfo->sampleDataBuf:g_sampleDataBuf; char *sampleDataBuf = (stbInfo)?stbInfo->sampleDataBuf:g_sampleDataBuf;
int64_t lenOfOneRow = (stbInfo)?stbInfo->lenOfOneRow:g_args.lenOfOneRow; int64_t lenOfOneRow = (stbInfo)?stbInfo->lenOfOneRow:g_args.lenOfOneRow;
for (int i=0; i < MAX_SAMPLES_ONCE_FROM_FILE; i++) { for (int i=0; i < MAX_SAMPLES; i++) {
int cursor = 0; int cursor = 0;
for (int c = 0; c < columnCount; c++) { for (int c = 0; c < columnCount; c++) {
...@@ -8105,11 +8105,11 @@ static int parseSampleToStmt( ...@@ -8105,11 +8105,11 @@ static int parseSampleToStmt(
SSuperTable *stbInfo, uint32_t timePrec) SSuperTable *stbInfo, uint32_t timePrec)
{ {
pThreadInfo->sampleBindArray = pThreadInfo->sampleBindArray =
calloc(1, sizeof(char *) * MAX_SAMPLES_ONCE_FROM_FILE); calloc(1, sizeof(char *) * MAX_SAMPLES);
if (pThreadInfo->sampleBindArray == NULL) { if (pThreadInfo->sampleBindArray == NULL) {
errorPrint2("%s() LN%d, Failed to allocate %"PRIu64" bind array buffer\n", errorPrint2("%s() LN%d, Failed to allocate %"PRIu64" bind array buffer\n",
__func__, __LINE__, __func__, __LINE__,
(uint64_t)sizeof(char *) * MAX_SAMPLES_ONCE_FROM_FILE); (uint64_t)sizeof(char *) * MAX_SAMPLES);
return -1; return -1;
} }
...@@ -8117,7 +8117,7 @@ static int parseSampleToStmt( ...@@ -8117,7 +8117,7 @@ static int parseSampleToStmt(
char *sampleDataBuf = (stbInfo)?stbInfo->sampleDataBuf:g_sampleDataBuf; char *sampleDataBuf = (stbInfo)?stbInfo->sampleDataBuf:g_sampleDataBuf;
int64_t lenOfOneRow = (stbInfo)?stbInfo->lenOfOneRow:g_args.lenOfOneRow; int64_t lenOfOneRow = (stbInfo)?stbInfo->lenOfOneRow:g_args.lenOfOneRow;
for (int i=0; i < MAX_SAMPLES_ONCE_FROM_FILE; i++) { for (int i=0; i < MAX_SAMPLES; i++) {
char *bindArray = char *bindArray =
calloc(1, sizeof(TAOS_BIND) * (columnCount + 1)); calloc(1, sizeof(TAOS_BIND) * (columnCount + 1));
if (bindArray == NULL) { if (bindArray == NULL) {
...@@ -8282,7 +8282,7 @@ static uint32_t execBindParam( ...@@ -8282,7 +8282,7 @@ static uint32_t execBindParam(
recordFrom ++; recordFrom ++;
(*pSamplePos) ++; (*pSamplePos) ++;
if ((*pSamplePos) == MAX_SAMPLES_ONCE_FROM_FILE) { if ((*pSamplePos) == MAX_SAMPLES) {
*pSamplePos = 0; *pSamplePos = 0;
} }
...@@ -9416,7 +9416,7 @@ static void startMultiThreadInsertData(int threads, char* db_name, ...@@ -9416,7 +9416,7 @@ static void startMultiThreadInsertData(int threads, char* db_name,
#else #else
tmfree((char *)pThreadInfo->bind_ts); tmfree((char *)pThreadInfo->bind_ts);
if (pThreadInfo->sampleBindArray) { if (pThreadInfo->sampleBindArray) {
for (int k = 0; k < MAX_SAMPLES_ONCE_FROM_FILE; k++) { for (int k = 0; k < MAX_SAMPLES; k++) {
uintptr_t *tmp = (uintptr_t *)(*(uintptr_t *)( uintptr_t *tmp = (uintptr_t *)(*(uintptr_t *)(
pThreadInfo->sampleBindArray pThreadInfo->sampleBindArray
+ sizeof(uintptr_t *) * k)); + sizeof(uintptr_t *) * k));
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
"port": 6030, "port": 6030,
"user": "root", "user": "root",
"password": "taosdata", "password": "taosdata",
"thread_count": 1, "thread_count": 4,
"thread_count_create_tbl": 4, "thread_count_create_tbl": 4,
"result_file": "./insert_res.txt", "result_file": "./insert_res.txt",
"confirm_parameter_prompt": "no", "confirm_parameter_prompt": "no",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册