Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory does not release #344

Open
zrus opened this issue Nov 10, 2022 · 0 comments
Open

Memory does not release #344

zrus opened this issue Nov 10, 2022 · 0 comments

Comments

@zrus
Copy link

zrus commented Nov 10, 2022

Struggling with Bastion does not release memory after handling messages

  • Version: bastion v0.4.5 feature tokio-runtime / tokio v1.21 feature full / tokio-util v0.7 feature full
  • Platform: Linux 5.15.68.1-microsoft-standard-WSL2 x86_64 GNU/Linux
  • Subsystem: Ubuntu 20.04 LTS

Hi,

Now I am working with a project that uses Bastion as a core of actor model architect. I have used it once before but with this project I am running into a problem as I describe. Here is my little demonstration about it:

use std::time::Instant;

use bastion::prelude::*;

#[tokio::main(flavor = "multi_thread", worker_threads = 16)]
async fn main() {
  let start = Instant::now();

  Bastion::children(|children| {
    children
      .with_distributor(Distributor::named("test_actor"))
      .with_redundancy(15)
      .with_exec(|ctx| async move {
        loop {
          MessageHandler::new(ctx.recv().await?).on_tell(|msg: Vec<u8>, _| {
            drop(msg);
          });
        }
      })
  })
  .unwrap();

  let sender = Bastion::children(|children| {
    children.with_exec(|_| async {
      let mut interval = tokio::time::interval(tokio::time::Duration::from_secs(10));
      loop {
        interval.tick().await;
        for _ in 0..3_000 {
          Distributor::named("test_actor")
            .tell_one(vec![0u8; 300])
            .unwrap();
        }
      }
    })
  })
  .unwrap();

  Bastion::init();
  Bastion::start();

  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).unwrap();
  sender.kill().unwrap();

  println!("Running time: {:?}", start.elapsed());

  let waiting = Instant::now();
  std::io::stdin().read_line(&mut buf).unwrap();

  println!("Waiting time: {:?}", waiting.elapsed());

  Bastion::block_until_stopped();
}

Result
After start: memory is about 0.2%
After first std::io::stdin().read_line(&mut buf).unwrap();: Running time: 2488.367728948s - memory is about 0.5%
After second std::io::stdin().read_line(&mut buf).unwrap();: Waiting time: 792.050614104s - memory is being kept at 0.5%

Sorry for my information that could not be easy to analyze (I am still new to Rust and have not found a tool to measure memory yet 😓).

As you can see if I send 10_000 of messages at a time (each message is about 300 bytes (in practice is more than that)) the issue comes.

Hope someone could help me out of this soon. Did I do something wrong? Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant