Package org.aksw.commons.io.cache
Class RangeRequestWorkerImpl<A>
java.lang.Object
org.aksw.commons.util.closeable.AutoCloseableBase
org.aksw.commons.util.closeable.AutoCloseableWithLeakDetectionBase
org.aksw.commons.io.cache.RangeRequestWorkerImpl<A>
- Type Parameters:
A-
- All Implemented Interfaces:
AutoCloseable,Runnable
public class RangeRequestWorkerImpl<A>
extends AutoCloseableWithLeakDetectionBase
implements Runnable
A producer task: Takes items from an iterator and writes them them to pages
- Author:
- raven
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intThe number of items to process in one batch (before checking for conditions such as interrupts or no-more-demand)protected AdvancedRangeCacheImpl<A>Reference to the manager - if there is a failure in processing the request the executor notifies itprotected longprotected ReadableChannel<A>The data supplying iterator.protected ObservableSlottedValue<Long,Long> Demands from clients to load data up to the supplied value.protected DurationTime it took to retrieve the first itemprotected IdleModeWait mode - true: do not fetch more data then there is demand - false: keep pre-fetching dataprotected longThe offset at which the next checkpoint is sheduledprotected longThroughput in items / secondprotected longThe current offsetprotected LongUnaryOperatorMetadata supplier to support scheduling: For a given offset return the maximum length of a run of items that have already been retrieved before a separate request should be fired instead of retrieving those items twice and wasting data volumeprotected SliceAccessor<A>The pages claimed by this worker; obtained from sliceprotected longTotal timeprotected final longThe requestLimit must take result-set-limit on the backend into account!protected final longThe offset of the original requestThe data sliceprotected DurationTask termination may be delayed in millis in order to allow it to recover should another observer register in the delay phaseprotected com.google.common.base.StopwatchA timer is started as soon as there is no more explicit demand for data.Fields inherited from class org.aksw.commons.util.closeable.AutoCloseableWithLeakDetectionBase
instantiationStackTraceFields inherited from class org.aksw.commons.util.closeable.AutoCloseableBase
closeStackTrace, enableCloseStackTrace, isClosed -
Constructor Summary
ConstructorsConstructorDescriptionRangeRequestWorkerImpl(AdvancedRangeCacheImpl<A> cacheSystem, long requestOffset, long requestLimit, int bulkSize, Duration terminationDelay) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected voidStops processing of this executor and also disposes the underlying data supplier (which is expected to terminate)floatetaAtIndex(long index) Estimated time of arrival at the given index in seconds Index must be greater or equal to offset Call#pause()before calling the method.longlongThe offset of the first item that won't be served by this workerTime in seconds it took to obtain the first itemlonggetMaxAllowedRefetchCount(long offset) floatThroughput measured in items per secondcom.google.common.collect.Range<Long>protected voidAcquire a new slot into which the end-offset of a demanded data range can be put.intProcess up to n more items.voidrun()voidrunCore()A worker can only shutdown if it holds the workerSetLock: A concurrent RangeRequestIterator may schedule a new task for a worker that was just about to terminate.Methods inherited from class org.aksw.commons.util.closeable.AutoCloseableWithLeakDetectionBase
finalize, getInstantiationStackTraceMethods inherited from class org.aksw.commons.util.closeable.AutoCloseableBase
close, ensureOpen, throwClosedException
-
Field Details
-
cacheSystem
Reference to the manager - if there is a failure in processing the request the executor notifies it -
arrayOps
-
endpointDemands
Demands from clients to load data up to the supplied value. A client can unregister a demand any time. -
dataStream
The data supplying iterator. If all data in the range of operation of this worker is cached then no backend request is made. -
slice
The data slice -
pageRange
The pages claimed by this worker; obtained from slice -
currentPageId
protected long currentPageId -
requestOffset
protected final long requestOffsetThe offset of the original request -
requestLimit
protected final long requestLimitThe requestLimit must take result-set-limit on the backend into account! -
offsetToMaxAllowedRefetchCount
Metadata supplier to support scheduling: For a given offset return the maximum length of a run of items that have already been retrieved before a separate request should be fired instead of retrieving those items twice and wasting data volume -
bulkSize
protected int bulkSizeThe number of items to process in one batch (before checking for conditions such as interrupts or no-more-demand) -
offset
protected volatile long offsetThe current offset -
nextCheckpointOffset
protected long nextCheckpointOffsetThe offset at which the next checkpoint is sheduled -
terminationDelay
Task termination may be delayed in millis in order to allow it to recover should another observer register in the delay phase -
idleMode
Wait mode - true: do not fetch more data then there is demand - false: keep pre-fetching data -
terminationTimer
protected transient com.google.common.base.Stopwatch terminationTimerA timer is started as soon as there is no more explicit demand for data. Depending on the idle mode the worker can either pause or read ahead until the termination delay is reached. -
firstItemTime
Time it took to retrieve the first item -
numItemsProcessed
protected long numItemsProcessedThroughput in items / second -
processingTimeInNanos
protected long processingTimeInNanosTotal time
-
-
Constructor Details
-
RangeRequestWorkerImpl
public RangeRequestWorkerImpl(AdvancedRangeCacheImpl<A> cacheSystem, long requestOffset, long requestLimit, int bulkSize, Duration terminationDelay)
-
-
Method Details
-
getMaxAllowedRefetchCount
public long getMaxAllowedRefetchCount(long offset) -
getFirstItemTime
Time in seconds it took to obtain the first item -
getThroughput
public float getThroughput()Throughput measured in items per second -
etaAtIndex
public float etaAtIndex(long index) Estimated time of arrival at the given index in seconds Index must be greater or equal to offset Call#pause()before calling the method. -
closeActual
protected void closeActual()Stops processing of this executor and also disposes the underlying data supplier (which is expected to terminate)- Overrides:
closeActualin classAutoCloseableBase
-
initBackendRequest
- Throws:
IOException
-
run
public void run() -
checkpoint
protected void checkpoint() -
runCore
A worker can only shutdown if it holds the workerSetLock: A concurrent RangeRequestIterator may schedule a new task for a worker that was just about to terminate. Shutdown conditions: - idle for too long - reached end of data - - exception- Throws:
Exception
-
getCurrentOffset
public long getCurrentOffset() -
getEndOffset
public long getEndOffset()The offset of the first item that won't be served by this worker -
getWorkingRange
-
process
Process up to n more items.- Throws:
Exception
-
newDemandSlot
Acquire a new slot into which the end-offset of a demanded data range can be put. FIXME The worker may just have terminated; so we need synchronization with the workerSyncLock such that during scheduling workers don't disappear.- Returns:
-