fix: add bench
This commit is contained in:
parent
3acd4d3afc
commit
ee7a18db29
|
@ -5,6 +5,7 @@ IF(NOT TD_DARWIN)
|
||||||
add_executable(idxUtilUT "")
|
add_executable(idxUtilUT "")
|
||||||
add_executable(idxJsonUT "")
|
add_executable(idxJsonUT "")
|
||||||
add_executable(idxFstUtilUT "")
|
add_executable(idxFstUtilUT "")
|
||||||
|
add_executable(idxBench "")
|
||||||
|
|
||||||
target_sources(idxTest
|
target_sources(idxTest
|
||||||
PRIVATE
|
PRIVATE
|
||||||
|
@ -32,6 +33,10 @@ IF(NOT TD_DARWIN)
|
||||||
PRIVATE
|
PRIVATE
|
||||||
"fstUtilUT.cc"
|
"fstUtilUT.cc"
|
||||||
)
|
)
|
||||||
|
target_sources(idxBench
|
||||||
|
PRIVATE
|
||||||
|
"indexBench.cc"
|
||||||
|
)
|
||||||
|
|
||||||
target_include_directories (idxTest
|
target_include_directories (idxTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
|
@ -80,6 +85,16 @@ IF(NOT TD_DARWIN)
|
||||||
"${TD_SOURCE_DIR}/include/libs/index"
|
"${TD_SOURCE_DIR}/include/libs/index"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
|
target_include_directories (idxJsonUT
|
||||||
|
PUBLIC
|
||||||
|
"${TD_SOURCE_DIR}/include/libs/index"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
|
)
|
||||||
|
target_include_directories (idxBench
|
||||||
|
PUBLIC
|
||||||
|
"${TD_SOURCE_DIR}/include/libs/index"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
|
)
|
||||||
|
|
||||||
target_link_libraries (idxTest
|
target_link_libraries (idxTest
|
||||||
os
|
os
|
||||||
|
@ -102,11 +117,7 @@ IF(NOT TD_DARWIN)
|
||||||
gtest_main
|
gtest_main
|
||||||
index
|
index
|
||||||
)
|
)
|
||||||
target_include_directories (idxJsonUT
|
|
||||||
PUBLIC
|
|
||||||
"${TD_SOURCE_DIR}/include/libs/index"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
|
||||||
)
|
|
||||||
target_link_libraries (idxTest
|
target_link_libraries (idxTest
|
||||||
os
|
os
|
||||||
util
|
util
|
||||||
|
@ -151,6 +162,13 @@ IF(NOT TD_DARWIN)
|
||||||
gtest_main
|
gtest_main
|
||||||
index
|
index
|
||||||
)
|
)
|
||||||
|
target_link_libraries (idxBench
|
||||||
|
os
|
||||||
|
util
|
||||||
|
common
|
||||||
|
gtest_main
|
||||||
|
index
|
||||||
|
)
|
||||||
|
|
||||||
add_test(
|
add_test(
|
||||||
NAME idxJsonUT
|
NAME idxJsonUT
|
||||||
|
@ -174,4 +192,8 @@ IF(NOT TD_DARWIN)
|
||||||
NAME idxFstUT
|
NAME idxFstUT
|
||||||
COMMAND idxFstUT
|
COMMAND idxFstUT
|
||||||
)
|
)
|
||||||
|
add_test(
|
||||||
|
NAME idxBench
|
||||||
|
COMMAND idxBench
|
||||||
|
)
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
|
@ -18,8 +18,18 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include "index.h"
|
#include "index.h"
|
||||||
|
#include "indexCache.h"
|
||||||
|
#include "indexFst.h"
|
||||||
|
#include "indexFstUtil.h"
|
||||||
|
#include "indexInt.h"
|
||||||
|
#include "indexTfile.h"
|
||||||
|
#include "indexUtil.h"
|
||||||
|
#include "tskiplist.h"
|
||||||
|
#include "tutil.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
static std::string logDir = TD_TMP_DIR_PATH "log";
|
||||||
|
|
||||||
static void initLog() {
|
static void initLog() {
|
||||||
const char *defaultLogFileNamePrefix = "taoslog";
|
const char *defaultLogFileNamePrefix = "taoslog";
|
||||||
const int32_t maxLogFileNum = 10;
|
const int32_t maxLogFileNum = 10;
|
||||||
|
@ -42,18 +52,20 @@ class Idx {
|
||||||
public:
|
public:
|
||||||
Idx(int _cacheSize = 1024 * 1024 * 4, const char *_path = "tindex") {
|
Idx(int _cacheSize = 1024 * 1024 * 4, const char *_path = "tindex") {
|
||||||
opts.cacheSize = _cacheSize;
|
opts.cacheSize = _cacheSize;
|
||||||
path = TD_TMP_DIR_PATH _path;
|
path += TD_TMP_DIR_PATH;
|
||||||
|
path += _path;
|
||||||
}
|
}
|
||||||
int SetUp(bool remove) {
|
int SetUp(bool remove) {
|
||||||
initLog();
|
initLog();
|
||||||
|
|
||||||
if (remove) taosRemoveDir(path);
|
if (remove) taosRemoveDir(path.c_str());
|
||||||
|
|
||||||
int ret = indexJsonOpen(&opts, path, &index);
|
int ret = indexJsonOpen(&opts, path.c_str(), &index);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
int Write(WriteBatch *batch) {
|
int Write(WriteBatch *batch, uint64_t uid) {
|
||||||
// write batch
|
// write batch
|
||||||
|
indexJsonPut(index, batch->terms, uid);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int Read(const char *json, void *key, int64_t *id) {
|
int Read(const char *json, void *key, int64_t *id) {
|
||||||
|
@ -69,7 +81,49 @@ class Idx {
|
||||||
SIndex *index;
|
SIndex *index;
|
||||||
};
|
};
|
||||||
|
|
||||||
int BenchWrite(Idx *idx, int nCol, int Limit) { return 0; }
|
SIndexTerm *indexTermCreateT(int64_t suid, SIndexOperOnColumn oper, uint8_t colType, const char *colName,
|
||||||
|
int32_t nColName, const char *colVal, int32_t nColVal) {
|
||||||
|
char buf[256] = {0};
|
||||||
|
int16_t sz = nColVal;
|
||||||
|
memcpy(buf, (uint16_t *)&sz, 2);
|
||||||
|
memcpy(buf + 2, colVal, nColVal);
|
||||||
|
if (colType == TSDB_DATA_TYPE_BINARY) {
|
||||||
|
return indexTermCreate(suid, oper, colType, colName, nColName, buf, sizeof(buf));
|
||||||
|
} else {
|
||||||
|
return indexTermCreate(suid, oper, colType, colName, nColName, colVal, nColVal);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
int initWriteBatch(WriteBatch *wb, int batchSize) {
|
||||||
|
SIndexMultiTerm *terms = indexMultiTermCreate();
|
||||||
|
|
||||||
|
std::string colName;
|
||||||
|
std::string colVal;
|
||||||
|
|
||||||
|
for (int i = 0; i < 64; i++) {
|
||||||
|
colName += '0' + i;
|
||||||
|
colVal += '0' + i;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < batchSize; i++) {
|
||||||
|
colVal[i % colVal.size()] = '0' + i % 128;
|
||||||
|
colName[i % colName.size()] = '0' + i % 128;
|
||||||
|
SIndexTerm *term = indexTermCreateT(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||||
|
colVal.c_str(), colVal.size());
|
||||||
|
indexMultiTermAdd(terms, term);
|
||||||
|
}
|
||||||
|
|
||||||
|
wb->terms = terms;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int BenchWrite(Idx *idx, int batchSize, int limit) {
|
||||||
|
for (int i = 0; i < limit; i += batchSize) {
|
||||||
|
WriteBatch wb;
|
||||||
|
idx->Write(&wb, i);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int BenchRead(Idx *idx) { return 0; }
|
int BenchRead(Idx *idx) { return 0; }
|
||||||
|
|
||||||
|
@ -81,5 +135,6 @@ int main() {
|
||||||
} else {
|
} else {
|
||||||
std::cout << "succ to setup index" << std::endl;
|
std::cout << "succ to setup index" << std::endl;
|
||||||
}
|
}
|
||||||
BenchWrite(idx, 10000, 100);
|
BenchWrite(idx, 100, 10000);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue