I - input payload data typeO - output payload data typepublic class BoundedInMemoryQueue<I,O> extends Object implements Iterable<O>
memoryLimit. Unlike standard bounded queue
implementations, this queue bounds the size by memory bytes occupied by its tenants. The standard implementation
bounds by the number of entries in the queue.
It internally samples every RECORD_SAMPLING_RATEth record and adjusts number of records in queue
accordingly. This is done to ensure that we don't OOM.
This queue supports multiple producer single consumer pattern.| Modifier and Type | Field and Description |
|---|---|
long |
avgRecordSizeInBytes
Indicates avg record size in bytes.
|
int |
currentRateLimit
indicates rate limit (number of records to cache).
|
Semaphore |
rateLimiter
It indicates number of records to cache.
|
static int |
RECORD_POLL_INTERVAL_SEC
Interval used for polling records in the queue.
|
static int |
RECORD_SAMPLING_RATE
Rate used for sampling records to determine avg record size in bytes.
|
AtomicLong |
samplingRecordCounter
Used for sampling records with "RECORD_SAMPLING_RATE" frequency.
|
| Constructor and Description |
|---|
BoundedInMemoryQueue(long memoryLimit,
Function<I,O> transformFunction)
Construct BoundedInMemoryQueue with default SizeEstimator.
|
BoundedInMemoryQueue(long memoryLimit,
Function<I,O> transformFunction,
SizeEstimator<O> payloadSizeEstimator)
Construct BoundedInMemoryQueue with passed in size estimator.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Puts an empty entry to queue to denote termination.
|
void |
insertRecord(I t)
Inserts record into queue after applying transformation.
|
Iterator<O> |
iterator() |
void |
markAsFailed(Throwable e)
API to allow producers and consumer to communicate termination due to failure.
|
int |
size() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorpublic static final int RECORD_POLL_INTERVAL_SEC
public static final int RECORD_SAMPLING_RATE
public final Semaphore rateLimiter
public final AtomicLong samplingRecordCounter
public int currentRateLimit
public long avgRecordSizeInBytes
public BoundedInMemoryQueue(long memoryLimit,
Function<I,O> transformFunction)
memoryLimit - MemoryLimit in bytestransformFunction - Transformer Function to convert input payload type to stored payload typepublic BoundedInMemoryQueue(long memoryLimit,
Function<I,O> transformFunction,
SizeEstimator<O> payloadSizeEstimator)
memoryLimit - MemoryLimit in bytestransformFunction - Transformer Function to convert input payload type to stored payload typepayloadSizeEstimator - Payload Size Estimatorpublic int size()
public void insertRecord(I t) throws Exception
t - Item to be queuedExceptionpublic void close()
public void markAsFailed(Throwable e)
Copyright © 2022 The Apache Software Foundation. All rights reserved.