提交 128e9bb7 编写于 作者: G groot 提交者: jinhai

performance issues (#2438)

* performance issues
Signed-off-by: Nyhmo <yihua.mo@zilliz.com>

* fix bugs
Signed-off-by: Nyhmo <yihua.mo@zilliz.com>

* preload collection issue
Signed-off-by: Nyhmo <yihua.mo@zilliz.com>

* uncomment boring log
Signed-off-by: Nyhmo <yihua.mo@zilliz.com>

* reduce unittest time
Signed-off-by: Nyhmo <yihua.mo@zilliz.com>

* reduce metric test time cost
Signed-off-by: Nyhmo <yihua.mo@zilliz.com>
上级 1251fbf2
......@@ -71,7 +71,8 @@ class DB {
GetCollectionRowCount(const std::string& collection_id, uint64_t& row_count) = 0;
virtual Status
PreloadCollection(const std::string& collection_id) = 0;
PreloadCollection(const std::shared_ptr<server::Context>& context, const std::string& collection_id,
bool force = false) = 0;
virtual Status
UpdateCollectionFlag(const std::string& collection_id, int64_t flag) = 0;
......@@ -108,10 +109,11 @@ class DB {
Flush() = 0;
virtual Status
Compact(const std::string& collection_id, double threshold = 0.0) = 0;
Compact(const std::shared_ptr<server::Context>& context, const std::string& collection_id,
double threshold = 0.0) = 0;
virtual Status
GetVectorsByID(const std::string& collection_id, const IDNumbers& id_array,
GetVectorsByID(const engine::meta::CollectionSchema& collection, const IDNumbers& id_array,
std::vector<engine::VectorsData>& vectors) = 0;
virtual Status
......
此差异已折叠。
......@@ -78,7 +78,8 @@ class DBImpl : public DB, public server::CacheConfigHandler, public server::Engi
GetCollectionInfo(const std::string& collection_id, std::string& collection_info) override;
Status
PreloadCollection(const std::string& collection_id) override;
PreloadCollection(const std::shared_ptr<server::Context>& context, const std::string& collection_id,
bool force = false) override;
Status
UpdateCollectionFlag(const std::string& collection_id, int64_t flag) override;
......@@ -119,10 +120,11 @@ class DBImpl : public DB, public server::CacheConfigHandler, public server::Engi
Flush() override;
Status
Compact(const std::string& collection_id, double threshold = 0.0) override;
Compact(const std::shared_ptr<server::Context>& context, const std::string& collection_id,
double threshold = 0.0) override;
Status
GetVectorsByID(const std::string& collection_id, const IDNumbers& id_array,
GetVectorsByID(const engine::meta::CollectionSchema& collection, const IDNumbers& id_array,
std::vector<engine::VectorsData>& vectors) override;
Status
......@@ -200,8 +202,8 @@ class DBImpl : public DB, public server::CacheConfigHandler, public server::Engi
ResultIds& result_ids, ResultDistances& result_distances);
Status
GetVectorsByIdHelper(const std::string& collection_id, const IDNumbers& id_array,
std::vector<engine::VectorsData>& vectors, meta::FilesHolder& files_holder);
GetVectorsByIdHelper(const IDNumbers& id_array, std::vector<engine::VectorsData>& vectors,
meta::FilesHolder& files_holder);
void
InternalFlush(const std::string& collection_id = "");
......@@ -228,7 +230,7 @@ class DBImpl : public DB, public server::CacheConfigHandler, public server::Engi
StartMetricTask();
void
StartMergeTask(bool force_merge_all = false);
StartMergeTask(const std::set<std::string>& merge_collection_ids, bool force_merge_all = false);
void
BackgroundMerge(std::set<std::string> collection_ids, bool force_merge_all);
......@@ -243,13 +245,7 @@ class DBImpl : public DB, public server::CacheConfigHandler, public server::Engi
BackgroundBuildIndex();
Status
CompactFile(const std::string& collection_id, double threshold, const meta::SegmentSchema& file,
meta::SegmentsSchema& files_to_update);
/*
Status
SyncMemData(std::set<std::string>& sync_collection_ids);
*/
CompactFile(const meta::SegmentSchema& file, double threshold, meta::SegmentsSchema& files_to_update);
Status
GetFilesToBuildIndex(const std::string& collection_id, const std::vector<int>& file_types,
......@@ -355,7 +351,6 @@ class DBImpl : public DB, public server::CacheConfigHandler, public server::Engi
ThreadPool merge_thread_pool_;
std::mutex merge_result_mutex_;
std::list<std::future<void>> merge_thread_results_;
std::set<std::string> merge_collection_ids_;
ThreadPool index_thread_pool_;
std::mutex index_result_mutex_;
......
......@@ -75,6 +75,8 @@ struct DBOptions {
int64_t auto_flush_interval_ = 1;
int64_t file_cleanup_timeout_ = 10;
bool metric_enable_ = false;
// wal relative configurations
bool wal_enable_ = true;
bool recovery_error_ignore_ = true;
......
......@@ -138,6 +138,10 @@ class Meta {
virtual Status
FilesByType(const std::string& collection_id, const std::vector<int>& file_types, FilesHolder& files_holder) = 0;
virtual Status
FilesByTypeEx(const std::vector<meta::CollectionSchema>& collections, const std::vector<int>& file_types,
FilesHolder& files_holder) = 0;
virtual Status
FilesByID(const std::vector<size_t>& ids, FilesHolder& files_holder) = 0;
......
此差异已折叠。
......@@ -124,6 +124,10 @@ class MySQLMetaImpl : public Meta {
FilesByType(const std::string& collection_id, const std::vector<int>& file_types,
FilesHolder& files_holder) override;
Status
FilesByTypeEx(const std::vector<meta::CollectionSchema>& collections, const std::vector<int>& file_types,
FilesHolder& files_holder) override;
Status
FilesByID(const std::vector<size_t>& ids, FilesHolder& files_holder) override;
......
......@@ -23,6 +23,7 @@
#include <memory>
#include <set>
#include <sstream>
#include <unordered_map>
#include "MetaConsts.h"
#include "db/IDGenerator.h"
......@@ -1076,7 +1077,8 @@ SqliteMetaImpl::FilesToSearch(const std::string& collection_id, FilesHolder& fil
// perform query
auto select_columns = columns(&SegmentSchema::id_, &SegmentSchema::collection_id_, &SegmentSchema::segment_id_,
&SegmentSchema::file_id_, &SegmentSchema::file_type_, &SegmentSchema::file_size_,
&SegmentSchema::row_count_, &SegmentSchema::date_, &SegmentSchema::engine_type_);
&SegmentSchema::row_count_, &SegmentSchema::date_, &SegmentSchema::engine_type_,
&SegmentSchema::created_on_, &SegmentSchema::updated_time_);
auto match_collectionid = c(&SegmentSchema::collection_id_) == collection_id;
......@@ -1104,6 +1106,9 @@ SqliteMetaImpl::FilesToSearch(const std::string& collection_id, FilesHolder& fil
collection_file.row_count_ = std::get<6>(file);
collection_file.date_ = std::get<7>(file);
collection_file.engine_type_ = std::get<8>(file);
collection_file.created_on_ = std::get<9>(file);
collection_file.updated_time_ = std::get<10>(file);
collection_file.dimension_ = collection_schema.dimension_;
collection_file.index_file_size_ = collection_schema.index_file_size_;
collection_file.index_params_ = collection_schema.index_params_;
......@@ -1145,18 +1150,15 @@ SqliteMetaImpl::FilesToSearchEx(const std::string& root_collection,
return status;
}
// distribute id array to batchs
const int64_t batch_size = 50;
// distribute id array to batches
const uint64_t batch_size = 50;
std::vector<std::vector<std::string>> id_groups;
std::vector<std::string> temp_group;
int64_t count = 1;
for (auto& id : partition_id_array) {
temp_group.push_back(id);
count++;
if (count >= batch_size) {
if (temp_group.size() >= batch_size) {
id_groups.emplace_back(temp_group);
temp_group.clear();
count = 0;
}
}
......@@ -1171,7 +1173,8 @@ SqliteMetaImpl::FilesToSearchEx(const std::string& root_collection,
auto select_columns =
columns(&SegmentSchema::id_, &SegmentSchema::collection_id_, &SegmentSchema::segment_id_,
&SegmentSchema::file_id_, &SegmentSchema::file_type_, &SegmentSchema::file_size_,
&SegmentSchema::row_count_, &SegmentSchema::date_, &SegmentSchema::engine_type_);
&SegmentSchema::row_count_, &SegmentSchema::date_, &SegmentSchema::engine_type_,
&SegmentSchema::created_on_, &SegmentSchema::updated_time_);
auto match_collectionid = in(&SegmentSchema::collection_id_, group);
......@@ -1197,6 +1200,8 @@ SqliteMetaImpl::FilesToSearchEx(const std::string& root_collection,
collection_file.row_count_ = std::get<6>(file);
collection_file.date_ = std::get<7>(file);
collection_file.engine_type_ = std::get<8>(file);
collection_file.created_on_ = std::get<9>(file);
collection_file.updated_time_ = std::get<10>(file);
collection_file.dimension_ = collection_schema.dimension_;
collection_file.index_file_size_ = collection_schema.index_file_size_;
collection_file.index_params_ = collection_schema.index_params_;
......@@ -1239,9 +1244,11 @@ SqliteMetaImpl::FilesToMerge(const std::string& collection_id, FilesHolder& file
}
// get files to merge
auto select_columns = columns(&SegmentSchema::id_, &SegmentSchema::collection_id_, &SegmentSchema::segment_id_,
&SegmentSchema::file_id_, &SegmentSchema::file_type_, &SegmentSchema::file_size_,
&SegmentSchema::row_count_, &SegmentSchema::date_, &SegmentSchema::created_on_);
auto select_columns =
columns(&SegmentSchema::id_, &SegmentSchema::collection_id_, &SegmentSchema::segment_id_,
&SegmentSchema::file_id_, &SegmentSchema::file_type_, &SegmentSchema::file_size_,
&SegmentSchema::row_count_, &SegmentSchema::date_, &SegmentSchema::engine_type_,
&SegmentSchema::created_on_, &SegmentSchema::updated_time_);
decltype(ConnectorPtr->select(select_columns)) selected;
{
// multi-threads call sqlite update may get exception('bad logic', etc), so we add a lock here
......@@ -1268,7 +1275,10 @@ SqliteMetaImpl::FilesToMerge(const std::string& collection_id, FilesHolder& file
collection_file.file_type_ = std::get<4>(file);
collection_file.row_count_ = std::get<6>(file);
collection_file.date_ = std::get<7>(file);
collection_file.created_on_ = std::get<8>(file);
collection_file.engine_type_ = std::get<8>(file);
collection_file.created_on_ = std::get<9>(file);
collection_file.updated_time_ = std::get<10>(file);
collection_file.dimension_ = collection_schema.dimension_;
collection_file.index_file_size_ = collection_schema.index_file_size_;
collection_file.index_params_ = collection_schema.index_params_;
......@@ -1302,10 +1312,11 @@ SqliteMetaImpl::FilesToIndex(FilesHolder& files_holder) {
server::MetricCollector metric;
auto select_columns = columns(&SegmentSchema::id_, &SegmentSchema::collection_id_, &SegmentSchema::segment_id_,
&SegmentSchema::file_id_, &SegmentSchema::file_type_, &SegmentSchema::file_size_,
&SegmentSchema::row_count_, &SegmentSchema::date_, &SegmentSchema::engine_type_,
&SegmentSchema::created_on_);
auto select_columns =
columns(&SegmentSchema::id_, &SegmentSchema::collection_id_, &SegmentSchema::segment_id_,
&SegmentSchema::file_id_, &SegmentSchema::file_type_, &SegmentSchema::file_size_,
&SegmentSchema::row_count_, &SegmentSchema::date_, &SegmentSchema::engine_type_,
&SegmentSchema::created_on_, &SegmentSchema::updated_time_);
decltype(ConnectorPtr->select(select_columns)) selected;
{
// multi-threads call sqlite update may get exception('bad logic', etc), so we add a lock here
......@@ -1329,6 +1340,7 @@ SqliteMetaImpl::FilesToIndex(FilesHolder& files_holder) {
collection_file.date_ = std::get<7>(file);
collection_file.engine_type_ = std::get<8>(file);
collection_file.created_on_ = std::get<9>(file);
collection_file.updated_time_ = std::get<10>(file);
auto status = utils::GetCollectionFilePath(options_, collection_file);
if (!status.ok()) {
......@@ -1388,7 +1400,8 @@ SqliteMetaImpl::FilesByType(const std::string& collection_id,
auto select_columns =
columns(&SegmentSchema::id_, &SegmentSchema::segment_id_, &SegmentSchema::file_id_,
&SegmentSchema::file_type_, &SegmentSchema::file_size_, &SegmentSchema::row_count_,
&SegmentSchema::date_, &SegmentSchema::engine_type_, &SegmentSchema::created_on_);
&SegmentSchema::date_, &SegmentSchema::engine_type_, &SegmentSchema::created_on_,
&SegmentSchema::updated_time_);
decltype(ConnectorPtr->select(select_columns)) selected;
{
// multi-threads call sqlite update may get exception('bad logic', etc), so we add a lock here
......@@ -1413,6 +1426,7 @@ SqliteMetaImpl::FilesByType(const std::string& collection_id,
file_schema.date_ = std::get<6>(file);
file_schema.engine_type_ = std::get<7>(file);
file_schema.created_on_ = std::get<8>(file);
file_schema.updated_time_ = std::get<9>(file);
file_schema.dimension_ = collection_schema.dimension_;
file_schema.index_file_size_ = collection_schema.index_file_size_;
......@@ -1476,6 +1490,146 @@ SqliteMetaImpl::FilesByType(const std::string& collection_id,
return ret;
}
Status
SqliteMetaImpl::FilesByTypeEx(const std::vector<meta::CollectionSchema>& collections,
const std::vector<int>& file_types,
FilesHolder& files_holder) {
if (file_types.empty()) {
return Status(DB_ERROR, "file types array is empty");
}
Status ret = Status::OK();
try {
fiu_do_on("SqliteMetaImpl.FilesByType.throw_exception", throw std::exception());
// distribute id array to batches
const uint64_t batch_size = 50;
std::vector<std::vector<std::string>> id_groups;
std::vector<std::string> temp_group;
std::unordered_map<std::string, meta::CollectionSchema> map_collections;
for (auto& collection : collections) {
map_collections.insert(std::make_pair(collection.collection_id_, collection));
temp_group.push_back(collection.collection_id_);
if (temp_group.size() >= batch_size) {
id_groups.emplace_back(temp_group);
temp_group.clear();
}
}
if (!temp_group.empty()) {
id_groups.emplace_back(temp_group);
}
// perform query batch by batch
Status ret;
int raw_count = 0, new_count = 0, new_merge_count = 0, new_index_count = 0;
int to_index_count = 0, index_count = 0, backup_count = 0;
for (auto group : id_groups) {
auto select_columns =
columns(&SegmentSchema::id_,
&SegmentSchema::collection_id_,
&SegmentSchema::segment_id_,
&SegmentSchema::file_id_,
&SegmentSchema::file_type_,
&SegmentSchema::file_size_,
&SegmentSchema::row_count_,
&SegmentSchema::date_,
&SegmentSchema::engine_type_,
&SegmentSchema::created_on_,
&SegmentSchema::updated_time_);
decltype(ConnectorPtr->select(select_columns)) selected;
auto match_collectionid = in(&SegmentSchema::collection_id_, group);
std::vector<int> file_types = {(int)SegmentSchema::RAW, (int)SegmentSchema::TO_INDEX,
(int)SegmentSchema::INDEX};
auto match_type = in(&SegmentSchema::file_type_, file_types);
{
// multi-threads call sqlite update may get exception('bad logic', etc), so we add a lock here
std::lock_guard<std::mutex> meta_lock(meta_mutex_);
auto filter = where(match_collectionid and match_type);
selected = ConnectorPtr->select(select_columns, filter);
}
for (auto& file : selected) {
SegmentSchema file_schema;
file_schema.id_ = std::get<0>(file);
file_schema.collection_id_ = std::get<1>(file);
file_schema.segment_id_ = std::get<2>(file);
file_schema.file_id_ = std::get<3>(file);
file_schema.file_type_ = std::get<4>(file);
file_schema.file_size_ = std::get<5>(file);
file_schema.row_count_ = std::get<6>(file);
file_schema.date_ = std::get<7>(file);
file_schema.engine_type_ = std::get<8>(file);
file_schema.created_on_ = std::get<9>(file);
file_schema.updated_time_ = std::get<10>(file);
auto& collection_schema = map_collections[file_schema.collection_id_];
file_schema.dimension_ = collection_schema.dimension_;
file_schema.index_file_size_ = collection_schema.index_file_size_;
file_schema.index_params_ = collection_schema.index_params_;
file_schema.metric_type_ = collection_schema.metric_type_;
switch (file_schema.file_type_) {
case (int)SegmentSchema::RAW:++raw_count;
break;
case (int)SegmentSchema::NEW:++new_count;
break;
case (int)SegmentSchema::NEW_MERGE:++new_merge_count;
break;
case (int)SegmentSchema::NEW_INDEX:++new_index_count;
break;
case (int)SegmentSchema::TO_INDEX:++to_index_count;
break;
case (int)SegmentSchema::INDEX:++index_count;
break;
case (int)SegmentSchema::BACKUP:++backup_count;
break;
default:break;
}
auto status = utils::GetCollectionFilePath(options_, file_schema);
if (!status.ok()) {
ret = status;
}
files_holder.MarkFile(file_schema);
}
}
std::string msg = "Get collection files by type.";
for (int file_type : file_types) {
switch (file_type) {
case (int)SegmentSchema::RAW:msg = msg + " raw files:" + std::to_string(raw_count);
break;
case (int)SegmentSchema::NEW:msg = msg + " new files:" + std::to_string(new_count);
break;
case (int)SegmentSchema::NEW_MERGE:
msg = msg + " new_merge files:" + std::to_string(new_merge_count);
break;
case (int)SegmentSchema::NEW_INDEX:
msg = msg + " new_index files:" + std::to_string(new_index_count);
break;
case (int)SegmentSchema::TO_INDEX:
msg = msg + " to_index files:" + std::to_string(to_index_count);
break;
case (int)SegmentSchema::INDEX:msg = msg + " index files:" + std::to_string(index_count);
break;
case (int)SegmentSchema::BACKUP:msg = msg + " backup files:" + std::to_string(backup_count);
break;
default:break;
}
}
LOG_ENGINE_DEBUG_ << msg;
} catch (std::exception& e) {
return HandleException("Encounter exception when check non index files", e.what());
}
return ret;
}
Status
SqliteMetaImpl::FilesByID(const std::vector<size_t>& ids, FilesHolder& files_holder) {
if (ids.empty()) {
......@@ -1486,9 +1640,17 @@ SqliteMetaImpl::FilesByID(const std::vector<size_t>& ids, FilesHolder& files_hol
server::MetricCollector metric;
fiu_do_on("SqliteMetaImpl.FilesByID.throw_exception", throw std::exception());
auto select_columns = columns(&SegmentSchema::id_, &SegmentSchema::collection_id_, &SegmentSchema::segment_id_,
&SegmentSchema::file_id_, &SegmentSchema::file_type_, &SegmentSchema::file_size_,
&SegmentSchema::row_count_, &SegmentSchema::date_, &SegmentSchema::engine_type_);
auto select_columns = columns(&SegmentSchema::id_,
&SegmentSchema::collection_id_,
&SegmentSchema::segment_id_,
&SegmentSchema::file_id_,
&SegmentSchema::file_type_,
&SegmentSchema::file_size_,
&SegmentSchema::row_count_,
&SegmentSchema::date_,
&SegmentSchema::engine_type_,
&SegmentSchema::created_on_,
&SegmentSchema::updated_time_);
std::vector<int> file_types = {(int)SegmentSchema::RAW, (int)SegmentSchema::TO_INDEX,
(int)SegmentSchema::INDEX};
......@@ -1518,6 +1680,8 @@ SqliteMetaImpl::FilesByID(const std::vector<size_t>& ids, FilesHolder& files_hol
collection_file.row_count_ = std::get<6>(file);
collection_file.date_ = std::get<7>(file);
collection_file.engine_type_ = std::get<8>(file);
collection_file.created_on_ = std::get<9>(file);
collection_file.updated_time_ = std::get<10>(file);
if (collections.find(collection_file.collection_id_) == collections.end()) {
CollectionSchema collection_schema;
......@@ -1943,6 +2107,9 @@ SqliteMetaImpl::SetGlobalLastLSN(uint64_t lsn) {
try {
server::MetricCollector metric;
// multi-threads call sqlite update may get exception('bad logic', etc), so we add a lock here
std::lock_guard<std::mutex> meta_lock(meta_mutex_);
auto selected = ConnectorPtr->select(columns(&EnvironmentSchema::global_lsn_));
if (selected.size() == 0) {
EnvironmentSchema env;
......
......@@ -126,6 +126,10 @@ class SqliteMetaImpl : public Meta {
FilesByType(const std::string& collection_id, const std::vector<int>& file_types,
FilesHolder& files_holder) override;
Status
FilesByTypeEx(const std::vector<meta::CollectionSchema>& collections, const std::vector<int>& file_types,
FilesHolder& files_holder) override;
Status
FilesByID(const std::vector<size_t>& ids, FilesHolder& files_holder) override;
......
......@@ -260,8 +260,10 @@ WalManager::GetNextRecord(MXLogRecord& record) {
}
}
LOG_WAL_INFO_ << "record type " << (int32_t)record.type << " collection " << record.collection_id << " lsn "
<< record.lsn;
if (record.type != MXLogType::None) {
LOG_WAL_INFO_ << "record type " << (int32_t)record.type << " collection " << record.collection_id << " lsn "
<< record.lsn;
}
return error_code;
}
......
......@@ -70,6 +70,13 @@ DBWrapper::StartService() {
return s;
}
// metric config
s = config.GetMetricConfigEnableMonitor(opt.metric_enable_);
if (!s.ok()) {
std::cerr << s.ToString() << std::endl;
return s;
}
// cache config
s = config.GetCacheConfigCacheInsertData(opt.insert_cache_immediately_);
if (!s.ok()) {
......@@ -255,7 +262,7 @@ DBWrapper::PreloadCollections(const std::string& preload_collections) {
db_->AllCollections(table_schema_array);
for (auto& schema : table_schema_array) {
auto status = db_->PreloadCollection(schema.collection_id_);
auto status = db_->PreloadCollection(nullptr, schema.collection_id_);
if (!status.ok()) {
return status;
}
......@@ -264,7 +271,7 @@ DBWrapper::PreloadCollections(const std::string& preload_collections) {
std::vector<std::string> collection_names;
StringHelpFunctions::SplitStringByDelimeter(preload_collections, ",", collection_names);
for (auto& name : collection_names) {
auto status = db_->PreloadCollection(name);
auto status = db_->PreloadCollection(nullptr, name);
if (!status.ok()) {
return status;
}
......
......@@ -70,7 +70,7 @@ CompactRequest::OnExecute() {
rc.RecordSection("check validation");
// step 2: check collection existence
status = DBWrapper::DB()->Compact(collection_name_, compact_threshold_);
status = DBWrapper::DB()->Compact(context_, collection_name_, compact_threshold_);
if (!status.ok()) {
return status;
}
......
......@@ -83,7 +83,7 @@ GetVectorsByIDRequest::OnExecute() {
}
// step 2: get vector data, now only support get one id
return DBWrapper::DB()->GetVectorsByID(collection_name_, ids_, vectors_);
return DBWrapper::DB()->GetVectorsByID(collection_schema, ids_, vectors_);
} catch (std::exception& ex) {
return Status(SERVER_UNEXPECTED_ERROR, ex.what());
}
......
......@@ -60,8 +60,9 @@ PreloadCollectionRequest::OnExecute() {
}
}
// step 2: check collection existence
status = DBWrapper::DB()->PreloadCollection(collection_name_);
// step 2: force load collection data into cache
// load each segment and insert into cache even cache capacity is not enough
status = DBWrapper::DB()->PreloadCollection(context_, collection_name_, true);
fiu_do_on("PreloadCollectionRequest.OnExecute.preload_collection_fail",
status = Status(milvus::SERVER_UNEXPECTED_ERROR, ""));
fiu_do_on("PreloadCollectionRequest.OnExecute.throw_std_exception", throw std::exception());
......
......@@ -32,7 +32,7 @@ namespace {
static const char* COLLECTION_NAME = "test_group";
static constexpr int64_t COLLECTION_DIM = 256;
static constexpr int64_t VECTOR_COUNT = 25000;
static constexpr int64_t VECTOR_COUNT = 5000;
static constexpr int64_t INSERT_LOOP = 100;
static constexpr int64_t SECONDS_EACH_HOUR = 3600;
static constexpr int64_t DAY_SECONDS = 24 * 60 * 60;
......@@ -180,7 +180,7 @@ TEST_F(DBTest, DB_TEST) {
milvus::engine::ResultIds result_ids;
milvus::engine::ResultDistances result_distances;
int k = 10;
std::this_thread::sleep_for(std::chrono::seconds(2));
std::this_thread::sleep_for(std::chrono::seconds(1));
INIT_TIMER;
std::stringstream ss;
......@@ -214,7 +214,7 @@ TEST_F(DBTest, DB_TEST) {
/* LOG(DEBUG) << ss.str(); */
}
ASSERT_TRUE(count >= prev_count);
std::this_thread::sleep_for(std::chrono::seconds(1));
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
});
......@@ -236,7 +236,7 @@ TEST_F(DBTest, DB_TEST) {
stat = db_->Flush();
ASSERT_TRUE(stat.ok());
std::this_thread::sleep_for(std::chrono::microseconds(1));
std::this_thread::sleep_for(std::chrono::milliseconds(20));
}
search.join();
......@@ -455,34 +455,34 @@ TEST_F(DBTest, PRELOAD_TEST) {
db_->CreateIndex(dummy_context_, COLLECTION_NAME, index); // wait until build index finish
int64_t prev_cache_usage = milvus::cache::CpuCacheMgr::GetInstance()->CacheUsage();
stat = db_->PreloadCollection(COLLECTION_NAME);
stat = db_->PreloadCollection(dummy_context_, COLLECTION_NAME);
ASSERT_TRUE(stat.ok());
int64_t cur_cache_usage = milvus::cache::CpuCacheMgr::GetInstance()->CacheUsage();
ASSERT_TRUE(prev_cache_usage < cur_cache_usage);
FIU_ENABLE_FIU("SqliteMetaImpl.FilesToSearch.throw_exception");
stat = db_->PreloadCollection(COLLECTION_NAME);
stat = db_->PreloadCollection(dummy_context_, COLLECTION_NAME);
ASSERT_FALSE(stat.ok());
fiu_disable("SqliteMetaImpl.FilesToSearch.throw_exception");
// create a partition
stat = db_->CreatePartition(COLLECTION_NAME, "part0", "0");
ASSERT_TRUE(stat.ok());
stat = db_->PreloadCollection(COLLECTION_NAME);
stat = db_->PreloadCollection(dummy_context_, COLLECTION_NAME);
ASSERT_TRUE(stat.ok());
FIU_ENABLE_FIU("DBImpl.PreloadCollection.null_engine");
stat = db_->PreloadCollection(COLLECTION_NAME);
stat = db_->PreloadCollection(dummy_context_, COLLECTION_NAME);
ASSERT_FALSE(stat.ok());
fiu_disable("DBImpl.PreloadCollection.null_engine");
FIU_ENABLE_FIU("DBImpl.PreloadCollection.exceed_cache");
stat = db_->PreloadCollection(COLLECTION_NAME);
stat = db_->PreloadCollection(dummy_context_, COLLECTION_NAME);
ASSERT_FALSE(stat.ok());
fiu_disable("DBImpl.PreloadCollection.exceed_cache");
FIU_ENABLE_FIU("DBImpl.PreloadCollection.engine_throw_exception");
stat = db_->PreloadCollection(COLLECTION_NAME);
stat = db_->PreloadCollection(dummy_context_, COLLECTION_NAME);
ASSERT_FALSE(stat.ok());
fiu_disable("DBImpl.PreloadCollection.engine_throw_exception");
}
......@@ -535,15 +535,15 @@ TEST_F(DBTest, SHUTDOWN_TEST) {
stat = db_->DeleteVectors(collection_info.collection_id_, ids_to_delete);
ASSERT_FALSE(stat.ok());
stat = db_->Compact(collection_info.collection_id_);
stat = db_->Compact(dummy_context_, collection_info.collection_id_);
ASSERT_FALSE(stat.ok());
std::vector<milvus::engine::VectorsData> vectors;
std::vector<int64_t> id_array = {0};
stat = db_->GetVectorsByID(collection_info.collection_id_, id_array, vectors);
stat = db_->GetVectorsByID(collection_info, id_array, vectors);
ASSERT_FALSE(stat.ok());
stat = db_->PreloadCollection(collection_info.collection_id_);
stat = db_->PreloadCollection(dummy_context_, collection_info.collection_id_);
ASSERT_FALSE(stat.ok());
uint64_t row_count = 0;
......@@ -612,7 +612,6 @@ TEST_F(DBTest, BACK_TIMER_THREAD_1) {
ASSERT_EQ(xb.id_array_.size(), nb);
}
std::this_thread::sleep_for(std::chrono::seconds(2));
db_->Stop();
fiu_disable("DBImpl.StartMetricTask.InvalidTotalCache");
fiu_disable("SqliteMetaImpl.FilesToMerge.throw_exception");
......@@ -620,7 +619,6 @@ TEST_F(DBTest, BACK_TIMER_THREAD_1) {
FIU_ENABLE_FIU("DBImpl.StartMetricTask.InvalidTotalCache");
db_->Start();
std::this_thread::sleep_for(std::chrono::seconds(2));
db_->Stop();
fiu_disable("DBImpl.StartMetricTask.InvalidTotalCache");
}
......@@ -644,7 +642,6 @@ TEST_F(DBTest, BACK_TIMER_THREAD_2) {
}
FIU_ENABLE_FIU("SqliteMetaImpl.CreateCollectionFile.throw_exception");
std::this_thread::sleep_for(std::chrono::seconds(2));
db_->Stop();
fiu_disable("SqliteMetaImpl.CreateCollectionFile.throw_exception");
}
......@@ -669,7 +666,6 @@ TEST_F(DBTest, BACK_TIMER_THREAD_3) {
FIU_ENABLE_FIU("DBImpl.MergeFiles.Serialize_ThrowException");
db_->Start();
std::this_thread::sleep_for(std::chrono::seconds(2));
db_->Stop();
fiu_disable("DBImpl.MergeFiles.Serialize_ThrowException");
}
......@@ -694,7 +690,6 @@ TEST_F(DBTest, BACK_TIMER_THREAD_4) {
FIU_ENABLE_FIU("DBImpl.MergeFiles.Serialize_ErrorStatus");
db_->Start();
std::this_thread::sleep_for(std::chrono::seconds(2));
db_->Stop();
fiu_disable("DBImpl.MergeFiles.Serialize_ErrorStatus");
}
......@@ -934,11 +929,9 @@ TEST_F(DBTest2, ARHIVE_DISK_CHECK) {
BuildVectors(nb, i, xb);
db_->InsertVectors(COLLECTION_NAME, "", xb);
std::this_thread::sleep_for(std::chrono::microseconds(1));
}
std::this_thread::sleep_for(std::chrono::seconds(1));
db_->Flush();
db_->Size(size);
LOG(DEBUG) << "size=" << size;
ASSERT_LE(size, 1 * milvus::engine::GB);
......@@ -981,8 +974,6 @@ TEST_F(DBTest2, DELETE_TEST) {
fiu_disable("DBImpl.DropCollectionRecursively.failed");
stat = db_->DropCollection(COLLECTION_NAME);
std::this_thread::sleep_for(std::chrono::seconds(2));
ASSERT_TRUE(stat.ok());
db_->HasCollection(COLLECTION_NAME, has_collection);
......@@ -1183,7 +1174,9 @@ TEST_F(DBTest2, FLUSH_NON_EXISTING_COLLECTION) {
TEST_F(DBTest2, GET_VECTOR_NON_EXISTING_COLLECTION) {
std::vector<milvus::engine::VectorsData> vectors;
std::vector<int64_t> id_array = {0};
auto status = db_->GetVectorsByID("non_existing", id_array, vectors);
milvus::engine::meta::CollectionSchema collection_info;
collection_info.collection_id_ = "non_existing";
auto status = db_->GetVectorsByID(collection_info, id_array, vectors);
ASSERT_FALSE(status.ok());
}
......@@ -1203,7 +1196,7 @@ TEST_F(DBTest2, GET_VECTOR_BY_ID_TEST) {
std::vector<milvus::engine::VectorsData> vectors;
std::vector<int64_t> empty_array;
stat = db_->GetVectorsByID(COLLECTION_NAME, empty_array, vectors);
stat = db_->GetVectorsByID(collection_info, empty_array, vectors);
ASSERT_FALSE(stat.ok());
stat = db_->InsertVectors(collection_info.collection_id_, partition_tag, qxb);
......@@ -1211,7 +1204,7 @@ TEST_F(DBTest2, GET_VECTOR_BY_ID_TEST) {
db_->Flush(collection_info.collection_id_);
stat = db_->GetVectorsByID(COLLECTION_NAME, qxb.id_array_, vectors);
stat = db_->GetVectorsByID(collection_info, qxb.id_array_, vectors);
ASSERT_TRUE(stat.ok());
ASSERT_EQ(vectors.size(), qxb.id_array_.size());
ASSERT_EQ(vectors[0].float_data_.size(), COLLECTION_DIM);
......@@ -1221,7 +1214,7 @@ TEST_F(DBTest2, GET_VECTOR_BY_ID_TEST) {
}
std::vector<int64_t> invalid_array = {-1, -1};
stat = db_->GetVectorsByID(COLLECTION_NAME, empty_array, vectors);
stat = db_->GetVectorsByID(collection_info, empty_array, vectors);
ASSERT_TRUE(stat.ok());
for (auto& vector : vectors) {
ASSERT_EQ(vector.vector_count_, 0);
......@@ -1344,7 +1337,7 @@ TEST_F(DBTest2, SEARCH_WITH_DIFFERENT_INDEX) {
stat = db_->CreateIndex(dummy_context_, collection_info.collection_id_, index);
ASSERT_TRUE(stat.ok());
stat = db_->PreloadCollection(collection_info.collection_id_);
stat = db_->PreloadCollection(dummy_context_, collection_info.collection_id_);
ASSERT_TRUE(stat.ok());
int topk = 10, nprobe = 10;
......@@ -1369,7 +1362,7 @@ result_distances);
stat = db_->CreateIndex(dummy_context_, collection_info.collection_id_, index);
ASSERT_TRUE(stat.ok());
stat = db_->PreloadCollection(collection_info.collection_id_);
stat = db_->PreloadCollection(dummy_context_, collection_info.collection_id_);
ASSERT_TRUE(stat.ok());
for (auto id : ids_to_search) {
......
......@@ -72,7 +72,7 @@ TEST_F(MySqlDBTest, DB_TEST) {
milvus::engine::ResultIds result_ids;
milvus::engine::ResultDistances result_distances;
int k = 10;
std::this_thread::sleep_for(std::chrono::seconds(2));
std::this_thread::sleep_for(std::chrono::seconds(1));
INIT_TIMER;
std::stringstream ss;
......@@ -106,7 +106,7 @@ TEST_F(MySqlDBTest, DB_TEST) {
/* LOG(DEBUG) << ss.str(); */
}
ASSERT_TRUE(count >= prev_count);
std::this_thread::sleep_for(std::chrono::seconds(1));
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
});
......@@ -128,7 +128,7 @@ TEST_F(MySqlDBTest, DB_TEST) {
stat = db_->Flush();
ASSERT_TRUE(stat.ok());
std::this_thread::sleep_for(std::chrono::microseconds(1));
std::this_thread::sleep_for(std::chrono::milliseconds(20));
}
search.join();
......@@ -183,7 +183,6 @@ TEST_F(MySqlDBTest, SEARCH_TEST) {
stat = db_->InsertVectors(COLLECTION_NAME, "", xb);
ASSERT_TRUE(stat.ok());
// sleep(2); // wait until build index finish
stat = db_->Flush();
ASSERT_TRUE(stat.ok());
......@@ -241,10 +240,8 @@ TEST_F(MySqlDBTest, ARHIVE_DISK_CHECK) {
milvus::engine::VectorsData xb;
BuildVectors(nb, i, xb);
db_->InsertVectors(COLLECTION_NAME, "", xb);
std::this_thread::sleep_for(std::chrono::microseconds(1));
}
// std::this_thread::sleep_for(std::chrono::seconds(1));
stat = db_->Flush();
ASSERT_TRUE(stat.ok());
......@@ -288,16 +285,12 @@ TEST_F(MySqlDBTest, DELETE_TEST) {
milvus::engine::VectorsData xb;
BuildVectors(nb, i, xb);
db_->InsertVectors(COLLECTION_NAME, "", xb);
std::this_thread::sleep_for(std::chrono::microseconds(1));
}
stat = db_->Flush();
ASSERT_TRUE(stat.ok());
stat = db_->DropCollection(COLLECTION_NAME);
//// std::cout << "5 sec start" << std::endl;
// std::this_thread::sleep_for(std::chrono::seconds(5));
//// std::cout << "5 sec finish" << std::endl;
ASSERT_TRUE(stat.ok());
//
db_->HasCollection(COLLECTION_NAME, has_collection);
......
......@@ -287,7 +287,7 @@ TEST_F(DeleteTest, delete_before_create_index) {
ASSERT_TRUE(stat.ok());
ASSERT_EQ(collection_info_get.dimension_, COLLECTION_DIM);
int64_t nb = 10000;
int64_t nb = 5000;
milvus::engine::VectorsData xb;
BuildVectors(nb, xb);
......@@ -369,7 +369,7 @@ TEST_F(DeleteTest, delete_with_index) {
ASSERT_TRUE(stat.ok());
ASSERT_EQ(collection_info_get.dimension_, COLLECTION_DIM);
int64_t nb = 10000;
int64_t nb = 5000;
milvus::engine::VectorsData xb;
BuildVectors(nb, xb);
......@@ -451,7 +451,7 @@ TEST_F(DeleteTest, delete_multiple_times_with_index) {
ASSERT_TRUE(stat.ok());
ASSERT_EQ(collection_info_get.dimension_, COLLECTION_DIM);
int64_t nb = 100000;
int64_t nb = 5000;
milvus::engine::VectorsData xb;
BuildVectors(nb, xb);
......@@ -749,7 +749,7 @@ TEST_F(CompactTest, compact_basic) {
ASSERT_TRUE(stat.ok());
ASSERT_EQ(row_count, nb - 2);
stat = db_->Compact(collection_info.collection_id_);
stat = db_->Compact(dummy_context_, collection_info.collection_id_);
ASSERT_TRUE(stat.ok());
const int topk = 1, nprobe = 1;
......@@ -834,7 +834,7 @@ TEST_F(CompactTest, compact_with_index) {
ASSERT_TRUE(stat.ok());
ASSERT_EQ(row_count, nb - ids_to_delete.size());
stat = db_->Compact(collection_info.collection_id_);
stat = db_->Compact(dummy_context_, collection_info.collection_id_);
ASSERT_TRUE(stat.ok());
stat = db_->GetCollectionRowCount(collection_info.collection_id_, row_count);
......@@ -864,6 +864,6 @@ TEST_F(CompactTest, compact_with_index) {
}
TEST_F(CompactTest, compact_non_existing_table) {
auto status = db_->Compact("non_existing_table");
auto status = db_->Compact(dummy_context_, "non_existing_table");
ASSERT_FALSE(status.ok());
}
......@@ -282,7 +282,7 @@ TEST_F(DBTest, COMPACT_TEST) {
stat = db_->Flush();
ASSERT_TRUE(stat.ok());
stat = db_->Compact(collection_info.collection_id_);
stat = db_->Compact(dummy_context_, collection_info.collection_id_);
ASSERT_TRUE(stat.ok());
const int topk = 1, nprobe = 1;
......
......@@ -318,20 +318,15 @@ TEST_F(MemManagerTest2, INSERT_TEST) {
ASSERT_TRUE(stat.ok());
ASSERT_EQ(collection_info_get.dimension_, COLLECTION_DIM);
auto start_time = METRICS_NOW_TIME;
int insert_loop = 20;
int insert_loop = 10;
for (int i = 0; i < insert_loop; ++i) {
int64_t nb = 40960;
int64_t nb = 4096;
milvus::engine::VectorsData xb;
BuildVectors(nb, xb);
milvus::engine::IDNumbers vector_ids;
stat = db_->InsertVectors(GetCollectionName(), "", xb);
ASSERT_TRUE(stat.ok());
}
auto end_time = METRICS_NOW_TIME;
auto total_time = METRICS_MICROSECONDS(start_time, end_time);
LOG(DEBUG) << "total_time spent in INSERT_TEST (ms) : " << total_time;
}
TEST_F(MemManagerTest2, INSERT_BINARY_TEST) {
......
......@@ -86,7 +86,7 @@ TEST_F(SearchByIdTest, BASIC_TEST) {
ASSERT_TRUE(stat.ok());
ASSERT_EQ(collection_info_get.dimension_, COLLECTION_DIM);
int64_t nb = 100000;
int64_t nb = 10000;
milvus::engine::VectorsData xb;
BuildVectors(nb, xb);
......@@ -185,7 +185,7 @@ TEST_F(SearchByIdTest, WITH_INDEX_TEST) {
ASSERT_TRUE(stat.ok());
ASSERT_EQ(collection_info_get.dimension_, COLLECTION_DIM);
int64_t nb = 10000;
int64_t nb = 5000;
milvus::engine::VectorsData xb;
BuildVectors(nb, xb);
......@@ -246,7 +246,7 @@ TEST_F(SearchByIdTest, WITH_DELETE_TEST) {
ASSERT_TRUE(stat.ok());
ASSERT_EQ(collection_info_get.dimension_, COLLECTION_DIM);
int64_t nb = 100000;
int64_t nb = 10000;
milvus::engine::VectorsData xb;
BuildVectors(nb, xb);
......@@ -315,7 +315,7 @@ TEST_F(GetVectorByIdTest, BASIC_TEST) {
ASSERT_TRUE(stat.ok());
ASSERT_EQ(collection_info_get.dimension_, COLLECTION_DIM);
int64_t nb = 100000;
int64_t nb = 10000;
milvus::engine::VectorsData xb;
BuildVectors(nb, xb);
......@@ -349,7 +349,7 @@ TEST_F(GetVectorByIdTest, BASIC_TEST) {
milvus::engine::ResultDistances result_distances;
std::vector<milvus::engine::VectorsData> vectors;
stat = db_->GetVectorsByID(collection_info.collection_id_, ids_to_search, vectors);
stat = db_->GetVectorsByID(collection_info, ids_to_search, vectors);
ASSERT_TRUE(stat.ok());
stat = db_->Query(dummy_context_, collection_info.collection_id_, tags, topk, json_params, vectors[0], result_ids,
......@@ -369,7 +369,7 @@ TEST_F(GetVectorByIdTest, WITH_INDEX_TEST) {
ASSERT_TRUE(stat.ok());
ASSERT_EQ(collection_info_get.dimension_, COLLECTION_DIM);
int64_t nb = 10000;
int64_t nb = 5000;
milvus::engine::VectorsData xb;
BuildVectors(nb, xb);
......@@ -409,7 +409,7 @@ TEST_F(GetVectorByIdTest, WITH_INDEX_TEST) {
milvus::engine::ResultDistances result_distances;
std::vector<milvus::engine::VectorsData> vectors;
stat = db_->GetVectorsByID(collection_info.collection_id_, ids_to_search, vectors);
stat = db_->GetVectorsByID(collection_info, ids_to_search, vectors);
ASSERT_TRUE(stat.ok());
stat = db_->Query(dummy_context_, collection_info.collection_id_, tags, topk, json_params, vectors[0], result_ids,
......@@ -429,7 +429,7 @@ TEST_F(GetVectorByIdTest, WITH_DELETE_TEST) {
ASSERT_TRUE(stat.ok());
ASSERT_EQ(collection_info_get.dimension_, COLLECTION_DIM);
int64_t nb = 100000;
int64_t nb = 10000;
milvus::engine::VectorsData xb;
BuildVectors(nb, xb);
......@@ -469,7 +469,7 @@ TEST_F(GetVectorByIdTest, WITH_DELETE_TEST) {
milvus::engine::ResultDistances result_distances;
std::vector<milvus::engine::VectorsData> vectors;
stat = db_->GetVectorsByID(collection_info.collection_id_, ids_to_search, vectors);
stat = db_->GetVectorsByID(collection_info, ids_to_search, vectors);
ASSERT_TRUE(stat.ok());
for (auto& vector : vectors) {
ASSERT_EQ(vector.vector_count_, 0);
......@@ -541,7 +541,7 @@ TEST_F(SearchByIdTest, BINARY_TEST) {
milvus::engine::ResultDistances result_distances;
std::vector<milvus::engine::VectorsData> vectors;
stat = db_->GetVectorsByID(collection_info.collection_id_, ids_to_search, vectors);
stat = db_->GetVectorsByID(collection_info, ids_to_search, vectors);
ASSERT_TRUE(stat.ok());
ASSERT_EQ(vectors.size(), ids_to_search.size());
......
......@@ -89,7 +89,7 @@ TEST_F(MetricTest, METRIC_TEST) {
// std::vector<std::string> tags;
// milvus::engine::ResultIds result_ids;
// milvus::engine::ResultDistances result_distances;
std::this_thread::sleep_for(std::chrono::seconds(2));
std::this_thread::sleep_for(std::chrono::seconds(1));
INIT_TIMER;
std::stringstream ss;
......@@ -115,11 +115,11 @@ TEST_F(MetricTest, METRIC_TEST) {
// }
}
ASSERT_TRUE(count >= prev_count);
std::this_thread::sleep_for(std::chrono::seconds(1));
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
});
int loop = 10000;
int loop = 100;
for (auto i = 0; i < loop; ++i) {
if (i == 40) {
......@@ -131,7 +131,7 @@ TEST_F(MetricTest, METRIC_TEST) {
db_->InsertVectors(group_name, "", xb);
ASSERT_EQ(xb.id_array_.size(), nb);
}
std::this_thread::sleep_for(std::chrono::microseconds(2000));
std::this_thread::sleep_for(std::chrono::milliseconds(20));
}
search.join();
......
......@@ -813,7 +813,7 @@ TEST(UtilTest, ROLLOUTHANDLER_TEST) {
TEST(UtilTest, THREADPOOL_TEST) {
auto thread_pool_ptr = std::make_unique<milvus::ThreadPool>(3);
auto fun = [](int i) {
sleep(1);
std::this_thread::sleep_for(std::chrono::milliseconds(50));
};
for (int i = 0; i < 10; ++i) {
thread_pool_ptr->enqueue(fun, i);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册