Skip to content

Commit 9633d32

Browse files
committed
Fix test crash in some circumstances
There appears to be some sort of race condition accessing thread vectors from the thread.
1 parent 866e60c commit 9633d32

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

AnnService/inc/SSDServing/SSDIndex.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,14 @@ namespace SPTAG {
111111

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

114+
NumaStrategy ns = (p_index->GetDiskIndex() != nullptr) ? NumaStrategy::SCATTER : NumaStrategy::LOCAL; // Only for SPANN, we need to avoid IO threads overlap with search threads.
115+
114116
SPTAGLIB_LOG(Helper::LogLevel::LL_Info, "Searching: numThread: %d, numQueries: %d.\n", p_numThreads, numQueries);
115117

116118
Utils::StopW sw;
117119

118120
for (int i = 0; i < p_numThreads; i++) { threads.emplace_back([&, i]()
119121
{
120-
NumaStrategy ns = (p_index->GetDiskIndex() != nullptr) ? NumaStrategy::SCATTER : NumaStrategy::LOCAL; // Only for SPANN, we need to avoid IO threads overlap with search threads.
121-
Helper::SetThreadAffinity(i, threads[i], ns, OrderStrategy::ASC);
122-
123122
Utils::StopW threadws;
124123
size_t index = 0;
125124
while (true)
@@ -147,6 +146,7 @@ namespace SPTAG {
147146
}
148147
}
149148
});
149+
Helper::SetThreadAffinity(i, threads.back(), ns, OrderStrategy::ASC);
150150
}
151151
for (auto& thread : threads) { thread.join(); }
152152

AnnService/src/IndexSearcher/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,12 @@ int Process(std::shared_ptr<SearcherOptions> options, VectorIndex& index)
189189
std::atomic_size_t queriesSent(0);
190190
std::vector<std::thread> threads;
191191

192+
NumaStrategy ns = (index.GetIndexAlgoType() == IndexAlgoType::SPANN)? NumaStrategy::SCATTER: NumaStrategy::LOCAL; // Only for SPANN, we need to avoid IO threads overlap with search threads.
193+
192194
auto batchstart = std::chrono::high_resolution_clock::now();
193195

194196
for (std::uint32_t i = 0; i < options->m_threadNum; i++) {
195197
threads.emplace_back([&, i] {
196-
NumaStrategy ns = (index.GetIndexAlgoType() == IndexAlgoType::SPANN)? NumaStrategy::SCATTER: NumaStrategy::LOCAL; // Only for SPANN, we need to avoid IO threads overlap with search threads.
197-
Helper::SetThreadAffinity(i, threads[i], ns, OrderStrategy::ASC);
198-
199198
size_t qid = 0;
200199
while (true)
201200
{
@@ -213,6 +212,7 @@ int Process(std::shared_ptr<SearcherOptions> options, VectorIndex& index)
213212
}
214213
}
215214
});
215+
Helper::SetThreadAffinity(i, threads.back(), ns, OrderStrategy::ASC);
216216
}
217217
for (auto& thread : threads) { thread.join(); }
218218

0 commit comments

Comments
 (0)