Ferry

ferry.Ferry
See theFerry companion trait
object Ferry

Attributes

Companion
trait
Source
Ferry.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Ferry.type

Members list

Type members

Classlikes

final case class Metrics(queued: Int, inFlightBatches: Int)

Value parameters

inFlightBatches

Batch calls currently running, including a perKey ferry's direct calls for idle keys.

queued

Inputs waiting in the queue. Inputs already taken into the batch being assembled are not counted.

Attributes

Source
Ferry.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Value members

Concrete methods

def keyed[R, E, I, A](config: FerryConfig)(call: (NonEmptyChunk[I]) => ZIO[R, E, Map[I, A]]): URIO[R & Scope, Ferry[I, E, Option[A]]]

Creates a Ferry for the common case of a batch call answering with one result per distinct input.

Creates a Ferry for the common case of a batch call answering with one result per distinct input.

The batch call receives each distinct input once. A caller whose input is absent from the returned map gets None.

Attributes

Source
Ferry.scala
def make[R, E, I, B, A](config: FerryConfig)(call: (NonEmptyChunk[I]) => ZIO[R, E, B])(extract: (I, B) => A): URIO[R & Scope, Ferry[I, E, A]]

Creates a Ferry whose lifetime is bound to the enclosing Scope.

Creates a Ferry whose lifetime is bound to the enclosing Scope.

Value parameters

call

The batch call. It receives the inputs in submission order, including duplicates.

extract

Picks one caller's result out of the batch result. If it throws, that caller gets the exception as a defect.

Attributes

Source
Ferry.scala
def perKey[R, E, K, I, B, A](config: PerKeyConfig, key: I => K, weigh: I => Long = ..., order: Order[I] = ...)(call: (K, NonEmptyChunk[I]) => ZIO[R, E, B])(extract: (I, B) => A): URIO[R & Scope, Ferry[I, E, A]]

Creates a Ferry that batches each key's inputs separately, and keeps each key's batches in order.

Creates a Ferry that batches each key's inputs separately, and keeps each key's batches in order.

Inputs with the same key are dispatched in order (by default, submission order), in batches of that key only, and a key never has more than one batch in flight: its next batch is dispatched only once the previous one has completed. Different keys are batched independently and run concurrently, up to maxInFlightBatches in total. Keys with work waiting take turns, so a key that always has more never starves the others.

Only keys that are busy are batched. With the default maxBatchDelay of zero, an input for an idle key (nothing waiting, nothing in flight) is sent at once by its own caller, as a batch of one, without queueing or waiting for a worker: occasional traffic pays no batching cost and never waits behind busy keys. Inputs that arrive for the key while that call is in flight are batched behind it, so a key switches to batching exactly when it has concurrent work, and back when it is idle again. These direct calls are not counted against maxInFlightBatches, which bounds the batches of busy keys; at most one runs per idle key. PerKeyConfig.directIdleKeys turns them off.

This suits writes that must be applied in order per entity, such as appends to a per-entity log guarded by a conditional write: one writer per entity removes write contention, and each round trip carries everything that arrived while the previous one was in flight.

To report outcomes per input, let call answer with one outcome per input and fail only when the whole batch did not happen. An input rejected on its own merits then affects only its own caller.

Value parameters

call

The batch call, given the key and that key's inputs in order. FoldWrite implements the common read-once, apply, conditional-write call, and ProjectedWrite the same with a second write that projects the result.

extract

Picks one caller's result out of the batch result. If it throws, that caller gets the exception as a defect.

key

The entity an input belongs to.

order

The order in which a key's waiting inputs are sent: see Order. Defaults to submission order.

weigh

The weight of an input, such as its size in bytes, for maxBatchWeight and maxQueuedWeight. Defaults to 1.

Attributes

Source
Ferry.scala