High memory usage when creating any task
sebastiaoamaro opened this issue · 1 comments
Hello, I am running a rust program inside docker containers, in this rust program I am using async-std to create tasks.
In the Cargo.toml:
async-std = { version = "1.11.0", features = ["attributes", "tokio1"] }
However, I noticed that with the creation of any type of task, just an empty one like:
pub async fn test()-> Result<()>{
Ok(())
}
Spawned with:
task::spawn(test());
The process starts to use an extra 8MB of virtual memory, I got this value with ps aux looking at the VSZ table, (the machine has 128Gb of RAM). When I noticed this, I went ahead and created a simple program like this, and ran it outside of docker:
use async_std::task;
use async_std::prelude::*;
use std::thread;
use std::time;
fn main() {
task::spawn(test());
loop{
let sleeptime = time::Duration::from_millis(10000);
thread::sleep(sleeptime);
}
}
pub async fn test(){
}
And noticed that it still uses 8MB of virtual memory, first of all, is this intended, and secondly, can it be avoided?
Thanks in advance!
8mb is a suspicious number; it's the default size pre-allocated per thread's stack space on many operating systems.
async-std by default spawns a driver thread to drive tasks to completion. Which would perfectly explain the allocation. This cannot be avoided with the current architecture. Any subsequent tasks use a single allocation per task, and should be relatively cheap.
I hope that answers your question!