From a0d824497845cca52ce795c1b0453eb44cac20b7 Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Sun, 29 Aug 2021 10:11:17 +0800 Subject: [PATCH] schemaless: add multi-thread performance test --- tests/examples/c/schemaless.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/tests/examples/c/schemaless.c b/tests/examples/c/schemaless.c index 6d1b257d4c..43e9e16978 100644 --- a/tests/examples/c/schemaless.c +++ b/tests/examples/c/schemaless.c @@ -10,7 +10,7 @@ int numThreads = 8; int numSuperTables = 8; -int numChildTablesPerThread = 4; +int numChildTables = 4; // per thread, per super table int numRowsPerChildTable = 2048; void shuffle(char** lines, size_t n) { @@ -42,6 +42,7 @@ typedef struct { TAOS* taos; char** lines; int numLines; + int64_t costTime; } SThreadInsertArgs; static void* insertLines(void* args) { @@ -52,6 +53,7 @@ static void* insertLines(void* args) { int64_t begin = getTimeInUs(); int32_t code = taos_insert_lines(insertArgs->taos, insertArgs->lines, insertArgs->numLines); int64_t end = getTimeInUs(); + insertArgs->costTime = end-begin; printf("code: %d, %s. time used:%"PRId64", thread: 0x%s\n", code, tstrerror(code), end - begin, tidBuf); return NULL; } @@ -91,8 +93,8 @@ int main(int argc, char* argv[]) { for (int i = 0; i < numSuperTables; i++) { char* lineStb = calloc(512, 1); snprintf(lineStb, 512, lineFormat, i, - numThreads * numSuperTables * numChildTablesPerThread, - ts + numThreads * numSuperTables * numChildTablesPerThread * numRowsPerChildTable); + numThreads * numSuperTables * numChildTables, + ts + numThreads * numSuperTables * numChildTables * numRowsPerChildTable); linesStb[i] = lineStb; } SThreadInsertArgs args = {0}; @@ -109,7 +111,7 @@ int main(int argc, char* argv[]) { printf("generate lines...\n"); char*** linesThread = calloc(numThreads, sizeof(char**)); for (int i = 0; i < numThreads; ++i) { - char** lines = calloc(numSuperTables * numChildTablesPerThread * numRowsPerChildTable, sizeof(char*)); + char** lines = calloc(numSuperTables * numChildTables * numRowsPerChildTable, sizeof(char*)); linesThread[i] = lines; } @@ -117,10 +119,10 @@ int main(int argc, char* argv[]) { int l = 0; char** lines = linesThread[t]; for (int i = 0; i < numSuperTables; ++i) { - for (int j = 0; j < numChildTablesPerThread; ++j) { + for (int j = 0; j < numChildTables; ++j) { for (int k = 0; k < numRowsPerChildTable; ++k) { int stIdx = i; - int ctIdx = t*numSuperTables*numChildTablesPerThread + j; + int ctIdx = t*numSuperTables*numChildTables + j; char* line = calloc(512, 1); snprintf(line, 512, lineFormat, stIdx, ctIdx, ts + 10 * l); lines[l] = line; @@ -132,24 +134,35 @@ int main(int argc, char* argv[]) { printf("shuffle lines...\n"); for (int t = 0; t < numThreads; ++t) { - shuffle(linesThread[t], numSuperTables * numChildTablesPerThread * numRowsPerChildTable); + shuffle(linesThread[t], numSuperTables * numChildTables * numRowsPerChildTable); } - printf("begin multi-thread insertion..."); + printf("begin multi-thread insertion...\n"); + int64_t begin = taosGetTimestampUs(); pthread_t* tids = calloc(numThreads, sizeof(pthread_t)); SThreadInsertArgs* argsThread = calloc(numThreads, sizeof(SThreadInsertArgs)); for (int i=0; i < numThreads; ++i) { argsThread[i].lines = linesThread[i]; argsThread[i].taos = taos; - argsThread[i].numLines = numSuperTables * numChildTablesPerThread * numRowsPerChildTable; + argsThread[i].numLines = numSuperTables * numChildTables * numRowsPerChildTable; pthread_create(tids+i, NULL, insertLines, argsThread+i); } - for (int i = 0; i < numThreads; ++i) { pthread_join(tids[i], NULL); } - + int64_t end = taosGetTimestampUs(); + + int totalLines = numThreads*numSuperTables*numChildTables*numRowsPerChildTable; + printf("TOTAL LINES: %d\n", totalLines); + printf("THREADS: %d\n", numThreads); + int64_t sumTime = 0; + for (int i=0; i