Skip to content

Commit 8882014

Browse files
authored
(feat) Add MemoryCoordinator and IndexRegistry for serverless scaling (#8)
Introduces two new components for serverless deployments: MemoryCoordinator: - Adaptive memory budget split between cache (40%) and mmap (60%) - Automatic rebalancing based on pressure detection - Workload hints (BulkIngestion, QueryHeavy, MemoryConstrained) - Environment variable configuration (XTREE_MEMORY_BUDGET) IndexRegistry: - Lazy index loading - indexes registered as lightweight metadata - On-demand loading via get_or_load<Record>() - LRU-based cold index eviction under memory pressure - Manifest integration for serverless cold start - register_from_data_dir() for one-line initialization Together these enable scaling to 1000+ indexes in memory-constrained serverless environments (Lambda, Cloud Run) by loading only active indexes and automatically unloading cold ones. 48 tests added, all passing. Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
1 parent 47c4cde commit 8882014

File tree

10 files changed

+2960
-1
lines changed

10 files changed

+2960
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ obj/
3939
.idea/
4040
*.iml
4141
.vscode/
42+
.claude/
4243
# But keep GitHub workflows
4344
!.github/
4445
*.swp

core/src/main/cpp/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,8 @@ set(GTEST_SOURCES
608608
test/test_lru_sharded_stress.cpp # Sharded LRU cache stress tests
609609
test/test_cache_policy.cpp # Cache memory policy tests
610610
test/test_cache_policy_stress.cpp # Cache policy stress tests
611+
test/test_memory_coordinator.cpp # Adaptive memory coordinator tests
612+
test/test_index_registry.cpp # Lazy index loading tests
611613
# Concurrent tests saved for adaptation to new persistence layer
612614
# test/test_xtree_concurrent_search.cpp
613615
# test/test_xtree_simple_concurrent.cpp

core/src/main/cpp/src/indexdetails.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "persistence/store_interface.h"
3333
#include "xtree_allocator_traits.hpp" // For XAlloc
3434
#include "cache_policy.hpp" // Cache memory policies
35+
#include "persistence/memory_coordinator.h" // Adaptive memory coordination
3536
#include <memory>
3637
#include <mutex>
3738
#include <atomic>
@@ -111,9 +112,16 @@ namespace xtree {
111112
break;
112113
}
113114

114-
std::cout << "[IndexDetails] Constructor completed for "
115+
std::cout << "[IndexDetails] Constructor completed for "
115116
<< (mode == PersistenceMode::DURABLE ? "DURABLE" : "IN_MEMORY") << " mode\n";
116117

118+
// Initialize memory coordinator for DURABLE mode
119+
// This ensures adaptive memory budget is active when mmap is in use
120+
if (mode == PersistenceMode::DURABLE) {
121+
// Touch the singleton to ensure it's initialized with env vars
122+
persist::MemoryCoordinator::global();
123+
}
124+
117125
// update cache size for each index
118126
// for_each(IndexDetails<Record>::indexes.begin(),
119127
// IndexDetails<Record>::indexes.end(),
@@ -1070,6 +1078,9 @@ namespace xtree {
10701078
<< " from dirty list of " << buckets.size() << " (iteration " << iteration << ")\n";
10711079
#endif
10721080
} // end while loop
1081+
1082+
// Tick the memory coordinator at safe points (after flush, no traversal in progress)
1083+
persist::MemoryCoordinator::global().tick();
10731084
}
10741085

10751086
/**

0 commit comments

Comments
 (0)