Configuration.pack()
Description
Appends a pack filter to the current pipeline layout.
A pack filter combines multiple input messages into one.
- INPUT - Stream of Messages to combine.
- OUTPUT - Stream of combined Messages.
The number of input Messages to combine into one is given by the batchSize parameter, which defaults to 1 if not presented.
You can set the maximum time interval between two consecutive batches coming out of a pack filter by the interval option in the options parameter. It can be a number in seconds, or a string with a time unit suffix such as 's', 'm', 'h' or 'd'. When interval is greater than 0, a combined Message, if any, is always produced every time that interval has passed, no matter if batchSize is reached or not.
Defragmentation
A Data object stores its bytes in an array of 4KB chunks. After a series of Data splitting and joining operations by codecs and scripts, the chunks stored in Data will be fragmented and have unused spaces inside of them. The pack filter has a side-effect to defragment the chunks to save memory.
The degree of defragmentation can be controlled by the vacancy option in the options parameter. It tells the filter how much vacant space is allowed in every chunk, ranging from 0 where no vacancy should be kept, to 1 where no defragmentation is done at all. The default is 0.5, which means when a chunk has over half (2KB) space unused, it should be merged with its neighboring chunks.
Defragmentation does not change your code logic, it only saves memory consumption at the cost of extra memory move operations.
Syntax
pipy().pipeline().pack()pipy().pipeline().pack(batchSize)pipy().pipeline().pack(batchSize,{vacancy,interval,})
Parameters
pack(batchSize?, options?)
Number of messages to pack into one. Default is 1.
Options including:
- vacancy - Percentage of spare space letf in the internal storage of packed Data object. Default is 0.5.
- interval - Maximum time to wait before outputting a batch even if the number of messages is not enough. Can be a number in seconds or a string with one of the time unit suffixes such as s, m or h. Default is 5 seconds.
The same Configuration object.