object Balance
Provides mechanisms for balancing the distribution of chunks across multiple streams.
- Source
- Balance.scala
- Alphabetic
- By Inheritance
- Balance
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
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 withprefetch
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 fromsource
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.
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native() @HotSpotIntrinsicCandidate()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
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
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
Deprecated Value Members
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] ) @Deprecated @deprecated
- Deprecated
(Since version ) see corresponding Javadoc for more information.