apache / brpc

brpc is an Industrial-grade RPC framework using C++ Language, which is often used in high performance system such as Search, Storage, Machine learning, Advertisement, Recommendation etc. "brpc" means "better RPC".

Home Page:https://brpc.apache.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

server 端通过channel 访问其他服务,内存持续缓慢上涨,疑似内存泄漏

qhren opened this issue · comments

Describe the bug (描述bug)
服务运行一段时间后,内存持续上涨

To Reproduce (复现方法)
链接tcmalloc,打开fno-omit-frame-pointer 编译选项 和 heap profiler,对比前后的内存占用diff,发现内存消耗在channel init和channel call调用。
下图中的sumit_post_request的基本结构如下:

   baidu::rpc::Channel channel;
   baidu::rpc::ChannelOptions options;
   baidu::rpc::Controller cntl;
   options.protocol = baidu::rpc::PROTOCOL_HTTP;
   options.timeout_ms = 60000;
   options.max_retry = 3;

   if (channel.Init(uri.c_str(), "", &options) != 0) {
       CFATAL_LOG("init channel failed url = %s ", base_url.c_str());
       return ErrorCode::ERROR;
   }

   cntl.http_request().set_method(baidu::rpc::HTTP_METHOD_POST);
   cntl.http_request().uri() = base_url;
   cntl.http_request().set_content_type("application/json");  // set content type
   cntl.request_attachment().append(data_json_str);

   channel.CallMethod(NULL, &cntl, NULL, NULL, NULL);
   if (cntl.Failed()) {
       CFATAL_LOG("rpc failed error text = %s", cntl.ErrorText().c_str());
       ret_code = -1;
       return ErrorCode::ERROR;
   }

   o_res_json_str = cntl.response_attachment().to_string();
   ret_code = 200;
   return ErrorCode::SUCCESS;

Expected behavior (期望行为)
内存在服务压力变化不大的情况下基本维持稳定

Versions (各种版本)
OS:centos 6.3
Compiler: gcc12
brpc: stable 版本
protobuf: protobuf 2.4

Additional context/screenshots (更多上下文/截图)
heap profiler 时间:
image
内存占用对比差异:
image