zio / zio-nio

A small, unopinionated ZIO interface to NIO.
https://zio.dev/zio-nio
Apache License 2.0
187 stars 76 forks source link

isReachable is blocking fibers on thread pool #688

Open eugeny-stoyka opened 1 month ago

eugeny-stoyka commented 1 month ago

Hello, i had problem with parallelism on this code (it block my fibers on it, and CPU utilization was on ~1%)

def run: ZIO[Any, Throwable, Unit] = {
  ipStream.mapZIOParUnordered(100000) {
        for {
          ipaddr <- InetAddress.byName(ip.toString)
          r <- ipaddr.isReachable(10000)
          _ <- if(r) Console.printLine(ip) else ZIO.none
        } yield ()
  }.runDrain
}

can you add new or edit current behavior of isReachable

def run: ZIO[Any, Throwable, Unit] = {
  ipStream.mapZIOParUnordered(100000) {
      ip =>
        for {
          ipaddr <- InetAddress.byName(ip.toString)
          r <- ZIO.blocking(ipaddr.isReachable(10000))
          _ <- if(r) Console.printLine(ip) else ZIO.none
        } yield ()
  }.runDrain
}
erikvanoosten commented 1 month ago

From Discord I understood that the request is to make InetAddress.byName and InetAddress.isReachable run on the blocking threadpool.

eugeny-stoyka commented 1 month ago

or add a new method out of box for it

eugeny-stoyka commented 1 month ago

is you accept it, can i add it to this zio-nio project?