偷得浮生半日咸 2023-02-03 10:23 采纳率: 0%
浏览 23

epoll_wait()高占用

mongoose_V7.8搭httpServer服务器长时间运行后,CPU出现高占用
程序运行在开发板中:aarch64 aarch64 GNU/Linux

使用gstack捕捉到的堆栈信息如下:

#0 0x0000ffff8f3fdf44 in epoll_pwait () from /lib/libc.so.6 
#1 0x000000000053bd84 in mg_iotest (mgr=0xffff78000b40, ms=1000) at /home/gaojie/RSU/common/net/mongoose/mongoose.c:4500 
#2 0x000000000053bf08 in mg_mgr_poll (mgr=0xffff78000b40, ms=1000) at /home/gaojie/RSU/common/net/mongoose/mongoose.c:4604 
#3 0x0000000000513e24 in HttpServer::Start (this=0xffff78000b20) at /home/gaojie/RSU/common/net/Http/Http.cpp:200 

相关代码段(参考官方示例:mongoose/examples/multi-threaded/

void thread_function(void *param)
{
    struct userdata *p = (struct userdata *) param;
    // Respond, wakeup event manager
    std::string url = std::string(p->uri.ptr, p->uri.len);
    std::string body = std::string(p->body.ptr, p->body.len);
    INF(RSUSTATE, "thread_function start pthreadId:%lu url:%s", pthread_self(), url.c_str());
    auto it = s_handler_map.find(url);
    if (it != s_handler_map.end()){
        ReqHandler handle_func = it->second;
        handle_func(url, body, p, sendHttpRsp);
        INF(RSUSTATE, "thread_function doing success url:%s", url.c_str());
    }
    else{
        // 未注册url-发送错误信息
        send(p->sock, RSP_ERR, strlen(RSP_ERR), 0);
    }
    close(p->sock);               // Close the connection
    free((void *) p->body.ptr);   // free body
    free((void *) p->uri.ptr);   // free uri
    free(p);                      // free userdata
    INF(RSUSTATE, "thread_function doing close url:%s", url.c_str());
}

void onHttpEvent(mg_connection *c, int ev, void *ev_data, void *fn_data)
{
    if (ev == MG_EV_HTTP_MSG) {
        mg_http_message *hm = (struct mg_http_message *) ev_data;
        userdata *data = (userdata *)calloc(1, sizeof(*data));  // worker will free it
        data->body = mg_strdup(hm->body);              // worker will free it
        data->uri = mg_strdup(hm->uri);                 // worker will free it
        data->sock = mg_mkpipe(c->mgr, _pipeEvent, c, true);  // Create pipe
        start_thread(thread_function, data);  // Start thread and pass data
    }
      else if (ev == MG_EV_CLOSE) {
        if (c->fn_data != NULL){
            _unlink_conns(c, (mg_connection *)c->fn_data);
        }    
      }
}
诚信请教大

img


牛的解答

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2023-02-03 12:09
    关注
    评论

报告相同问题?

问题事件

  • 创建了问题 2月3日

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?