Packages

object Balance

Provides mechanisms for balancing the distribution of chunks across multiple streams.

Source
Balance.scala
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Balance
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def apply[F[_], O](chunkSize: Int)(implicit arg0: Concurrent[F]): Pipe[F, O, Stream[F, O]]

    Allows balanced processing of this stream via multiple concurrent streams.

    Allows balanced processing of this stream via multiple concurrent streams.

    This could be viewed as Stream "fan-out" operation, allowing concurrent processing of elements. As the elements arrive, they are evenly distributed to streams that have already started their evaluation. To control the fairness of the balance, the chunkSize parameter is available, which controls the maximum number of elements pulled by single inner stream.

    Note that this will pull only enough elements to satisfy needs of all inner streams currently being evaluated. When there are no stream awaiting the elements, this will stop pulling more elements from source.

    If there is need to achieve high throughput, balance may be used together with prefetch to initially prefetch large chunks that will be available for immediate distribution to streams. For example:

    source.prefetch(100).balance(chunkSize=10).take(10)

    This constructs a stream of 10 subscribers, which always takes 100 elements from the source, and gives 10 elements to each subscriber. While the subscribers process the elements, this will pull another 100 elements, which will be available for distribution when subscribers are ready.

    Often this combinator is used together with parJoin, such as :

    Stream(1,2,3,4).balance.map { worker =>
      worker.map(_.toString)
    }.take(3).parJoinUnbounded.compile.to[Set].unsafeRunSync

    When source terminates, the resulting streams (workers) are terminated once all elements so far pulled from source are processed.

    The resulting stream terminates after the source stream terminates and all workers terminate. Conversely, if the resulting stream is terminated early, the source stream will be terminated.

  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws(classOf[java.lang.CloneNotSupportedException])
  7. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  8. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  9. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  10. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  11. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  12. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  13. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  14. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  15. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  16. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  17. def through[F[_], O, O2](chunkSize: Int)(pipes: Pipe[F, O, O2]*)(implicit arg0: Concurrent[F]): Pipe[F, O, O2]

    Like apply but instead of providing a stream of worker streams, the supplied pipes are used to transform each worker.

    Like apply but instead of providing a stream of worker streams, the supplied pipes are used to transform each worker.

    Each supplied pipe is run concurrently with other. This means that amount of pipes determines concurrency.

    Each pipe may have a different implementation, if required; for example one pipe may process elements while another may send elements for processing to another machine.

    Results from pipes are collected and emitted as the resulting stream.

    This will terminate when :

    • this terminates
    • any pipe fails
    • all pipes terminate
    chunkSize

    maximum chunk to present to each pipe, allowing fair distribution between pipes

    pipes

    pipes to use to process work

  18. def toString(): String
    Definition Classes
    AnyRef → Any
  19. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  20. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  21. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws(classOf[java.lang.InterruptedException])

Inherited from AnyRef

Inherited from Any

Ungrouped