Class PiecePickerImpl
java.lang.Object
com.biglybt.core.peermanager.piecepicker.impl.PiecePickerImpl
- All Implemented Interfaces:
PiecePicker
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
An instance of this listener is registered with peerControlprivate class
An instance of this listener is registered with each peerprivate class
An instance of this listener is registered with peerControl Through this, we learn of peers joining and leaving and attach/detach listeners to themprotected static class
private static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
protected int[]
periodically updated consistent view of availability for calculatingprotected int[]
asynchronously updated availabilityprotected long
private long
protected long
indicates availability needs to be recomputed due to detected driftprotected final AEMonitor
private long
protected static boolean
private final DiskManager
private final PiecePickerImpl.DiskManagerListenerImpl
private final SpeedTokenDispenser
private final DiskManagerPiece[]
private static final boolean
private static boolean
private static final long
private static final long
private static final long
private static final long
private static final long
private boolean
A flag to indicate when we're in endgame modeprivate boolean
private final Object
private Map
<Long, EndGameModeChunk> private LinkedList
<EndGameModeChunk> The list of chunks needing to be downloaded (the mechanism change when entering end-game mode)private float[]
private long
protected long
event # of user file priority settings changesprivate static final long
min # pieces in file for first/last prioritizationprotected static boolean
protected static boolean
protected static long
private CopyOnWriteSet
<Integer> private int[]
private float
private float
private int
private int
private int
The rarest availability level of pieces that we affirmatively want to try to request from others soonest ie; our prime targets for requesting rarest piecesprotected boolean
private static boolean
private long
private final CopyOnWriteList
<PiecePickerListener> private static final boolean
private static final LogIDs
private int
private int
private final int
protected int
private int
protected long
private static final int
private static final int
protected static long
event # of user settings controlling priority changesprivate final PEPeerControl
protected final Map
private final PEPeerManagerListener
private final PEPiece[]
private final int
private static final int
ms a block is expected to complete inprivate static final int
ms since last writeprivate static final int
private static final int
currently webseeds + other explicit priorities are around 10000 or more - at this point we ignore rarityprivate final CopyOnWriteList
private static final int
priority at and above which pieces require real-time schedulingprivate static final int
private static final int
private static final int
priority boost due to being too oldprivate static final int
Additional boost for more completed High priorityprivate static final int
user sets file as "High"private static final int
private static final int
user select prioritize first/lastprivate static final int
finish pieces already almost doneprivate static final int
keep working on same pieceprivate long
last availability event # when priority bases were calculatedprivate long
last user priority event # when priority bases were calculatedprivate long
last user parameter settings event # when priority bases were calculatedprivate boolean
private long[]
private long[]
(package private) static final Random
private static final int
Max number of request sent to a peerprivate static final int
private static final int
Min number of requests sent to a peerprivate boolean
private static final long
private static final long
private final CopyOnWriteList
protected int
private static final int
Default number of requests sent to a peer, (for each X B/s another request will be used)private int[]
the priority for starting each piece/base priority for resumingprivate static final long
min ms for forced availability rebuildprivate long
private long
private static final long
min ms for recalculating availability - reducing this has serious ramificationsprivate static final long
private static final long
min ms for recalculating base prioritiesprivate long
private long
private long
private long
time that base priorities were last computedFields inherited from interface com.biglybt.core.peermanager.piecepicker.PiecePicker
REQUEST_HINT_MAX_LIFE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
final void
addEndGameChunks
(PEPiece pePiece) adds every block from the piece to the list of chuncks to be selected for egm requestingfinal void
addHavePiece
(PEPeer peer, int pieceNumber) void
addListener
(PiecePickerListener listener) void
addPriorityProvider
(PiecePriorityProvider provider) void
addRTAProvider
(PieceRTAProvider provider) final void
one reason requests don't stem from the individual peers is so the connections can be sorted by best uploaders, providing some ooprtunity to download the most important (ie; rarest and/or highest priority) pieces faster and more reliablyprivate int
Count current global min avail pieces in progress (not counting non-rarest pieces but keep them to compensate high churn, remove completed ones, ignore idle ones)protected final void
Early-outs when finds a downloadable piece Either way sets hasNeededUndonePiece and neededUndonePieceChange if necessaryprivate void
final void
void
private void
This computes the base priority for all pieces that need requesting if there's been any availability change or user priority setting changes since the last call, which will be most of the time since availability changes so dynamically It will change startPriorities[] (unless there was nothing to do)private void
private boolean
void
destroy()
protected final int
findPieceInEndGameMode
(PEPeerTransport pt, int wants) protected final int
findPieceToDownload
(PEPeerTransport pt, int nbWanted) protected final boolean
findRTAPieceToDownload
(PEPeerTransport pt, boolean best_uploader, long best_uploader_next_block_eta) void
generateEvidence
(IndentWriter writer) final int[]
final int
getAvailability
(int pieceNumber) final long
final float
final long
int
getEGMRequestCount
(int piece_number, int block_number) int[]
final int
final float
float
getMinAvailability
(int fileIndex) int
final long
protected int
int
getPieceString
(int piece_number) protected final int
getPieceToStart
(BitFlags startCandidates) private int
This method is the downloading core.boolean
int
final boolean
boolean
boolean
isForcePiece
(int pieceNumber) final boolean
protected void
private int[]
final void
removeFromEndGameModeChunks
(int pieceNumber, int offset) void
removeListener
(PiecePickerListener listener) void
removePriorityProvider
(PiecePriorityProvider provider) void
removeRTAProvider
(PieceRTAProvider provider) void
setForcePiece
(int pieceNumber, boolean forced) void
setGlobalRequestHint
(int piece_number, int start_bytes, int byte_count) void
setReverseBlockOrder
(boolean is_reverse) void
setSequentialAscendingFrom
(int start_piece) void
setSequentialDescendingFrom
(int start_piece) private void
setSequentialDownload
(int val) private void
final void
This method will compute the pieces' overall availability (including ourself) and the _globalMinOthers invalid input: '&' _globalAvail
-
Field Details
-
LOG_RTA
private static final boolean LOG_RTA- See Also:
-
EGM_IS_BLOCK_BASED
private static final boolean EGM_IS_BLOCK_BASED- See Also:
-
LOGID
-
TIME_MIN_AVAILABILITY
private static final long TIME_MIN_AVAILABILITYmin ms for recalculating availability - reducing this has serious ramifications- See Also:
-
TIME_MIN_FILE_AVAILABILITY
private static final long TIME_MIN_FILE_AVAILABILITY- See Also:
-
TIME_MIN_PRIORITIES
private static final long TIME_MIN_PRIORITIESmin ms for recalculating base priorities- See Also:
-
TIME_AVAIL_REBUILD
private static final long TIME_AVAIL_REBUILDmin ms for forced availability rebuild- See Also:
-
PRIORITY_W_FIRSTLAST
private static final int PRIORITY_W_FIRSTLASTuser select prioritize first/last- See Also:
-
FIRST_PIECE_MIN_NB
private static final long FIRST_PIECE_MIN_NBmin # pieces in file for first/last prioritization- See Also:
-
PRIORITY_W_FILE_BASE
private static final int PRIORITY_W_FILE_BASEuser sets file as "High"- See Also:
-
PRIORITY_W_FILE_RANGE
private static final int PRIORITY_W_FILE_RANGE- See Also:
-
PRIORITY_W_COMPLETION
private static final int PRIORITY_W_COMPLETIONAdditional boost for more completed High priority- See Also:
-
PRIORITY_W_AGE
private static final int PRIORITY_W_AGEpriority boost due to being too old- See Also:
-
PRIORITY_DW_AGE
private static final int PRIORITY_DW_AGEms a block is expected to complete in- See Also:
-
PRIORITY_DW_STALE
private static final int PRIORITY_DW_STALEms since last write- See Also:
-
PRIORITY_W_PIECE_DONE
private static final int PRIORITY_W_PIECE_DONEfinish pieces already almost done- See Also:
-
PRIORITY_W_SAME_PIECE
private static final int PRIORITY_W_SAME_PIECEkeep working on same piece- See Also:
-
PRIORITY_OVERRIDES_RAREST
private static final int PRIORITY_OVERRIDES_RARESTcurrently webseeds + other explicit priorities are around 10000 or more - at this point we ignore rarity- See Also:
-
PRIORITY_REQUEST_HINT
private static final int PRIORITY_REQUEST_HINT- See Also:
-
PRIORITY_SEQUENTIAL_START
private static final int PRIORITY_SEQUENTIAL_START- See Also:
-
PRIORITY_REALTIME
private static final int PRIORITY_REALTIMEpriority at and above which pieces require real-time scheduling- See Also:
-
PRIORITY_FORCED
private static final int PRIORITY_FORCED- See Also:
-
REQUESTS_MIN_MIN
private static final int REQUESTS_MIN_MINMin number of requests sent to a peer- See Also:
-
REQUESTS_MIN_MAX
private static final int REQUESTS_MIN_MAX- See Also:
-
REQUESTS_MAX
private static final int REQUESTS_MAXMax number of request sent to a peer- See Also:
-
SLOPE_REQUESTS
private static final int SLOPE_REQUESTSDefault number of requests sent to a peer, (for each X B/s another request will be used)- See Also:
-
RTA_END_GAME_MODE_SIZE_TRIGGER
private static final long RTA_END_GAME_MODE_SIZE_TRIGGER- See Also:
-
END_GAME_MODE_RESERVED_TRIGGER
private static final long END_GAME_MODE_RESERVED_TRIGGER- See Also:
-
END_GAME_MODE_SIZE_TRIGGER
private static final long END_GAME_MODE_SIZE_TRIGGER- See Also:
-
RTA_END_GAME_MODE_SIZE_TRIGGER_BLOCKS
private static final long RTA_END_GAME_MODE_SIZE_TRIGGER_BLOCKS- See Also:
-
END_GAME_MODE_RESERVED_TRIGGER_BLOCKS
private static final long END_GAME_MODE_RESERVED_TRIGGER_BLOCKS- See Also:
-
END_GAME_MODE_SIZE_TRIGGER_BLOCKS
private static final long END_GAME_MODE_SIZE_TRIGGER_BLOCKS- See Also:
-
END_GAME_MODE_TIMEOUT
private static final long END_GAME_MODE_TIMEOUT- See Also:
-
NO_REQUEST_BACKOFF_MAX_MILLIS
private static final int NO_REQUEST_BACKOFF_MAX_MILLIS- See Also:
-
NO_REQUEST_BACKOFF_MAX_LOOPS
private static final int NO_REQUEST_BACKOFF_MAX_LOOPS -
random
-
diskManager
-
peerControl
-
diskManagerListener
-
peerListeners
-
peerManagerListener
-
nbPieces
private final int nbPieces -
dmPieces
-
pePieces
-
pieceSize
private final int pieceSize -
rarestStartedPieces
-
availabilityMon
-
endGameModeChunkLock
-
nbPiecesDone
protected volatile int nbPiecesDone -
availabilityAsynch
protected volatile int[] availabilityAsynchasynchronously updated availability -
availabilityDrift
protected volatile long availabilityDriftindicates availability needs to be recomputed due to detected drift -
timeAvailRebuild
private long timeAvailRebuild -
availability
protected volatile int[] availabilityperiodically updated consistent view of availability for calculating -
time_last_avail
private long time_last_avail -
availabilityChange
protected volatile long availabilityChange -
availabilityComputeChange
private volatile long availabilityComputeChange -
time_last_rebuild
private long time_last_rebuild -
timeAvailLessThanOne
private long timeAvailLessThanOne -
globalAvail
private float globalAvail -
globalAvgAvail
private float globalAvgAvail -
nbRarestActive
private int nbRarestActive -
globalMin
private int globalMin -
globalMax
private int globalMax -
globalMinOthers
private volatile int globalMinOthersThe rarest availability level of pieces that we affirmatively want to try to request from others soonest ie; our prime targets for requesting rarest pieces -
filePriorityChange
protected volatile long filePriorityChangeevent # of user file priority settings changes -
sequentialDownload
protected volatile int sequentialDownload -
priorityParamChange
private volatile long priorityParamChangelast user parameter settings event # when priority bases were calculated -
priorityFileChange
private volatile long priorityFileChangelast user priority event # when priority bases were calculated -
priorityAvailChange
private volatile long priorityAvailChangelast availability event # when priority bases were calculated -
priorityRTAexists
private boolean priorityRTAexists -
timeLastPriorities
private long timeLastPrioritiestime that base priorities were last computed -
startPriorities
private int[] startPrioritiesthe priority for starting each piece/base priority for resuming -
hasNeededUndonePiece
protected volatile boolean hasNeededUndonePiece -
neededUndonePieceChange
protected volatile long neededUndonePieceChange -
endGameMode
private volatile boolean endGameModeA flag to indicate when we're in endgame mode -
endGameModeAbandoned
private volatile boolean endGameModeAbandoned -
timeEndGameModeEntered
private volatile long timeEndGameModeEntered -
endGameModeChunks
The list of chunks needing to be downloaded (the mechanism change when entering end-game mode) -
endGameModeChunkMap
-
lastProviderRecalcTime
private long lastProviderRecalcTime -
rta_providers
-
provider_piece_rtas
private long[] provider_piece_rtas -
priority_providers
-
provider_piece_priorities
private long[] provider_piece_priorities -
allocate_request_loop_count
private int allocate_request_loop_count -
max_file_priority
private int max_file_priority -
min_file_priority
private int min_file_priority -
reverse_block_order
private boolean reverse_block_order -
global_request_hint
private int[] global_request_hint -
enable_request_hints
private static boolean enable_request_hints -
includeLanPeersInReqLimiting
private static boolean includeLanPeersInReqLimiting -
listeners
-
fileAvailabilities
private volatile float[] fileAvailabilities -
fileAvailabilitiesCalcTime
private volatile long fileAvailabilitiesCalcTime -
forced_pieces
-
firstPiecePriority
protected static volatile boolean firstPiecePriority -
firstPriorityBytes
protected static volatile long firstPriorityBytes -
firstPiecePriorityForce
protected static volatile boolean firstPiecePriorityForce -
completionPriority
protected static volatile boolean completionPriority -
paramPriorityChange
protected static volatile long paramPriorityChangeevent # of user settings controlling priority changes -
dispenser
-
-
Constructor Details
-
PiecePickerImpl
-
-
Method Details
-
getPeerManager
- Specified by:
getPeerManager
in interfacePiecePicker
-
addHavePiece
- Specified by:
addHavePiece
in interfacePiecePicker
-
updateAvailability
public final void updateAvailability()This method will compute the pieces' overall availability (including ourself) and the _globalMinOthers invalid input: '&' _globalAvail- Specified by:
updateAvailability
in interfacePiecePicker
-
recomputeAvailability
private int[] recomputeAvailability() -
getNumberOfPieces
public int getNumberOfPieces()- Specified by:
getNumberOfPieces
in interfacePiecePicker
-
getAvailability
public final int[] getAvailability()- Specified by:
getAvailability
in interfacePiecePicker
-
getAvailability
public final int getAvailability(int pieceNumber) - Specified by:
getAvailability
in interfacePiecePicker
-
getMinAvailability
public final float getMinAvailability()- Specified by:
getMinAvailability
in interfacePiecePicker
-
getMinAvailability
public float getMinAvailability(int fileIndex) - Specified by:
getMinAvailability
in interfacePiecePicker
-
getAvailWentBadTime
public final long getAvailWentBadTime()- Specified by:
getAvailWentBadTime
in interfacePiecePicker
-
getMaxAvailability
public final int getMaxAvailability()- Specified by:
getMaxAvailability
in interfacePiecePicker
-
getAvgAvail
public final float getAvgAvail()- Specified by:
getAvgAvail
in interfacePiecePicker
-
getNbPiecesDone
public int getNbPiecesDone()- Specified by:
getNbPiecesDone
in interfacePiecePicker
-
checkDownloadablePiece
protected final void checkDownloadablePiece()Early-outs when finds a downloadable piece Either way sets hasNeededUndonePiece and neededUndonePieceChange if necessary -
allocateRequests
public final void allocateRequests()one reason requests don't stem from the individual peers is so the connections can be sorted by best uploaders, providing some ooprtunity to download the most important (ie; rarest and/or highest priority) pieces faster and more reliably- Specified by:
allocateRequests
in interfacePiecePicker
-
getNextBlockETAFromNow
-
calcRarestAllowed
private int calcRarestAllowed()Count current global min avail pieces in progress (not counting non-rarest pieces but keep them to compensate high churn, remove completed ones, ignore idle ones)- Returns:
- number of pieces that may be started due to the "rarest first" picking rule
-
syncFilePriorities
private void syncFilePriorities() -
computeBasePriorities
private void computeBasePriorities()This computes the base priority for all pieces that need requesting if there's been any availability change or user priority setting changes since the last call, which will be most of the time since availability changes so dynamically It will change startPriorities[] (unless there was nothing to do) -
findPieceToDownload
- Parameters:
pt
- the PEPeerTransport we're working on- Returns:
- int # of blocks that were requested (0 if no requests were made)
-
findRTAPieceToDownload
protected final boolean findRTAPieceToDownload(PEPeerTransport pt, boolean best_uploader, long best_uploader_next_block_eta) -
getRequestCandidate
This method is the downloading core. It decides, for a given peer, which block should be requested. Here is the overall algorithm : 0. If there a FORCED_PIECE or reserved piece, that will be started/resumed if possible 1. Scan all the active pieces and find the rarest piece (and highest priority among equally rarest) that can possibly be continued by this peer, if any 2. While scanning the active pieces, develop a list of equally highest priority pieces (and equally rarest among those) as candidates for starting a new piece 3. If it can't find any piece, this means all pieces are already downloaded/full requested 4. Returns int[] pieceNumber, blockNumber if a request to be made is found, or null if none could be found- Parameters:
pc
- PEPeerTransport to work with- Returns:
- int with pieceNumberto be requested or -1 if no request could be found
-
getPieceToStart
- Parameters:
startCandidates
- BitFlags of potential candidates to choose from- Returns:
- int the piece number that was chosen to be started. Note it's possible for the chosen piece to have been started already (by another thread). This method considers that potential to not be relevant.
-
hasDownloadablePiece
public final boolean hasDownloadablePiece()- Specified by:
hasDownloadablePiece
in interfacePiecePicker
-
getNeededUndonePieceChange
public final long getNeededUndonePieceChange()- Specified by:
getNeededUndonePieceChange
in interfacePiecePicker
- Returns:
- long value indicated serial number of current count of changes to hasNeededUndonePiece. A method interesting in tracking changes can compare this with a locally stored value to determine if the hasNeededUndonePiece status has changed since the last check.
-
checkEndGameMode
private void checkEndGameMode() -
computeEndGameModeChunks
private void computeEndGameModeChunks() -
isInEndGameMode
public final boolean isInEndGameMode()- Specified by:
isInEndGameMode
in interfacePiecePicker
-
hasEndGameModeBeenAbandoned
public boolean hasEndGameModeBeenAbandoned()- Specified by:
hasEndGameModeBeenAbandoned
in interfacePiecePicker
-
addEndGameChunks
adds every block from the piece to the list of chuncks to be selected for egm requesting- Specified by:
addEndGameChunks
in interfacePiecePicker
- Parameters:
pePiece
-
-
findPieceInEndGameMode
-
removeFromEndGameModeChunks
public final void removeFromEndGameModeChunks(int pieceNumber, int offset) - Specified by:
removeFromEndGameModeChunks
in interfacePiecePicker
-
clearEndGameChunks
public final void clearEndGameChunks()- Specified by:
clearEndGameChunks
in interfacePiecePicker
-
leaveEndGameMode
protected void leaveEndGameMode() -
abandonEndGameMode
protected void abandonEndGameMode() -
computeProviderPriorities
private boolean computeProviderPriorities() -
addRTAProvider
- Specified by:
addRTAProvider
in interfacePiecePicker
-
removeRTAProvider
- Specified by:
removeRTAProvider
in interfacePiecePicker
-
getRTAProviders
- Specified by:
getRTAProviders
in interfacePiecePicker
-
addPriorityProvider
- Specified by:
addPriorityProvider
in interfacePiecePicker
-
removePriorityProvider
- Specified by:
removePriorityProvider
in interfacePiecePicker
-
getPriorityProviders
- Specified by:
getPriorityProviders
in interfacePiecePicker
-
addListener
- Specified by:
addListener
in interfacePiecePicker
-
removeListener
- Specified by:
removeListener
in interfacePiecePicker
-
setForcePiece
public void setForcePiece(int pieceNumber, boolean forced) - Specified by:
setForcePiece
in interfacePiecePicker
-
isForcePiece
public boolean isForcePiece(int pieceNumber) - Specified by:
isForcePiece
in interfacePiecePicker
-
setSequentialDownload
private void setSequentialDownload(int val) -
setSequentialAscendingFrom
public void setSequentialAscendingFrom(int start_piece) - Specified by:
setSequentialAscendingFrom
in interfacePiecePicker
-
setSequentialDescendingFrom
public void setSequentialDescendingFrom(int start_piece) - Specified by:
setSequentialDescendingFrom
in interfacePiecePicker
-
clearSequential
public void clearSequential()- Specified by:
clearSequential
in interfacePiecePicker
-
getSequentialInfo
public int getSequentialInfo()- Specified by:
getSequentialInfo
in interfacePiecePicker
- Returns:
- 0 - inactive; +ve -> ascending from (n-1) -ve -> descending from (-n+1)
-
getEGMInfo
- Specified by:
getEGMInfo
in interfacePiecePicker
-
getEGMRequestCount
public int getEGMRequestCount(int piece_number, int block_number) - Specified by:
getEGMRequestCount
in interfacePiecePicker
-
setGlobalRequestHint
public void setGlobalRequestHint(int piece_number, int start_bytes, int byte_count) - Specified by:
setGlobalRequestHint
in interfacePiecePicker
-
getGlobalRequestHint
public int[] getGlobalRequestHint()- Specified by:
getGlobalRequestHint
in interfacePiecePicker
-
setReverseBlockOrder
public void setReverseBlockOrder(boolean is_reverse) - Specified by:
setReverseBlockOrder
in interfacePiecePicker
-
getReverseBlockOrder
public boolean getReverseBlockOrder()- Specified by:
getReverseBlockOrder
in interfacePiecePicker
-
destroy
public void destroy()- Specified by:
destroy
in interfacePiecePicker
-
getPieceString
- Specified by:
getPieceString
in interfacePiecePicker
-
generateEvidence
- Specified by:
generateEvidence
in interfacePiecePicker
-