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

Feature/sangshuduo/td 5875 taosdemo ue improve (#7560)

* [TD-5875]<featur>: taosdemo show progress

* empty commit for CI

* better msg for create child table.
上级 46b9c174
...@@ -443,6 +443,7 @@ typedef struct SThreadInfo_S { ...@@ -443,6 +443,7 @@ typedef struct SThreadInfo_S {
uint64_t start_table_from; uint64_t start_table_from;
uint64_t end_table_to; uint64_t end_table_to;
int64_t ntables; int64_t ntables;
int64_t tables_created;
uint64_t data_of_rate; uint64_t data_of_rate;
int64_t start_time; int64_t start_time;
char* cols; char* cols;
...@@ -639,6 +640,7 @@ SArguments g_args = { ...@@ -639,6 +640,7 @@ SArguments g_args = {
static SDbs g_Dbs; static SDbs g_Dbs;
static int64_t g_totalChildTables = 0; static int64_t g_totalChildTables = 0;
static int64_t g_actualChildTables = 0;
static SQueryMetaInfo g_queryInfo; static SQueryMetaInfo g_queryInfo;
static FILE * g_fpOfInsertResult = NULL; static FILE * g_fpOfInsertResult = NULL;
...@@ -964,6 +966,7 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) { ...@@ -964,6 +966,7 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
arguments->num_of_tables = atoi(argv[++i]); arguments->num_of_tables = atoi(argv[++i]);
g_totalChildTables = arguments->num_of_tables;
} else if (strcmp(argv[i], "-n") == 0) { } else if (strcmp(argv[i], "-n") == 0) {
if ((argc == i+1) || if ((argc == i+1) ||
(!isStringNumber(argv[i+1]))) { (!isStringNumber(argv[i+1]))) {
...@@ -1134,7 +1137,7 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) { ...@@ -1134,7 +1137,7 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} else if ((strcmp(argv[i], "--version") == 0) || } else if ((strcmp(argv[i], "--version") == 0) ||
(strcmp(argv[i], "-V") == 0)){ (strcmp(argv[i], "-V") == 0)) {
printVersion(); printVersion();
exit(0); exit(0);
} else if (strcmp(argv[i], "--help") == 0) { } else if (strcmp(argv[i], "--help") == 0) {
...@@ -1345,14 +1348,14 @@ static void selectAndGetResult( ...@@ -1345,14 +1348,14 @@ static void selectAndGetResult(
} }
} }
static char *rand_bool_str(){ static char *rand_bool_str() {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0;
return g_randbool_buff + ((cursor % MAX_PREPARED_RAND) * BOOL_BUFF_LEN); return g_randbool_buff + ((cursor % MAX_PREPARED_RAND) * BOOL_BUFF_LEN);
} }
static int32_t rand_bool(){ static int32_t rand_bool() {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0;
...@@ -1485,7 +1488,7 @@ static char *demo_phase_float_str() { ...@@ -1485,7 +1488,7 @@ static char *demo_phase_float_str() {
return g_rand_phase_buff + ((cursor % MAX_PREPARED_RAND) * FLOAT_BUFF_LEN); return g_rand_phase_buff + ((cursor % MAX_PREPARED_RAND) * FLOAT_BUFF_LEN);
} }
static float UNUSED_FUNC demo_phase_float(){ static float UNUSED_FUNC demo_phase_float() {
static int cursor; static int cursor;
cursor++; cursor++;
if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0; if (cursor > (MAX_PREPARED_RAND - 1)) cursor = 0;
...@@ -1564,7 +1567,7 @@ static void init_rand_data() { ...@@ -1564,7 +1567,7 @@ static void init_rand_data() {
g_randdouble_buff = calloc(1, DOUBLE_BUFF_LEN * MAX_PREPARED_RAND); g_randdouble_buff = calloc(1, DOUBLE_BUFF_LEN * MAX_PREPARED_RAND);
assert(g_randdouble_buff); assert(g_randdouble_buff);
for (int i = 0; i < MAX_PREPARED_RAND; i++){ for (int i = 0; i < MAX_PREPARED_RAND; i++) {
g_randint[i] = (int)(taosRandom() % 65535); g_randint[i] = (int)(taosRandom() % 65535);
sprintf(g_randint_buff + i * INT_BUFF_LEN, "%d", sprintf(g_randint_buff + i * INT_BUFF_LEN, "%d",
g_randint[i]); g_randint[i]);
...@@ -3276,6 +3279,7 @@ static void* createTable(void *sarg) ...@@ -3276,6 +3279,7 @@ static void* createTable(void *sarg)
pThreadInfo->db_name, pThreadInfo->db_name,
g_args.tb_prefix, i, g_args.tb_prefix, i,
pThreadInfo->cols); pThreadInfo->cols);
batchNum ++;
} else { } else {
if (stbInfo == NULL) { if (stbInfo == NULL) {
free(pThreadInfo->buffer); free(pThreadInfo->buffer);
...@@ -3325,13 +3329,14 @@ static void* createTable(void *sarg) ...@@ -3325,13 +3329,14 @@ static void* createTable(void *sarg)
len = 0; len = 0;
if (0 != queryDbExec(pThreadInfo->taos, pThreadInfo->buffer, if (0 != queryDbExec(pThreadInfo->taos, pThreadInfo->buffer,
NO_INSERT_TYPE, false)){ NO_INSERT_TYPE, false)) {
errorPrint2("queryDbExec() failed. buffer:\n%s\n", pThreadInfo->buffer); errorPrint2("queryDbExec() failed. buffer:\n%s\n", pThreadInfo->buffer);
free(pThreadInfo->buffer); free(pThreadInfo->buffer);
return NULL; return NULL;
} }
pThreadInfo->tables_created += batchNum;
uint64_t currentPrintTime = taosGetTimestampMs(); uint64_t currentPrintTime = taosGetTimestampMs();
if (currentPrintTime - lastPrintTime > 30*1000) { if (currentPrintTime - lastPrintTime > 30*1000) {
printf("thread[%d] already create %"PRIu64" - %"PRIu64" tables\n", printf("thread[%d] already create %"PRIu64" - %"PRIu64" tables\n",
pThreadInfo->threadID, pThreadInfo->start_table_from, i); pThreadInfo->threadID, pThreadInfo->start_table_from, i);
...@@ -3401,6 +3406,7 @@ static int startMultiThreadCreateChildTable( ...@@ -3401,6 +3406,7 @@ static int startMultiThreadCreateChildTable(
pThreadInfo->use_metric = true; pThreadInfo->use_metric = true;
pThreadInfo->cols = cols; pThreadInfo->cols = cols;
pThreadInfo->minDelay = UINT64_MAX; pThreadInfo->minDelay = UINT64_MAX;
pThreadInfo->tables_created = 0;
pthread_create(pids + i, NULL, createTable, pThreadInfo); pthread_create(pids + i, NULL, createTable, pThreadInfo);
} }
...@@ -3411,6 +3417,8 @@ static int startMultiThreadCreateChildTable( ...@@ -3411,6 +3417,8 @@ static int startMultiThreadCreateChildTable(
for (int i = 0; i < threads; i++) { for (int i = 0; i < threads; i++) {
threadInfo *pThreadInfo = infos + i; threadInfo *pThreadInfo = infos + i;
taos_close(pThreadInfo->taos); taos_close(pThreadInfo->taos);
g_actualChildTables += pThreadInfo->tables_created;
} }
free(pids); free(pids);
...@@ -3437,7 +3445,6 @@ static void createChildTables() { ...@@ -3437,7 +3445,6 @@ static void createChildTables() {
verbosePrint("%s() LN%d: %s\n", __func__, __LINE__, verbosePrint("%s() LN%d: %s\n", __func__, __LINE__,
g_Dbs.db[i].superTbls[j].colsOfCreateChildTable); g_Dbs.db[i].superTbls[j].colsOfCreateChildTable);
uint64_t startFrom = 0; uint64_t startFrom = 0;
g_totalChildTables += g_Dbs.db[i].superTbls[j].childTblCount;
verbosePrint("%s() LN%d: create %"PRId64" child tables from %"PRIu64"\n", verbosePrint("%s() LN%d: create %"PRId64" child tables from %"PRIu64"\n",
__func__, __LINE__, g_totalChildTables, startFrom); __func__, __LINE__, g_totalChildTables, startFrom);
...@@ -4232,6 +4239,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) { ...@@ -4232,6 +4239,7 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
goto PARSE_OVER; goto PARSE_OVER;
} }
g_Dbs.db[i].superTbls[j].childTblCount = count->valueint; g_Dbs.db[i].superTbls[j].childTblCount = count->valueint;
g_totalChildTables += g_Dbs.db[i].superTbls[j].childTblCount;
cJSON *dataSource = cJSON_GetObjectItem(stbInfo, "data_source"); cJSON *dataSource = cJSON_GetObjectItem(stbInfo, "data_source");
if (dataSource && dataSource->type == cJSON_String if (dataSource && dataSource->type == cJSON_String
...@@ -4936,7 +4944,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) { ...@@ -4936,7 +4944,7 @@ static bool getMetaFromQueryJsonFile(cJSON* root) {
cJSON *result = cJSON_GetObjectItem(sql, "result"); cJSON *result = cJSON_GetObjectItem(sql, "result");
if (result != NULL && result->type == cJSON_String if (result != NULL && result->type == cJSON_String
&& result->valuestring != NULL){ && result->valuestring != NULL) {
tstrncpy(g_queryInfo.superQueryInfo.result[j], tstrncpy(g_queryInfo.superQueryInfo.result[j],
result->valuestring, MAX_FILE_NAME_LEN); result->valuestring, MAX_FILE_NAME_LEN);
} else if (NULL == result) { } else if (NULL == result) {
...@@ -7586,7 +7594,7 @@ static void startMultiThreadInsertData(int threads, char* db_name, ...@@ -7586,7 +7594,7 @@ static void startMultiThreadInsertData(int threads, char* db_name,
} }
int ret = taos_stmt_prepare(pThreadInfo->stmt, stmtBuffer, 0); int ret = taos_stmt_prepare(pThreadInfo->stmt, stmtBuffer, 0);
if (ret != 0){ if (ret != 0) {
free(pids); free(pids);
free(infos); free(infos);
free(stmtBuffer); free(stmtBuffer);
...@@ -7932,18 +7940,30 @@ static int insertTestProcess() { ...@@ -7932,18 +7940,30 @@ static int insertTestProcess() {
double start; double start;
double end; double end;
// create child tables
start = taosGetTimestampMs();
createChildTables();
end = taosGetTimestampMs();
if (g_totalChildTables > 0) { if (g_totalChildTables > 0) {
fprintf(stderr, "Spent %.4f seconds to create %"PRId64" tables with %d thread(s)\n\n", fprintf(stderr,
(end - start)/1000.0, g_totalChildTables, g_Dbs.threadCountByCreateTbl); "creating %"PRId64" table(s) with %d thread(s)\n\n",
g_totalChildTables, g_Dbs.threadCountByCreateTbl);
if (g_fpOfInsertResult) {
fprintf(g_fpOfInsertResult,
"creating %"PRId64" table(s) with %d thread(s)\n\n",
g_totalChildTables, g_Dbs.threadCountByCreateTbl);
}
// create child tables
start = taosGetTimestampMs();
createChildTables();
end = taosGetTimestampMs();
fprintf(stderr,
"Spent %.4f seconds to create %"PRId64" table(s) with %d thread(s), actual %"PRId64" table(s) created\n\n",
(end - start)/1000.0, g_totalChildTables,
g_Dbs.threadCountByCreateTbl, g_actualChildTables);
if (g_fpOfInsertResult) { if (g_fpOfInsertResult) {
fprintf(g_fpOfInsertResult, fprintf(g_fpOfInsertResult,
"Spent %.4f seconds to create %"PRId64" tables with %d thread(s)\n\n", "Spent %.4f seconds to create %"PRId64" table(s) with %d thread(s), actual %"PRId64" table(s) created\n\n",
(end - start)/1000.0, g_totalChildTables, g_Dbs.threadCountByCreateTbl); (end - start)/1000.0, g_totalChildTables,
g_Dbs.threadCountByCreateTbl, g_actualChildTables);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册