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

concurrent.join leaks memory #834

Closed
pchlupacek opened this issue Mar 25, 2017 · 10 comments
Closed

concurrent.join leaks memory #834

pchlupacek opened this issue Mar 25, 2017 · 10 comments

Comments

@pchlupacek
Copy link
Contributor

pchlupacek commented Mar 25, 2017

concurrent.join seems to leak memory, as following program will consume memory that retains in oldGen after manual GC.

object StreamsTestApp extends App {
  import Resources._

  def innerStream(idx:Int):Stream[Task, Unit] = {
    val allocate = "*"*10000
    Stream.eval(Task.delay(println(s"XXXG START $idx" + allocate.take(1))))
  }

  concurrent.join(Int.MaxValue)(
    time.sleep_[Task](10.seconds) ++
    Stream.range(0, 7000).map { i =>
      innerStream(i)
    } ++ Stream.eval_(Task.delay(println("XXXY DONE"))) ++
      time.sleep_[Task](1.hour)
  ).run.unsafeAttemptRun()


//  (
//    time.sleep_[Task](10.seconds) ++
//    Stream.range(0, 7000).flatMap { i =>
//      innerStream(i)
//    } ++ Stream.eval_(Task.delay(println("XXXY DONE"))) ++
//      time.sleep_[Task](1.hour)
//  ).run.unsafeAttemptRun()

}

After analysing through YourKit, the JVM seems to hold exactly 7000 references to stream in heap, together with their definition.

The commented (sequential) variant is just working fine w/o leaking the memory.

Any ideas of the source ?

@mpilquist
Copy link
Member

@pchlupacek
Copy link
Contributor Author

pchlupacek commented Mar 27, 2017 via email

@mpilquist
Copy link
Member

My theory is that the queue is full of the cancellation tasks, each of which closes over the inner stream.

@pchlupacek
Copy link
Contributor Author

ok, that may be the issue. However you still don't want them to be released only after outer stream terminates. You want them to be released as soon as inner is finished?

@mpilquist
Copy link
Member

Yeah, I'll put together a fix and then we can compare it to the new implementation.

@mpilquist
Copy link
Member

I confirmed this theory and have most of a fix. General idea is to race the done queue with the outer stream in go. There are some edge cases that are nasty to deal with though, so if we're happy with #836, I'm not going to finish this work.

@mpilquist
Copy link
Member

Edge cases were easy enough to fix though note that await1Async lies in its type signature -- it shouldn't be defined with Option[A] but rather A. #837.

@pchlupacek
Copy link
Contributor Author

@mpilquist like one week in production under decent load, I am ok to promote RC1. Any opinions on your side?

@mpilquist
Copy link
Member

@pchlupacek Sounds great. I'll backport a few things to 0.9 and release 0.9.5 tomorrow.

@mpilquist
Copy link
Member

@pchlupacek 0.9.5 is released

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

2 participants