Skip to content

Commit

Permalink
Optimize the memory usage of RPC requests
Browse files Browse the repository at this point in the history
  • Loading branch information
liucc1997 authored and ob-robot committed Oct 20, 2024
1 parent 94f4e26 commit e7c6768
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion deps/oblib/src/rpc/obrpc/ob_poc_rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ int ObPocServerHandleContext::create(int64_t resp_id, const char* buf, int64_t s
}
IGNORE_RETURN snprintf(rpc_timeguard_str, sizeof(rpc_timeguard_str), "sz=%ld,pcode=%x,id=%ld", sz, pcode, tenant_id);
timeguard.click(rpc_timeguard_str);
ObRpcMemPool* pool = ObRpcMemPool::create(tenant_id, pcode_label, pool_size);
ObRpcMemPool* pool = ObRpcMemPool::create(tenant_id, pcode_label, pool_size, ObRpcMemPool::RPC_CACHE_SIZE);
void *temp = NULL;

#ifdef ERRSIM
Expand Down
8 changes: 4 additions & 4 deletions deps/oblib/src/rpc/obrpc/ob_rpc_mem_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ static void* rpc_mem_pool_direct_alloc(int64_t tenant_id, const char* label, int
return common::ob_malloc(sz, attr);
}
static void rpc_mem_pool_direct_free(void* p) { common::ob_free(p); }
static ObRpcMemPool::Page* rpc_mem_pool_create_page(int64_t tenant_id, const char* label, int64_t sz) {
int64_t alloc_sz = std::max(sizeof(ObRpcMemPool::Page) + sz, (uint64_t)ObRpcMemPool::RPC_POOL_PAGE_SIZE);
static ObRpcMemPool::Page* rpc_mem_pool_create_page(int64_t tenant_id, const char* label, int64_t sz, int64_t cache_sz = ObRpcMemPool::RPC_POOL_PAGE_SIZE) {
int64_t alloc_sz = std::max(sizeof(ObRpcMemPool::Page) + sz, (uint64_t)cache_sz);
ObRpcMemPool::Page* page = (typeof(page))rpc_mem_pool_direct_alloc(tenant_id, label, alloc_sz);
if (OB_ISNULL(page)) {
LOG_WARN_RET(common::OB_ALLOCATE_MEMORY_FAILED, "rpc memory pool alloc memory failed", K(sz), K(alloc_sz));
Expand All @@ -67,11 +67,11 @@ static void rpc_mem_pool_destroy_page(ObRpcMemPool::Page* page) {
}
}

ObRpcMemPool* ObRpcMemPool::create(int64_t tenant_id, const char* label, int64_t req_sz)
ObRpcMemPool* ObRpcMemPool::create(int64_t tenant_id, const char* label, int64_t req_sz, int64_t cache_sz)
{
Page* page = nullptr;
ObRpcMemPool* pool = nullptr;
if (OB_NOT_NULL(page = rpc_mem_pool_create_page(tenant_id, label, req_sz + sizeof(ObRpcMemPool)))) {
if (OB_NOT_NULL(page = rpc_mem_pool_create_page(tenant_id, label, req_sz + sizeof(ObRpcMemPool), cache_sz))) {
if (OB_NOT_NULL(pool = (typeof(pool))page->alloc(sizeof(ObRpcMemPool)))) {
new(pool)ObRpcMemPool(tenant_id, label); // can not be null
pool->add_page(page);
Expand Down
7 changes: 5 additions & 2 deletions deps/oblib/src/rpc/obrpc/ob_rpc_mem_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ namespace obrpc
class ObRpcMemPool
{
public:
enum { RPC_POOL_PAGE_SIZE = (1<<14) - 128};
enum {
RPC_POOL_PAGE_SIZE = (1<<14) - 128,
RPC_CACHE_SIZE = 3968
};
struct Page;
explicit ObRpcMemPool(): last_(NULL), tenant_id_(OB_INVALID_TENANT_ID), mem_label_("RpcDefault") {}
explicit ObRpcMemPool(int64_t tenant_id, const char* label): last_(NULL), tenant_id_(tenant_id), mem_label_(label) {}
~ObRpcMemPool() { destroy(); }
static ObRpcMemPool* create(int64_t tenant_id, const char* label, int64_t req_sz);
static ObRpcMemPool* create(int64_t tenant_id, const char* label, int64_t req_sz, int64_t cache_sz = ObRpcMemPool::RPC_POOL_PAGE_SIZE);
void* alloc(int64_t sz);
void set_tenant_id(int64_t tenant_id) { tenant_id_ = tenant_id; }
void reuse();
Expand Down

0 comments on commit e7c6768

Please sign in to comment.