From 36c9fccd542577bded8d8524f2ba9c66c54336c9 Mon Sep 17 00:00:00 2001 From: Suryansh Gupta Date: Wed, 11 Dec 2024 15:18:35 +0530 Subject: [PATCH] Add single threaded benchmark_disk_read script --- apps/CMakeLists.txt | 4 +++ apps/benchmark_reads.cpp | 53 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 apps/benchmark_reads.cpp diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index e42c0b6cb..5d2c8faaa 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -28,6 +28,9 @@ target_link_libraries(test_streaming_scenario ${PROJECT_NAME} ${DISKANN_TOOLS_TC add_executable(test_insert_deletes_consolidate test_insert_deletes_consolidate.cpp) target_link_libraries(test_insert_deletes_consolidate ${PROJECT_NAME} ${DISKANN_TOOLS_TCMALLOC_LINK_OPTIONS} Boost::program_options) +add_executable(benchmark_reads benchmark_reads.cpp) +target_link_libraries(benchmark_reads ${PROJECT_NAME} ${DISKANN_TOOLS_TCMALLOC_LINK_OPTIONS} Boost::program_options) + if (NOT MSVC) install(TARGETS build_memory_index build_stitched_index @@ -37,6 +40,7 @@ if (NOT MSVC) range_search_disk_index test_streaming_scenario test_insert_deletes_consolidate + benchmark_reads RUNTIME ) endif() diff --git a/apps/benchmark_reads.cpp b/apps/benchmark_reads.cpp new file mode 100644 index 000000000..a66218375 --- /dev/null +++ b/apps/benchmark_reads.cpp @@ -0,0 +1,53 @@ +#include +#include +#include "windows_aligned_file_reader.h" +#include "aligned_file_reader.h" +#include "utils.h" + +using namespace std; +using namespace diskann; + +#define IS_ALIGNED(X, Y) ((uint64_t)(X) % (uint64_t)(Y) == 0) + +#define SECTOR_LEN 4096 + +void do_reads() +{ + string file_name = "C:\\DiskANN\\Data\\turning_100k\\index_disk.index"; + auto reader = new WindowsAlignedFileReader(); + reader->open(file_name.c_str()); + auto ctx = reader->get_ctx(); + + std::vector read_reqs; + int num_sectors = 100; + + char *buf = nullptr; + alloc_aligned((void **)&buf, num_sectors * SECTOR_LEN, SECTOR_LEN); + + // create read requests + for (size_t i = 0; i < num_sectors; ++i) + { + AlignedRead read; + read.len = SECTOR_LEN; + read.buf = buf + i * SECTOR_LEN; + auto sector_id = (rand() % 10000); + read.offset = sector_id * SECTOR_LEN; + if (read.offset) + read_reqs.push_back(read); + } + + auto s = std::chrono::high_resolution_clock::now(); + for (int i = 0; i < 10000; i++) + { + reader->read(read_reqs, ctx, false); + } + auto e = std::chrono::high_resolution_clock::now(); + std::chrono::duration diff = e - s; + cout << "Time taken to read: " << diff.count() << endl; +} + +int main() +{ + cout << "Hello World" << endl; + do_reads(); +} \ No newline at end of file