Throttler

class Throttler

Enables limiting of Source and Sink throughput. Attach to this throttler via source and sink and set the desired throughput via bytesPerSecond. Multiple Sources and Sinks can be attached to a single Throttler and they will be throttled as a group, where their combined throughput will not exceed the desired throughput. The same Source or Sink can be attached to multiple Throttlers and its throughput will not exceed the desired throughput of any of the Throttlers.

This class has these tuning parameters:

  • bytesPerSecond: Maximum sustained throughput. Use 0 for no limit.

  • waitByteCount: When the requested byte count is greater than this many bytes and isn't immediately available, only wait until we can allocate at least this many bytes. Use this to set the ideal byte count during sustained throughput.

  • maxByteCount: Maximum number of bytes to allocate on any call. This is also the number of bytes that will be returned before any waiting.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun bytesPerSecond(bytesPerSecond: Long, waitByteCount: Long = this.waitByteCount, maxByteCount: Long = this.maxByteCount)

Sets the rate at which bytes will be allocated. Use 0 for no limit.

Link copied to clipboard
fun sink(sink: Sink): Sink

Create a Sink which honors this Throttler.

Link copied to clipboard
fun source(source: Source): Source

Create a Source which honors this Throttler.