Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BufferScheduler

Package version

This class accepts a Node.js Readable stream as input, and keeps reading data from the stream into the internal buffer structure, until it reaches maxBuffers. Every available buffer will try to trigger outgoingHandler.

The internal buffer structure includes an incoming buffer array, and a outgoing buffer array. The incoming buffer array includes the "empty" buffers can be filled with new incoming data. The outgoing array includes the filled buffers to be handled by outgoingHandler. Every above buffer size is defined by parameter bufferSize.

NUM_OF_ALL_BUFFERS = BUFFERS_IN_INCOMING + BUFFERS_IN_OUTGOING + BUFFERS_UNDER_HANDLING

NUM_OF_ALL_BUFFERS lesser than or equal to maxBuffers

PERFORMANCE IMPROVEMENT TIPS:

  1. Input stream highWaterMark is better to set a same value with bufferSize parameter, which will avoid Buffer.concat() operations.
  2. concurrency should set a smaller value than maxBuffers, which is helpful to reduce the possibility when a outgoing handler waits for the stream data. in this situation, outgoing handlers are blocked. Outgoing queue shouldn't be empty.

Hierarchy

  • BufferScheduler

Index

Constructors

Methods

Constructors

constructor

  • new BufferScheduler(readable: Readable, bufferSize: number, maxBuffers: number, outgoingHandler: OutgoingHandler, concurrency: number, encoding?: BufferEncoding): BufferScheduler
  • Creates an instance of BufferScheduler.

    Parameters

    • readable: Readable

      A Node.js Readable stream

    • bufferSize: number

      Buffer size of every maintained buffer

    • maxBuffers: number

      How many buffers can be allocated

    • outgoingHandler: OutgoingHandler

      An async function scheduled to be triggered when a buffer fully filled with stream data

    • concurrency: number

      Concurrency of executing outgoingHandlers (>0)

    • Optional encoding: BufferEncoding

      [Optional] Encoding of Readable stream when it's a string stream

    Returns BufferScheduler

Methods

do

  • do(): Promise<void>

Generated using TypeDoc