Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Oleg Pyzhcov
@oleg-py
But you won't get a case where A is half-executed and then stopped in the middle
Jules Ivanic
@guizmaii

With this:

      heuristic.flatMap {
        case Some(a) => Task.now(Some(a))
        case _ => bruteForce
      }

My benchmark gives me ~4000 ops/s

While with this

      bruteForce.flatMap {
        case Some(a) => Task.now(Some(a))
        case _       => heuristic
      }

The same benchmark gives me ~5 ops/s

So I don’t understand why with this code:

      Task
        .racePair(heuristic, bruteForce)
        .flatMap {
          case Left((Some(a), _))    => Task.now(Some(a)) // I don’t cancel anymore here 
          case Left((None, slower))  => slower.join
          case Right((_, Some(b)))   => Task.now(Some(b)) // I don’t cancel anymore here 
          case Right((slower, None)) => slower.join
        }

The same benchmark gives me ~40 ops/s

With this last impl, I was expecting to get the 4000 ops/s.

I wast resources in the last impl but I should get the 4000 ops/s, no ?
Oleg Pyzhcov
@oleg-py
If you're always executing brute force even if you're not interested in its result, you waste CPU cycles so you get less ops/s
Your code might be computing brute force impls for the previous 10 runs where heuristic was enough, but you didn't interrupt the execution of brute-force
so it will run until completion anyway
It has to do with how tasks are constructed even more than it has to do with how they are executed.
Jules Ivanic
@guizmaii
interesting. Any way to cancel bruteForce ? or I’m fucked and will have to suffer this perf lost ?
Piotr Gawryś
@Avasil
The only way is to shift inside bruteFroce from time to time. Ideally cancelBoundary after Alex finishes new changes
Jules Ivanic
@guizmaii
bruteFroce is just pure computation.
      val bruteForce =
        Task
          .async { (scheduler, cb) =>

            scheduler.execute(new Runnable { override def run(): Unit = {
              try {
                cb(...)
              } catch {
                _ => cb(null)
              }
            } })

            Cancelable.empty
          }
what about something like that ?
This message was deleted
Oleg Pyzhcov
@oleg-py
Yeah, see that Cancelable.empty? :D
Jules Ivanic
@guizmaii
ahah
Cancelable.empty == uncancelable ?
Oleg Pyzhcov
@oleg-py
Yep
Jules Ivanic
@guizmaii
so. Impossible to kill a running Runnable ?? :’(
Oleg Pyzhcov
@oleg-py
Yeah. Monix doesn't give you Thread.interrupt()esque things. Your only way is to rewrite the logic inside.
Jules Ivanic
@guizmaii
ahah
So i’m fucked :/
Oleg Pyzhcov
@oleg-py
Effective cancellation requires either:
  1. Cleanup action specified as Cancelable
  2. Logic written as a series of Tasks, not as a single monolithic one
Fabio Labella
@SystemFw
what does the logic actually do?
Jules Ivanic
@guizmaii
compute things I can’t talk about
Fabio Labella
@SystemFw
you first need to think about what it means to cancel that at all, before thinking about what it means to do it with monix, or cats-effect, or whatever
sure, I don't need to know what things you are computing
but kinda how: are these http calls (canceling means stop waiting for a response)
or cpu computation expresses as one big thing?
the latter is impossible to cancel
it's not about monix
Jules Ivanic
@guizmaii
cpu computation
:/
Fabio Labella
@SystemFw
can you express that computation has a series of flatMap
?
Piotr Gawryś
@Avasil
I assume you have no way of splitting it?
Jules Ivanic
@guizmaii

can you express that computation has a series of flatMap

No

Oleg Pyzhcov
@oleg-py
Can you modify computation code to periodically check for an AtomicBoolean?
Jules Ivanic
@guizmaii

Can you modify computation code to periodically check for an AtomicBoolean?

Maybe but it’ll require me weeks of work I don’t have. :/

Oleg Pyzhcov
@oleg-py
Then you're left with option of Thread.interrupt() and a lot of hope
Piotr Gawryś
@Avasil
Its like "guess who" game :D
Oleg Pyzhcov
@oleg-py
Now @SystemFw will probably talk you out of it :D
Fabio Labella
@SystemFw
nah
I just want to point out that this isn't a Monix (or cats-effect) design constraint or anything
on the JVM, you can't just stop an arbitrary thing
just unplug it
the model simply doesn't allow you to do that
Jules Ivanic
@guizmaii
:/
Fabio Labella
@SystemFw
there are the various Thread.stop and interrupt primitives
they might work
they are also considered unsafe (and dangerous)