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

Reduce memory usage when large number of GraphStageLogic involves #1624

Open
He-Pin opened this issue Dec 22, 2024 · 1 comment
Open

Reduce memory usage when large number of GraphStageLogic involves #1624

He-Pin opened this issue Dec 22, 2024 · 1 comment

Comments

@He-Pin
Copy link
Member

He-Pin commented Dec 22, 2024

@queimadus's report in #1566
refs: #1623

and with the code below

import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.stream.scaladsl.{Sink, Source}
import org.apache.pekko.util.ByteString

import scala.concurrent.Await

object PekkoQuickstart extends App {
  private implicit val system: ActorSystem = ActorSystem()

  val s = Source
    .repeat(())
    .map(_ => ByteString('a' * 400000))
    .take(1000000)
    .prefixAndTail(50000)
    .flatMapConcat { case (prefix, tail) => Source(prefix).concatLazy(tail) }

  val r = Source.empty
    .concatAllLazy(List.tabulate(30000)(_ => s): _*)
    .runWith(Sink.ignore)

  Await.result(r, scala.concurrent.duration.Duration.Inf)
  println(r.value)

//  Source
//    .repeat(s)
//    .take(30000)
//    .flatMapConcat(x => x)
//    .runWith(Sink.ignore)
//    .onComplete(println(_))

//  Source.empty
//    .concatAllLazy(List.tabulate(30000)(_ => Source.lazySource(() => s)): _*)
//    .runWith(Sink.ignore).onComplete(println(_))
}
image

we can get a heap dump of
image

image

To fix the problem, I think we need to clean the logic once we are done with a sub-graph, but the current code needs to get a snapshot for the materializer

To fix the problem I think we need to recycle the graph stage logics, which means more changes need to be done in the interpreter.

@He-Pin
Copy link
Member Author

He-Pin commented Dec 22, 2024

We can see, that there are 30000 logics, which are brought in by the concatAll, to reduce memory, we may need to recycle the logics once it's been done (then will not show up in the snapshot maybe?)

Another problem is, to support the debug, we may let the GraphStageLogic extends GraphStageLogicInfo, etc thing after the logic is done, switch the GraphStageLogic with GraphStageLogicInfo implementation

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