Leo Laudouard
08/20/2020, 3:30 PMarrow.fx.Schedule$Decision
arrow.fx.typeclasses.Duration
arrow.fx.ScheduleKt$repeatOrElseEither$$inlined$run$lambda$1$1$2
A basic example can highlight it: (with arrow 0.10.5)
import <http://arrow.fx.IO|arrow.fx.IO>
import arrow.fx.IO.Companion.effect
import arrow.fx.Schedule
import arrow.fx.extensions.io.concurrent.concurrent
import arrow.fx.extensions.io.monad.monad
import arrow.fx.fix
import arrow.fx.repeat
import arrow.fx.typeclasses.milliseconds
fun main(args: Array<String>) {
effect {
println("Looped")
}.repeat(IO.concurrent(), Schedule.spaced(IO.monad(), 10.milliseconds))
.fix()
.unsafeRunSync()
}
Are we missing something ?
Thanks!Patrick Louis
08/21/2020, 5:22 AMfun <A> repeatPolicy() = Schedule.withMonad(IO.monad()) {
identity<A>() zipLeft spaced(AppConfig.updateFrequency.seconds) and forever()
}
My Guess is that you're missing the identity<A>() zipLeft
part which basically folds the results of your scheduled executions into the identity of the latest run, dropping all other results.
As shown in the attached picture, we don't face any memory leak with this usage.simon.vergauwen
08/21/2020, 8:02 AMsimon.vergauwen
08/21/2020, 8:03 AMSchedule
that accumulates state can be indeed ignored, and dropped with zipXX
as Patrick mentioned.simon.vergauwen
08/21/2020, 8:05 AMand forever
since spaced
is build on top of forever
while increasing the delay: Duration
property of the Decision using desc.copy(delay = d + spacedParam)
.Patrick Louis
08/21/2020, 8:14 AMPatrick Louis
08/21/2020, 8:14 AMPatrick Louis
08/21/2020, 8:15 AMand forever
, I wasn't sure on the behaviour of spaced on it's own when I implemented it.Leo Laudouard
08/21/2020, 9:07 AMfun main(args: Array<String>) {
effect {
println("Looped")
}.repeat(IO.concurrent(), repeatPolicy())
.fix()
.unsafeRunSync()
}
fun <A> repeatPolicy() = Schedule.withMonad(IO.monad()) {
identity<A>() zipLeft spaced(1.milliseconds)
}
And I have the same result:simon.vergauwen
08/21/2020, 11:48 AMsimon.vergauwen
08/21/2020, 11:49 AMsimon.vergauwen
08/21/2020, 11:49 AMPatrick Louis
08/21/2020, 12:06 PM-Xms200M -Xmx200M
Leo Laudouard
08/21/2020, 12:41 PMLooped
Looped
Looped
Looped
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "ForkJoinPool-1-worker-5"
Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: Java heap space
Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: Java heap space
Exception in thread "RMI TCP Connection(idle)" Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: Java heap space
java.lang.OutOfMemoryError: Java heap space
Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: Java heap space
Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: Java heap space
Corresponding visualVM heap graph and heap dump:Leo Laudouard
08/24/2020, 3:59 PMsimon.vergauwen
08/25/2020, 7:51 AM0.11.0-SNAPSHOT
, since that's the encoding we'll move forward with in the following releases.
It's probably also easier to debug that code, and we can then easily back-port a fix 🙂Leo Laudouard
12/18/2020, 2:03 PMsimon.vergauwen
12/18/2020, 6:47 PM