Skip to content

Commit

Permalink
Fix test crash in some circumstances
Browse files Browse the repository at this point in the history
There appears to be some sort of race condition accessing thread vectors from the thread.
  • Loading branch information
pabs3 committed Jun 16, 2023
1 parent 866e60c commit 9633d32
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions AnnService/inc/SSDServing/SSDIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,14 @@ namespace SPTAG {

std::vector<std::thread> threads;

NumaStrategy ns = (p_index->GetDiskIndex() != nullptr) ? NumaStrategy::SCATTER : NumaStrategy::LOCAL; // Only for SPANN, we need to avoid IO threads overlap with search threads.

SPTAGLIB_LOG(Helper::LogLevel::LL_Info, "Searching: numThread: %d, numQueries: %d.\n", p_numThreads, numQueries);

Utils::StopW sw;

for (int i = 0; i < p_numThreads; i++) { threads.emplace_back([&, i]()
{
NumaStrategy ns = (p_index->GetDiskIndex() != nullptr) ? NumaStrategy::SCATTER : NumaStrategy::LOCAL; // Only for SPANN, we need to avoid IO threads overlap with search threads.
Helper::SetThreadAffinity(i, threads[i], ns, OrderStrategy::ASC);

Utils::StopW threadws;
size_t index = 0;
while (true)
Expand Down Expand Up @@ -147,6 +146,7 @@ namespace SPTAG {
}
}
});
Helper::SetThreadAffinity(i, threads.back(), ns, OrderStrategy::ASC);
}
for (auto& thread : threads) { thread.join(); }

Expand Down
6 changes: 3 additions & 3 deletions AnnService/src/IndexSearcher/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,12 @@ int Process(std::shared_ptr<SearcherOptions> options, VectorIndex& index)
std::atomic_size_t queriesSent(0);
std::vector<std::thread> threads;

NumaStrategy ns = (index.GetIndexAlgoType() == IndexAlgoType::SPANN)? NumaStrategy::SCATTER: NumaStrategy::LOCAL; // Only for SPANN, we need to avoid IO threads overlap with search threads.

auto batchstart = std::chrono::high_resolution_clock::now();

for (std::uint32_t i = 0; i < options->m_threadNum; i++) {
threads.emplace_back([&, i] {
NumaStrategy ns = (index.GetIndexAlgoType() == IndexAlgoType::SPANN)? NumaStrategy::SCATTER: NumaStrategy::LOCAL; // Only for SPANN, we need to avoid IO threads overlap with search threads.
Helper::SetThreadAffinity(i, threads[i], ns, OrderStrategy::ASC);

size_t qid = 0;
while (true)
{
Expand All @@ -213,6 +212,7 @@ int Process(std::shared_ptr<SearcherOptions> options, VectorIndex& index)
}
}
});
Helper::SetThreadAffinity(i, threads.back(), ns, OrderStrategy::ASC);
}
for (auto& thread : threads) { thread.join(); }

Expand Down

0 comments on commit 9633d32

Please sign in to comment.