-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Opt](TabletSchema) reuse TabletColumn info to reduce mem (#42448)
1. When there are a large number of identical TabletColumns in the cluster, which usually occurs when VARIANT type columns are modified and added, each Rowset has an individual TabletSchema. Excessive TabletSchemas can lead to significant memory overhead. Reusing memory for identical TabletColumns would greatly reduce this memory consumption. 2. Serialized TabletSchema as LRU cache key could also increase memusage when large sets of schemas are in LRU cache, so inorder to reduce the memory footprint we just record the key signature caculated by generating an UUID by hash algorithm, and lookup the key signature in LRU cache, and check the key in case of hash collision
- Loading branch information
Showing
13 changed files
with
225 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
#include "olap/tablet_column_object_pool.h" | ||
|
||
#include <gen_cpp/AgentService_types.h> | ||
#include <gen_cpp/olap_file.pb.h> | ||
|
||
#include "olap/tablet_schema.h" | ||
|
||
namespace doris { | ||
|
||
bvar::Adder<int64_t> g_tablet_column_cache_count("tablet_column_cache_count"); | ||
bvar::Adder<int64_t> g_tablet_column_cache_hit_count("tablet_column_cache_hit_count"); | ||
|
||
std::pair<Cache::Handle*, TabletColumnPtr> TabletColumnObjectPool::insert(const std::string& key) { | ||
auto* lru_handle = lookup(key); | ||
TabletColumnPtr tablet_column_ptr; | ||
if (lru_handle) { | ||
auto* value = (CacheValue*)LRUCachePolicy::value(lru_handle); | ||
tablet_column_ptr = value->tablet_column; | ||
VLOG_DEBUG << "reuse column "; | ||
g_tablet_column_cache_hit_count << 1; | ||
} else { | ||
auto* value = new CacheValue; | ||
tablet_column_ptr = std::make_shared<TabletColumn>(); | ||
ColumnPB pb; | ||
pb.ParseFromString(key); | ||
tablet_column_ptr->init_from_pb(pb); | ||
VLOG_DEBUG << "create column "; | ||
value->tablet_column = tablet_column_ptr; | ||
lru_handle = LRUCachePolicy::insert(key, value, 1, 0, CachePriority::NORMAL); | ||
g_tablet_column_cache_count << 1; | ||
} | ||
DCHECK(lru_handle != nullptr); | ||
return {lru_handle, tablet_column_ptr}; | ||
} | ||
|
||
TabletColumnObjectPool::CacheValue::~CacheValue() { | ||
g_tablet_column_cache_count << -1; | ||
} | ||
|
||
} // namespace doris |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
#pragma once | ||
|
||
#include "olap/tablet_fwd.h" | ||
#include "olap/tablet_schema.h" | ||
#include "runtime/exec_env.h" | ||
#include "runtime/memory/lru_cache_policy.h" | ||
|
||
namespace doris { | ||
|
||
// TabletColumnObjectPool is a cache for TabletColumn objects. It is used to reduce memory consumption | ||
// when there are a large number of identical TabletColumns in the cluster, which usually occurs | ||
// when VARIANT type columns are modified and added, each Rowset has an individual TabletSchema. | ||
// Excessive TabletSchemas can lead to significant memory overhead. Reusing memory for identical | ||
// TabletColumns would greatly reduce this memory consumption. | ||
|
||
class TabletColumnObjectPool : public LRUCachePolicy { | ||
public: | ||
TabletColumnObjectPool(size_t capacity) | ||
: LRUCachePolicy(CachePolicy::CacheType::TABLET_COLUMN_OBJECT_POOL, capacity, | ||
LRUCacheType::NUMBER, config::tablet_schema_cache_recycle_interval) {} | ||
|
||
static TabletColumnObjectPool* create_global_column_cache(size_t capacity) { | ||
auto* res = new TabletColumnObjectPool(capacity); | ||
return res; | ||
} | ||
|
||
static TabletColumnObjectPool* instance() { | ||
return ExecEnv::GetInstance()->get_tablet_column_object_pool(); | ||
} | ||
|
||
std::pair<Cache::Handle*, TabletColumnPtr> insert(const std::string& key); | ||
|
||
private: | ||
class CacheValue : public LRUCacheValueBase { | ||
public: | ||
~CacheValue() override; | ||
TabletColumnPtr tablet_column; | ||
}; | ||
}; | ||
|
||
} // namespace doris |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.