优化大量分区场景下,负载均衡模块内存占用大问题

This commit is contained in:
wanhong.wwh
2023-07-03 03:42:09 +00:00
committed by ob-robot
parent dd3554a7a5
commit ee34cba0bb
6 changed files with 46 additions and 18 deletions

View File

@ -90,7 +90,7 @@ int ObBalanceGroupInfo::create_new_part_group_()
if (OB_ISNULL(buf)) { if (OB_ISNULL(buf)) {
ret = OB_ALLOCATE_MEMORY_FAILED; ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("allocate memory for partition group fail", KR(ret), K(buf), K(part_group_size)); LOG_WARN("allocate memory for partition group fail", KR(ret), K(buf), K(part_group_size));
} else if (OB_ISNULL(part_group = new(buf) ObTransferPartGroup())) { } else if (OB_ISNULL(part_group = new(buf) ObTransferPartGroup(alloc_))) {
ret = OB_ALLOCATE_MEMORY_FAILED; ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("construct ObTransferPartGroup fail", KR(ret), K(buf), K(part_group_size)); LOG_WARN("construct ObTransferPartGroup fail", KR(ret), K(buf), K(part_group_size));
} else if (OB_FAIL(part_groups_.push_back(part_group))) { } else if (OB_FAIL(part_groups_.push_back(part_group))) {

View File

@ -14,9 +14,11 @@
#define OCEANBASE_ROOTSERVER_OB_BALANCE_GROUP_INFO_H #define OCEANBASE_ROOTSERVER_OB_BALANCE_GROUP_INFO_H
#include "lib/container/ob_array.h" //ObArray #include "lib/container/ob_array.h" //ObArray
#include "lib/ob_define.h" // OB_MALLOC_NORMAL_BLOCK_SIZE
#include "lib/allocator/ob_allocator.h" // ObIAllocator #include "lib/allocator/ob_allocator.h" // ObIAllocator
#include "share/transfer/ob_transfer_info.h" // ObTransferPartInfo, ObTransferPartList #include "share/transfer/ob_transfer_info.h" // ObTransferPartInfo, ObTransferPartList
#include "ob_balance_group_define.h" //ObBalanceGroupID #include "ob_balance_group_define.h" //ObBalanceGroupID
#include "lib/allocator/page_arena.h" // ModulePageAllocator
namespace oceanbase namespace oceanbase
{ {
@ -27,7 +29,14 @@ namespace rootserver
class ObTransferPartGroup class ObTransferPartGroup
{ {
public: public:
ObTransferPartGroup() : data_size_(0), part_list_() {} ObTransferPartGroup() :
data_size_(0),
part_list_("PartGroup") {}
ObTransferPartGroup(common::ObIAllocator &alloc) :
data_size_(0),
part_list_(alloc, "PartGroup") {}
~ObTransferPartGroup() { ~ObTransferPartGroup() {
data_size_ = 0; data_size_ = 0;
part_list_.reset(); part_list_.reset();
@ -55,7 +64,7 @@ public:
explicit ObBalanceGroupInfo(const ObBalanceGroupID &id, common::ObIAllocator &alloc) : explicit ObBalanceGroupInfo(const ObBalanceGroupID &id, common::ObIAllocator &alloc) :
id_(id), id_(id),
alloc_(alloc), alloc_(alloc),
part_groups_() part_groups_(OB_MALLOC_NORMAL_BLOCK_SIZE, ModulePageAllocator(alloc, "PartGroupArray"))
{ {
} }

View File

@ -29,10 +29,13 @@ namespace rootserver
class ObLSBalanceGroupInfo final class ObLSBalanceGroupInfo final
{ {
public: public:
ObLSBalanceGroupInfo() : inited_(false), ls_id_(), ObLSBalanceGroupInfo() :
alloc_("LSBGInfo", common::OB_MALLOC_NORMAL_BLOCK_SIZE, inited_(false),
MTL_ID()), ls_id_(),
bg_map_(), orig_part_group_cnt_map_() {} alloc_("LSBGInfo", common::OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID()),
bg_map_(),
orig_part_group_cnt_map_()
{}
~ObLSBalanceGroupInfo() { destroy(); } ~ObLSBalanceGroupInfo() { destroy(); }
int init(const share::ObLSID &ls_id); int init(const share::ObLSID &ls_id);

View File

@ -245,7 +245,7 @@ int ObPartitionBalance::on_new_partition(
if (OB_ISNULL(part_group = reinterpret_cast<ObTransferPartGroup*>(allocator_.alloc(sizeof(ObTransferPartGroup))))) { if (OB_ISNULL(part_group = reinterpret_cast<ObTransferPartGroup*>(allocator_.alloc(sizeof(ObTransferPartGroup))))) {
ret = OB_ALLOCATE_MEMORY_FAILED; ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("alloc mem fail", KR(ret)); LOG_WARN("alloc mem fail", KR(ret));
} else if (FALSE_IT(cur_part_group_ = new(part_group) ObTransferPartGroup())) { } else if (FALSE_IT(cur_part_group_ = new(part_group) ObTransferPartGroup(allocator_))) {
} else if (OB_FAIL(add_part_to_bg_map_(src_ls_id, *cur_part_group_, bg))) { } else if (OB_FAIL(add_part_to_bg_map_(src_ls_id, *cur_part_group_, bg))) {
LOG_WARN("add partition to balance group fail", KR(ret), K(src_ls_id), K(bg), LOG_WARN("add partition to balance group fail", KR(ret), K(src_ls_id), K(bg),
K(cur_part_group_)); K(cur_part_group_));

View File

@ -37,7 +37,7 @@ class ObPartitionBalance final : public ObAllBalanceGroupBuilder::NewPartitionCa
{ {
public: public:
ObPartitionBalance() : inited_(false), tenant_id_(OB_INVALID_TENANT_ID), sql_proxy_(nullptr), ObPartitionBalance() : inited_(false), tenant_id_(OB_INVALID_TENANT_ID), sql_proxy_(nullptr),
allocator_(lib::ObLabel("PART_BALANCE")), allocator_("PART_BALANCE", OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID()),
bg_builder_(), cur_part_group_(nullptr), bg_builder_(), cur_part_group_(nullptr),
ls_desc_array_(), ls_desc_map_(), ls_desc_array_(), ls_desc_map_(),
bg_map_(), bg_map_(),

View File

@ -14,7 +14,7 @@
#define OCEANBASE_SHARE_OB_DISPLAY_LIST #define OCEANBASE_SHARE_OB_DISPLAY_LIST
#include <stdint.h> #include <stdint.h>
#include "lib/container/ob_iarray.h" // ObIArray #include "lib/container/ob_iarray.h" // ObIArray
#include "lib/container/ob_array.h" // ObArrayImpl #include "lib/container/ob_se_array.h" // ObSEArrayImpl
#include "lib/string/ob_string.h" // ObString #include "lib/string/ob_string.h" // ObString
#include "lib/ob_errno.h" // OB_xx #include "lib/ob_errno.h" // OB_xx
#include "lib/utility/ob_print_utils.h" // COMMON_LOG #include "lib/utility/ob_print_utils.h" // COMMON_LOG
@ -143,12 +143,28 @@ public:
// ObDisplayList: a list which can convert to string or parse from string // ObDisplayList: a list which can convert to string or parse from string
template<typename T, typename BlockAllocatorT = ModulePageAllocator, bool auto_free = false, typename CallBack = ObArrayDefaultCallBack<T>, typename ItemEncode = NotImplementItemEncode<T> > template<typename T, int64_t LOCAL_ARRAY_SIZE = 1, typename BlockAllocatorT = ModulePageAllocator, bool auto_free = false>
class ObDisplayList : public common::ObArrayImpl<T, BlockAllocatorT, auto_free, CallBack, ItemEncode> class ObDisplayList : public common::ObSEArrayImpl<T, LOCAL_ARRAY_SIZE, BlockAllocatorT, auto_free>
{ {
public: public:
// use ObArrayImpl constructors // use ObSEArrayImpl constructors
using common::ObArrayImpl<T, BlockAllocatorT, auto_free, CallBack, ItemEncode>::ObArrayImpl; using common::ObSEArrayImpl<T, LOCAL_ARRAY_SIZE, BlockAllocatorT, auto_free>::ObSEArrayImpl;
ObDisplayList(int64_t block_size = OB_MALLOC_NORMAL_BLOCK_SIZE,
const BlockAllocatorT &alloc = BlockAllocatorT("DisplayList")) :
common::ObSEArrayImpl<T, LOCAL_ARRAY_SIZE, BlockAllocatorT, auto_free>(block_size, alloc)
{}
// specify label
ObDisplayList(const lib::ObLabel &label) :
common::ObSEArrayImpl<T, LOCAL_ARRAY_SIZE, BlockAllocatorT, auto_free>(label, OB_MALLOC_NORMAL_BLOCK_SIZE)
{}
// specify allocator and label
ObDisplayList(ObIAllocator &alloc, const lib::ObLabel &label) :
common::ObSEArrayImpl<T, LOCAL_ARRAY_SIZE, BlockAllocatorT, auto_free>
(OB_MALLOC_NORMAL_BLOCK_SIZE, ModulePageAllocator(alloc, label))
{}
// to display string // to display string
// See list_to_display_str(..) for more information // See list_to_display_str(..) for more information