Skip to content

Commit c1e6681

Browse files
committed
[improvement](point-query) Reduce lookup cache block memory
1 parent d2cfcc1 commit c1e6681

4 files changed

Lines changed: 44 additions & 11 deletions

File tree

‎be/src/common/config.cpp‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,6 +1559,19 @@ DEFINE_mInt64(auto_inc_low_water_level_mark_size_ratio, "3");
15591559
DEFINE_mInt64(auto_inc_fetch_thread_num, "3");
15601560
// default max to 2048 connections
15611561
DEFINE_mInt64(lookup_connection_cache_capacity, "2048");
1562+
// Number of reusable result blocks retained by each point lookup cache entry, in [1, 32].
1563+
DEFINE_mInt32(lookup_connection_cache_block_pool_size, "1");
1564+
DEFINE_Validator(lookup_connection_cache_block_pool_size,
1565+
[](int32_t value) -> bool { return value >= 1 && value <= 32; });
1566+
static std::atomic<size_t> atomic_lookup_connection_cache_block_pool_size {1};
1567+
DEFINE_ON_UPDATE(lookup_connection_cache_block_pool_size, [](int32_t, int32_t value) {
1568+
atomic_lookup_connection_cache_block_pool_size.store(static_cast<size_t>(value),
1569+
std::memory_order_relaxed);
1570+
});
1571+
1572+
size_t get_lookup_connection_cache_block_pool_size() {
1573+
return atomic_lookup_connection_cache_block_pool_size.load(std::memory_order_relaxed);
1574+
}
15621575

15631576
// level of compression when using LZ4_HC, whose defalut value is LZ4HC_CLEVEL_DEFAULT
15641577
DEFINE_mInt64(LZ4_HC_compression_level, "9");
@@ -2397,6 +2410,9 @@ bool init(const char* conf_file, bool fill_conf_map, bool must_exist, bool set_t
23972410
}
23982411
published_inverted_index_candidate_pushdown_ratio.store(
23992412
inverted_index_candidate_pushdown_ratio);
2413+
atomic_lookup_connection_cache_block_pool_size.store(
2414+
static_cast<size_t>(lookup_connection_cache_block_pool_size),
2415+
std::memory_order_relaxed);
24002416

24012417
// Emit a warning for every key present in the conf file that does not correspond to a
24022418
// registered BE config field. Such keys (typos or configs removed in a newer version)

‎be/src/common/config.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#pragma once
1919

20+
#include <cstddef>
2021
#include <cstdint>
2122
#include <functional>
2223
#include <map>
@@ -1616,6 +1617,9 @@ DECLARE_mInt64(auto_inc_low_water_level_mark_size_ratio);
16161617
DECLARE_mInt64(auto_inc_fetch_thread_num);
16171618
// Max connection cache num for point lookup queries
16181619
DECLARE_mInt64(lookup_connection_cache_capacity);
1620+
// Number of reusable result blocks retained by each point lookup cache entry, in [1, 32].
1621+
DECLARE_mInt32(lookup_connection_cache_block_pool_size);
1622+
size_t get_lookup_connection_cache_block_pool_size();
16191623

16201624
// level of compression when using LZ4_HC, whose defalut value is LZ4HC_CLEVEL_DEFAULT
16211625
DECLARE_mInt64(LZ4_HC_compression_level);

‎be/src/service/point_query_executor.cpp‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ static void get_missing_and_include_cids(const TabletSchema& schema,
112112
}
113113
}
114114

115-
constexpr static int s_preallocted_blocks_num = 32;
116-
117115
static void extract_slot_ref(const VExprSPtr& expr, TupleDescriptor* tuple_desc,
118116
std::vector<SlotDescriptor*>& slots) {
119117
const auto& children = expr->children();
@@ -212,8 +210,9 @@ void Reusable::return_block(std::unique_ptr<Block>& block) {
212210
}
213211
block->clear_column_data();
214212
_block_pool.push_back(std::move(block));
215-
if (_block_pool.size() > s_preallocted_blocks_num) {
216-
_block_pool.resize(s_preallocted_blocks_num);
213+
const auto block_pool_size = config::get_lookup_connection_cache_block_pool_size();
214+
if (_block_pool.size() > block_pool_size) {
215+
_block_pool.resize(block_pool_size);
217216
}
218217
}
219218

@@ -350,15 +349,10 @@ Status PointQueryExecutor::init(const PTabletKeyLookupRequest* request,
350349
reinterpret_cast<const uint8_t*>(request->query_options().data()), &len, false,
351350
&t_query_options));
352351
}
352+
RETURN_IF_ERROR(reusable_ptr->init(t_desc_tbl, t_output_exprs.exprs, t_query_options,
353+
*_tablet->tablet_schema(), 1));
353354
if (uuid != 0) {
354-
// could be reused by requests after, pre allocte more blocks
355-
RETURN_IF_ERROR(reusable_ptr->init(t_desc_tbl, t_output_exprs.exprs, t_query_options,
356-
*_tablet->tablet_schema(),
357-
s_preallocted_blocks_num));
358355
LookupConnectionCache::instance()->add(uuid, reusable_ptr);
359-
} else {
360-
RETURN_IF_ERROR(reusable_ptr->init(t_desc_tbl, t_output_exprs.exprs, t_query_options,
361-
*_tablet->tablet_schema(), 1));
362356
}
363357
}
364358
_init_remote_scan_cache_write_limiter();

‎be/test/common/config_validator_test.cpp‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,23 @@ TEST(ConfigValidatorTest, Validator) {
5050
EXPECT_EQ(cfg_validator_2, 8);
5151
}
5252

53+
TEST(ConfigValidatorTest, LookupConnectionCacheBlockPoolSize) {
54+
const auto old_value = config::get_lookup_connection_cache_block_pool_size();
55+
56+
EXPECT_TRUE(config::set_config("lookup_connection_cache_block_pool_size", "1").ok());
57+
EXPECT_EQ(config::get_lookup_connection_cache_block_pool_size(), 1);
58+
EXPECT_FALSE(config::set_config("lookup_connection_cache_block_pool_size", "0").ok());
59+
EXPECT_FALSE(config::set_config("lookup_connection_cache_block_pool_size", "-1").ok());
60+
EXPECT_EQ(config::get_lookup_connection_cache_block_pool_size(), 1);
61+
62+
EXPECT_TRUE(config::set_config("lookup_connection_cache_block_pool_size", "32").ok());
63+
EXPECT_EQ(config::get_lookup_connection_cache_block_pool_size(), 32);
64+
EXPECT_FALSE(config::set_config("lookup_connection_cache_block_pool_size", "33").ok());
65+
EXPECT_EQ(config::get_lookup_connection_cache_block_pool_size(), 32);
66+
67+
EXPECT_TRUE(
68+
config::set_config("lookup_connection_cache_block_pool_size", std::to_string(old_value))
69+
.ok());
70+
}
71+
5372
} // namespace doris

0 commit comments

Comments
 (0)