This repository has been archived by the owner on Aug 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: lixinguo <[email protected]>
- Loading branch information
lixinguo
committed
Sep 27, 2022
1 parent
75177e4
commit d2cc1de
Showing
11 changed files
with
171 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (C) 2019-2020 Zilliz. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software distributed under the License | ||
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
// or implied. See the License for the specific language governing permissions and limitations under the License. | ||
|
||
#include "unittest/ThreadChecker.h" | ||
|
||
namespace knowhere::threadchecker { | ||
|
||
#define MAX_THREAD_NUM 100000 | ||
#define MIN_THREAD_NUM 0 | ||
#define THREAD_LENGTH 7 // the length of max_thread_num +1 | ||
|
||
int32_t | ||
GetBuildOmpThread(const Config& conf) { | ||
return CheckKeyInConfig(conf, meta::BUILD_INDEX_OMP_NUM) ? GetMetaBuildIndexOmpNum(conf) : omp_get_max_threads(); | ||
} | ||
|
||
int32_t | ||
GetQueryOmpThread(const Config& conf) { | ||
return CheckKeyInConfig(conf, meta::QUERY_OMP_NUM) ? GetMetaQueryOmpNum(conf) : omp_get_max_threads(); | ||
} | ||
|
||
int32_t | ||
GetThreadNum(int pid) { | ||
std::string cmd = "ps -p " + std::to_string(pid) + " -Tf | wc -l"; | ||
FILE* file = popen(cmd.c_str(), "r"); | ||
char fBuff[THREAD_LENGTH]; | ||
if (fgets(fBuff, sizeof(fBuff), file) == nullptr) { | ||
KNOWHERE_THROW_MSG("could not open the file to get thread number"); | ||
} | ||
pclose(file); | ||
const std::size_t len = strlen(fBuff); | ||
if (len > 0 && fBuff[len - 1] == '\n') { | ||
fBuff[len - 1] = '\0'; | ||
} | ||
int32_t ans = atoi(fBuff); | ||
if (ans < MIN_THREAD_NUM || ans > MAX_THREAD_NUM) { | ||
KNOWHERE_THROW_MSG("thread number is out of control"); | ||
} | ||
return ans; | ||
} | ||
|
||
} // namespace knowhere::threadchecker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (C) 2019-2020 Zilliz. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software distributed under the License | ||
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
// or implied. See the License for the specific language governing permissions and limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include <omp.h> | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
|
||
#include "common/Log.h" | ||
#include "knowhere/index/vector_index/helpers/IndexParameter.h" | ||
|
||
namespace knowhere::threadchecker { | ||
|
||
int32_t | ||
GetBuildOmpThread(const Config& conf); | ||
|
||
int32_t | ||
GetQueryOmpThread(const Config& conf); | ||
|
||
int32_t | ||
GetThreadNum(int pid); | ||
|
||
} // namespace knowhere::threadchecker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters