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(idxJsonUT "")
|
||||
add_executable(idxFstUtilUT "")
|
||||
add_executable(idxBench "")
|
||||
|
||||
target_sources(idxTest
|
||||
PRIVATE
|
||||
|
@ -32,6 +33,10 @@ IF(NOT TD_DARWIN)
|
|||
PRIVATE
|
||||
"fstUtilUT.cc"
|
||||
)
|
||||
target_sources(idxBench
|
||||
PRIVATE
|
||||
"indexBench.cc"
|
||||
)
|
||||
|
||||
target_include_directories (idxTest
|
||||
PUBLIC
|
||||
|
@ -80,6 +85,16 @@ IF(NOT TD_DARWIN)
|
|||
"${TD_SOURCE_DIR}/include/libs/index"
|
||||
"${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
|
||||
os
|
||||
|
@ -102,11 +117,7 @@ IF(NOT TD_DARWIN)
|
|||
gtest_main
|
||||
index
|
||||
)
|
||||
target_include_directories (idxJsonUT
|
||||
PUBLIC
|
||||
"${TD_SOURCE_DIR}/include/libs/index"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
|
||||
target_link_libraries (idxTest
|
||||
os
|
||||
util
|
||||
|
@ -151,6 +162,13 @@ IF(NOT TD_DARWIN)
|
|||
gtest_main
|
||||
index
|
||||
)
|
||||
target_link_libraries (idxBench
|
||||
os
|
||||
util
|
||||
common
|
||||
gtest_main
|
||||
index
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME idxJsonUT
|
||||
|
@ -174,4 +192,8 @@ IF(NOT TD_DARWIN)
|
|||
NAME idxFstUT
|
||||
COMMAND idxFstUT
|
||||
)
|
||||
add_test(
|
||||
NAME idxBench
|
||||
COMMAND idxBench
|
||||
)
|
||||
ENDIF ()
|
||||
|
|
|
@ -18,8 +18,18 @@
|
|||
#include <string>
|
||||
#include <thread>
|
||||
#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;
|
||||
|
||||
static std::string logDir = TD_TMP_DIR_PATH "log";
|
||||
|
||||
static void initLog() {
|
||||
const char *defaultLogFileNamePrefix = "taoslog";
|
||||
const int32_t maxLogFileNum = 10;
|
||||
|
@ -42,18 +52,20 @@ class Idx {
|
|||
public:
|
||||
Idx(int _cacheSize = 1024 * 1024 * 4, const char *_path = "tindex") {
|
||||
opts.cacheSize = _cacheSize;
|
||||
path = TD_TMP_DIR_PATH _path;
|
||||
path += TD_TMP_DIR_PATH;
|
||||
path += _path;
|
||||
}
|
||||
int SetUp(bool remove) {
|
||||
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;
|
||||
}
|
||||
int Write(WriteBatch *batch) {
|
||||
int Write(WriteBatch *batch, uint64_t uid) {
|
||||
// write batch
|
||||
indexJsonPut(index, batch->terms, uid);
|
||||
return 0;
|
||||
}
|
||||
int Read(const char *json, void *key, int64_t *id) {
|
||||
|
@ -69,7 +81,49 @@ class Idx {
|
|||
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; }
|
||||
|
||||
|
@ -81,5 +135,6 @@ int main() {
|
|||
} else {
|
||||
std::cout << "succ to setup index" << std::endl;
|
||||
}
|
||||
BenchWrite(idx, 10000, 100);
|
||||
BenchWrite(idx, 100, 10000);
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue