From 7deeb69934ecddba55bd7af9d7b5b87355dd6427 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Wed, 5 Jan 2022 15:45:34 +0000 Subject: If TLS buffer has more than 8x overhead, shrink it to fit prior to posting task for compression. Intention to reduce amount of allocated memory in flight in the case there are cpu starvation, or something else causing hickups. --- searchlib/src/tests/transactionlog/chunks_test.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'searchlib/src/tests/transactionlog/chunks_test.cpp') diff --git a/searchlib/src/tests/transactionlog/chunks_test.cpp b/searchlib/src/tests/transactionlog/chunks_test.cpp index 8d6620c9f8b..ca03a47634d 100644 --- a/searchlib/src/tests/transactionlog/chunks_test.cpp +++ b/searchlib/src/tests/transactionlog/chunks_test.cpp @@ -115,4 +115,25 @@ TEST("test multi element commitchunk") { } EXPECT_EQUAL(0u, counter); } + +TEST("shrinkToFit if difference is larger than 8x") { + Packet p(16000); + p.add(Packet::Entry(1, 3, ConstBufferRef(TEXT, strlen(TEXT)))); + EXPECT_EQUAL(150u, p.sizeBytes()); + EXPECT_EQUAL(16384u, p.getHandle().capacity()); + p.shrinkToFit(); + EXPECT_EQUAL(150u, p.sizeBytes()); + EXPECT_EQUAL(150u, p.getHandle().capacity()); +} + +TEST("not shrinkToFit if difference is less than 8x") { + Packet p(1000); + p.add(Packet::Entry(1, 3, ConstBufferRef(TEXT, strlen(TEXT)))); + EXPECT_EQUAL(150u, p.sizeBytes()); + EXPECT_EQUAL(1024u, p.getHandle().capacity()); + p.shrinkToFit(); + EXPECT_EQUAL(150u, p.sizeBytes()); + EXPECT_EQUAL(1024u, p.getHandle().capacity()); +} + TEST_MAIN() { TEST_RUN_ALL(); } -- cgit v1.2.3