Skip to content

rust web服务内存占用过高不释放问题 #182

@zqlpaopao

Description

@zqlpaopao

程序是actix_web的,我的程序启动的时候14MB的内存,请求接口会用800MB+的内存执行一些操作。然而,后续接口返回大量数据后程序中的800MB+尚未回收。这是什么原因?该语言的一些设置功能,或者有没有像PPROF这样的有用工具可以检测内存溢出

然后发现 大多web框架都有这个问题
image
image

use actix_web::{get, HttpResponse, Responder};
use crate::controller::link_inspection::check::LinkInspection;
use std::collections::HashMap;
#[get("/check")]
async fn check() -> impl Responder {

// 启动堆分析器
// let res = LinkInspection::new().doing().await;
// match res {
//     Ok(response) => HttpResponse::Ok().json(response),
//     Err(error) => HttpResponse::InternalServerError().body(error.to_string()),
// }
let mut  h: HashMap<i64,i64> = HashMap::with_capacity(100000);
test(&mut h).await;

HttpResponse::InternalServerError().body(format!("{:?}", h))
}

async fn test (h : &mut HashMap<i64,i64>){

// tokio::time::sleep(tokio::time::Duration::from_secs(25)).await;
println!("start");
for v in 0..1000000{
    h.insert(v,v);
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions