Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions cachelib/allocator/CacheAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -6359,6 +6359,7 @@ folly::IOBufQueue CacheAllocator<CacheTrait>::saveStateToIOBuf() {
template <typename CacheTrait>
bool CacheAllocator<CacheTrait>::stopWorkers(std::chrono::seconds timeout) {
bool success = true;
success &= stopPoolOptimizer(timeout);
success &= stopPoolRebalancer(timeout);
success &= stopPoolResizer(timeout);
success &= stopMemMonitor(timeout);
Expand Down
4 changes: 4 additions & 0 deletions cachelib/allocator/tests/SimplePoolOptimizationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ TYPED_TEST(SimplePoolOptimizationTest, PoolOptimizerBasic) {
this->testPoolOptimizerBasic();
}

TYPED_TEST(SimplePoolOptimizationTest, StopWorkersStopsPoolOptimizer) {
this->testStopWorkersStopsPoolOptimizer();
}

} // namespace tests
} // namespace cachelib
} // namespace facebook
31 changes: 31 additions & 0 deletions cachelib/allocator/tests/SimplePoolOptimizationTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
#include <folly/Random.h>
#include <gtest/gtest.h>

#include <atomic>
#include <chrono>
#include <future>
#include <thread>

#include "cachelib/allocator/CCacheAllocator.h"
#include "cachelib/allocator/PoolOptimizer.h"
Expand Down Expand Up @@ -85,6 +88,34 @@ struct SimplePoolOptimizeStrategy : public PoolOptimizeStrategy {
template <typename AllocatorT>
class SimplePoolOptimizationTest : public testing::Test {
public:
void testStopWorkersStopsPoolOptimizer() {
struct CountingStrategy : public PoolOptimizeStrategy {
std::atomic<int> calls{0};

protected:
PoolOptimizeContext pickVictimAndReceiverRegularPoolsImpl(
const CacheBase&) override {
++calls;
return kNoOpContext;
}
};
auto strategy = std::make_shared<CountingStrategy>();
typename AllocatorT::Config config;
config.setCacheSize(30 * Slab::kSize);
config.enablePoolOptimizer(strategy, std::chrono::seconds{1},
std::chrono::seconds{1}, 1);
AllocatorT alloc(config);
for (int i = 0; i < 100 && strategy->calls == 0; ++i) {
std::this_thread::sleep_for(std::chrono::milliseconds{100});
}
ASSERT_GT(strategy->calls.load(), 0);

ASSERT_TRUE(alloc.stopWorkers());
const int calls = strategy->calls.load();
std::this_thread::sleep_for(std::chrono::seconds{2});
EXPECT_EQ(calls, strategy->calls.load());
}

void testPoolOptimizerBasic() {
typename AllocatorT::Config config;
config.setCacheSize(30 * Slab::kSize);
Expand Down