aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/tests/proton
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2021-11-15 11:47:54 +0100
committerTor Egge <Tor.Egge@online.no>2021-11-15 11:47:54 +0100
commit960822b673e305e3e5e001515e6b21c2c4597753 (patch)
tree242a4052881082740bcd105f169b16dfd64dda14 /searchcore/src/tests/proton
parent692cf16348631bfe521b7c0926979456a7b3ed1f (diff)
Optimize proton::documentmetastore::LidAllocator::unregister_lids().
Diffstat (limited to 'searchcore/src/tests/proton')
-rw-r--r--searchcore/src/tests/proton/documentmetastore/lid_allocator/lid_allocator_test.cpp39
-rw-r--r--searchcore/src/tests/proton/documentmetastore/lid_state_vector/lid_state_vector_test.cpp27
2 files changed, 66 insertions, 0 deletions
diff --git a/searchcore/src/tests/proton/documentmetastore/lid_allocator/lid_allocator_test.cpp b/searchcore/src/tests/proton/documentmetastore/lid_allocator/lid_allocator_test.cpp
index deb1b04e11a..b0f1220c768 100644
--- a/searchcore/src/tests/proton/documentmetastore/lid_allocator/lid_allocator_test.cpp
+++ b/searchcore/src/tests/proton/documentmetastore/lid_allocator/lid_allocator_test.cpp
@@ -2,9 +2,12 @@
#include <vespa/searchcore/proton/documentmetastore/lid_allocator.h>
#include <vespa/vespalib/util/generationholder.h>
+#include <vespa/vespalib/util/time.h>
#include <vespa/vespalib/gtest/gtest.h>
+#include <iostream>
using vespalib::GenerationHolder;
+using vespalib::Timer;
namespace proton {
@@ -118,6 +121,42 @@ TEST_F(LidAllocatorTest, unregister_lids)
EXPECT_EQ((std::vector<uint32_t>{1, 3, 5, 7, 8}), alloc_lids(5));
}
+class LidAllocatorPerformanceTest : public LidAllocatorTest,
+ public testing::WithParamInterface<bool>
+{
+};
+
+TEST_P(LidAllocatorPerformanceTest, unregister_lids_performance)
+{
+ constexpr uint32_t test_size = 1000000;
+ _allocator.ensureSpace(test_size + 1, test_size + 1);
+ std::vector<std::vector<uint32_t>> buckets;
+ buckets.resize(1000);
+ auto reserve_size = (test_size + (buckets.size() - 1)) / buckets.size();
+for (auto& bucket : buckets) {
+ bucket.reserve(reserve_size);
+}
+ for (uint32_t i = 0; i < test_size; ++i) {
+ _allocator.registerLid(i + 1);
+ buckets[i % buckets.size()].emplace_back(i + 1);
+ }
+ construct_free_list();
+ Timer timer;
+ for (auto& bucket: buckets) {
+ if (GetParam()) {
+ unregister_lids(bucket);
+ } else {
+ for (auto lid : bucket) {
+ _allocator.unregisterLid(lid);
+ }
+ }
+ }
+ auto rate = test_size / vespalib::to_s(timer.elapsed());
+ std::cout << "Unregister rate: " << std::fixed << rate << std::endl;
+}
+
+VESPA_GTEST_INSTANTIATE_TEST_SUITE_P(LidAllocatorParameterizedPerformanceTest, LidAllocatorPerformanceTest, testing::Values(false, true));
+
}
GTEST_MAIN_RUN_ALL_TESTS()
diff --git a/searchcore/src/tests/proton/documentmetastore/lid_state_vector/lid_state_vector_test.cpp b/searchcore/src/tests/proton/documentmetastore/lid_state_vector/lid_state_vector_test.cpp
index af4c2efd74b..ab45cca0971 100644
--- a/searchcore/src/tests/proton/documentmetastore/lid_state_vector/lid_state_vector_test.cpp
+++ b/searchcore/src/tests/proton/documentmetastore/lid_state_vector/lid_state_vector_test.cpp
@@ -141,6 +141,33 @@ TEST_F(LidStateVectorTest, lid_state_vector_resizing_is_working)
assertLidStateVector({}, 2000, 0, lids);
}
+TEST_F(LidStateVectorTest, set_bits)
+{
+ LidStateVector lids(1000, 1000, _gen_hold, true, true);
+ EXPECT_EQ(100, lids.assert_not_set_bits({ 10, 40, 100 }));
+ assertLidStateVector({}, 1000, 0, lids);
+ EXPECT_EQ(100, lids.set_bits({ 10, 40, 100 }));
+ assertLidStateVector({ 10, 40, 100 }, 10, 100, lids);
+}
+
+TEST_F(LidStateVectorTest, clear_bits)
+{
+ LidStateVector lids(1000, 1000, _gen_hold, true, true);
+ lids.set_bits({ 10, 40, 100 });
+ lids.clear_bits({ 10, 100 });
+ assertLidStateVector({ 40 }, 40, 40, lids);
+}
+
+TEST_F(LidStateVectorTest, consider_clear_bits)
+{
+ LidStateVector lids(1000, 1000, _gen_hold, true, true);
+ lids.set_bits({ 40 });
+ lids.consider_clear_bits({ 10, 100 });
+ assertLidStateVector({ 40 }, 40, 40, lids);
+ lids.consider_clear_bits({ 10, 40, 100 });
+ assertLidStateVector({}, 1000, 0, lids);
+}
+
}
GTEST_MAIN_RUN_ALL_TESTS()