Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deleted elements at addition #418

Merged
merged 28 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add C++ multi thread load test
  • Loading branch information
Dmitry Yashunin committed Nov 26, 2022
commit 1f12fdbfdeed580530e3b7e0c5ea1e0168e7c7a5
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
fi
./searchKnnCloserFirst_test
./searchKnnWithFilter_test
./multiThreadLoad_test
./test_updates
./test_updates update
shell: bash
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
add_executable(searchKnnWithFilter_test examples/searchKnnWithFilter_test.cpp)
target_link_libraries(searchKnnWithFilter_test hnswlib)

add_executable(multiThreadLoad_test examples/multiThreadLoad_test.cpp)
target_link_libraries(multiThreadLoad_test hnswlib)

add_executable(main main.cpp sift_1b.cpp)
target_link_libraries(main hnswlib)
endif()
53 changes: 53 additions & 0 deletions examples/multiThreadLoad_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "../hnswlib/hnswlib.h"
#include <thread>

int main() {
int d = 16;
int max_elements = 100;

std::mt19937 rng;
rng.seed(47);
std::uniform_real_distribution<> distrib_real;

hnswlib::L2Space space(d);
hnswlib::HierarchicalNSW<float>* alg_hnsw = new hnswlib::HierarchicalNSW<float>(&space, max_elements);

int num_threads = 40;
int num_ids = 1;

int num_iterations = 10;
int start_id = 0;

while (true) {
std::uniform_int_distribution<> distrib_int(start_id, start_id + num_ids - 1);
std::vector<std::thread> threads;
for (size_t thread_id = 0; thread_id < num_threads; thread_id++) {
threads.push_back(
std::thread(
[&] {
for (int iter = 0; iter < num_iterations; iter++) {
std::vector<float> data(d);
int id = distrib_int(rng);
//std::cout << id << std::endl;
for (int i = 0; i < d; i++) {
data[i] = distrib_real(rng);
}
alg_hnsw->addPoint(data.data(), id);
}
}
)
);
}
for (auto &thread : threads) {
thread.join();
}
//std::cout << alg_hnsw->cur_element_count << std::endl;
if (alg_hnsw->cur_element_count > max_elements - num_ids) {
//std::cout << "Exit" << std::endl;
break;
}
start_id += num_ids;
}

return 0;
}