Skip to content

Commit 8889662

Browse files
committed
MB-52812: Fix engine benchmark fixture resource isolation
Improve ep_engine_benchmarks infrastructure with proper resource isolation and intelligent test registration: EngineFixture improvements: - Use cb::io::mkdtemp() to create unique temporary directories instead of hardcoded 'benchmarks-test', eliminating race conditions when multiple benchmark instances run concurrently - Store the generated dbname path as a member variable for proper cleanup - Use fmt::format() for cleaner string composition - Add defensive check before cleanup to prevent accidental deletion CMakeLists.txt improvements: - Normalize to lowercase CMake commands (modern convention) - Remove unused GTest dependencies (pure benchmark suite) - Streamline include directories - Intelligently register 18 individual benchmark tests with CTest: * Only run on non-sanitizer builds (avoid timeouts) * Use separate test entries for each benchmark for targeted execution * Regex filtering (--benchmark_filter=^name) to run benchmarks in isolation * Fast execution mode (--benchmark_min_time=0.0000001s) - Document problematic benchmarks that need resolution Change-Id: I06ce09315c9514b2dcc69a6a829d905f8965a7b1 Reviewed-on: https://review.couchbase.org/c/kv_engine/+/245350 Tested-by: Build Bot <build@couchbase.com> Reviewed-by: Jim Walker <jim@couchbase.com>
1 parent 27f686e commit 8889662

3 files changed

Lines changed: 55 additions & 10 deletions

File tree

engines/ep/CMakeLists.txt

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -528,21 +528,62 @@ cb_add_test_executable(ep_engine_benchmarks
528528
${Memcached_SOURCE_DIR}/engines/ep/tests/module_tests/test_helpers.cc)
529529
kv_enable_pch(ep_engine_benchmarks)
530530

531-
TARGET_LINK_LIBRARIES(ep_engine_benchmarks
531+
target_link_libraries(ep_engine_benchmarks
532532
PRIVATE
533533
ep
534534
mock_dcp
535535
ep_mocks
536536
couchstore_test_fileops
537537
benchmark::benchmark
538538
cluster_framework
539-
GTest::gtest
540-
GTest::gmock
541539
platform_cb_malloc_arena)
542-
TARGET_INCLUDE_DIRECTORIES(ep_engine_benchmarks PUBLIC
543-
tests
544-
benchmarks
545-
${Couchstore_SOURCE_DIR})
540+
target_include_directories(ep_engine_benchmarks PUBLIC tests)
541+
542+
# MB-52812 Run the benchmarks on non-sanitizer builds only as some of the
543+
# benchmarks are not expected to run in a reasonable time when built with
544+
# sanitizers.
545+
# Ideally we could have just run the ep_engine_benchmark binary directly,
546+
# but there are a few benchmarks which currently don't work. While
547+
# trying to resolve them try to run each test individually.
548+
if (NOT CB_SANITIZERS)
549+
function(add_benchmark_test benchmark_name)
550+
add_test(NAME ep_engine_benchmarks-${benchmark_name}
551+
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
552+
COMMAND ep_engine_benchmarks --benchmark_min_time=0.0000001s
553+
--benchmark_filter=^${benchmark_name})
554+
endfunction()
555+
556+
# The following tests currently don't work
557+
# add_benchmark_test(AccessLogBenchEngine)
558+
559+
# The following test should probably be deleted as it
560+
# starts with the following comment:
561+
# "Skip this test as it's not working."
562+
# add_benchmark_test(QuotaSharingBench)
563+
564+
add_benchmark_test(BM_CheckpointIteratorCompare)
565+
add_benchmark_test(BM_CompareQueuedItemsBySeqnoAndKey)
566+
add_benchmark_test(BM_SaturateCounter)
567+
add_benchmark_test(CheckpointBench)
568+
add_benchmark_test(DcpProducerStreamsMapBench)
569+
add_benchmark_test(DefragmentBench)
570+
add_benchmark_test(EngineStatsBench)
571+
add_benchmark_test(ExecutorPoolFixture<FollyExecutorPool>)
572+
add_benchmark_test(HashTableBench)
573+
add_benchmark_test(ItemCompressorBench)
574+
add_benchmark_test(KVStoreBench)
575+
add_benchmark_test(MemTrackingVBucketBench)
576+
add_benchmark_test(MultiVBEngineStatsBench)
577+
add_benchmark_test(PagingVisitorBench)
578+
add_benchmark_test(PureFollyExecutorBench)
579+
add_benchmark_test(SessionTracingEncode)
580+
add_benchmark_test(SessionTracingRecordMutationSpan)
581+
add_benchmark_test(SessionTracingScopeTimer)
582+
add_benchmark_test(StatsBench)
583+
add_benchmark_test(VBCBAdaptorBench)
584+
add_benchmark_test(VBReadyQueueBench)
585+
add_benchmark_test(VBucketDetailsBench)
586+
endif ()
546587

547588
add_sanitizers(ep_engine_benchmarks)
548589
cb_enable_unity_build(ep_engine_benchmarks)

engines/ep/benchmarks/engine_fixture.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626

2727
void EngineFixture::SetUp(const benchmark::State& state) {
2828
if (state.thread_index() == 0) {
29+
dbname = cb::io::mkdtemp("benchmarks-test");
2930
{
3031
NonBucketAllocationGuard guard;
3132
ExecutorPool::create(ExecutorPool::Backend::Fake);
3233
}
3334
executorPool = reinterpret_cast<SingleThreadedExecutorPool*>(
3435
ExecutorPool::get());
35-
std::string config = "dbname=benchmarks-test;ht_locks=47;" + varConfig;
36-
36+
auto config = fmt::format(
37+
"dbname={};ht_locks=47;{}", dbname.string(), varConfig);
3738
engine = SynchronousEPEngine::build(config);
3839

3940
initialize_time_functions(get_mock_server_api()->core);
@@ -55,7 +56,9 @@ void EngineFixture::TearDown(const benchmark::State& state) {
5556
engine->getDcpConnMap().manageConnections();
5657
engine.reset();
5758
ExecutorPool::shutdown();
58-
cb::io::remove_with_retry("benchmarks-test");
59+
if (!dbname.empty()) {
60+
cb::io::remove_with_retry(dbname.string());
61+
}
5962
}
6063
ObjectRegistry::onSwitchThread(nullptr);
6164
}

engines/ep/benchmarks/engine_fixture.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ class EngineFixture : public benchmark::Fixture {
4141
// Allows subclasses to add stuff to the config
4242
std::string varConfig;
4343
SingleThreadedExecutorPool* executorPool;
44+
std::filesystem::path dbname;
4445
};

0 commit comments

Comments
 (0)