Class SpeedLimitMonitor
java.lang.Object
com.biglybt.core.speedmanager.impl.v2.SpeedLimitMonitor
- All Implemented Interfaces:
PSMonitorListener
This class is responsible for re-adjusting the limits used by AutoSpeedV2.
This class will keep track of the "status" (i.e. seeding, downloading)of the
application. It will then re-adjust the MAX limits when it thinks limits
are being reached.
Here are the rules it will use.
#1) When seeding. If the upload is AT_LIMIT for a period of time it will allow
that to adjust upward.
#2) When downloading. If the download is AT_LIMIT for a period of time it will
allow that to adjust upward.
#3) When downloading, if a down-tick is detected and the upload is near a limit,
it will drop the upload limit to 80% of MAX_UPLOAD.
#4) Once that limit is reached it will drop both the upload and download limits together.
#5) Seeding mode is triggered when - download bandwidth at LOW - compared to CAPACITY for 5 minutes continuously.
#6) Download mode is triggered when - download bandwidth reaches MEDIUM - compared to CURRENT_LIMIT for the first time.
Rules #5 and #6 favor downloading over seeding.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private long
private long
private static final long
private boolean
static final String
private long
private SaturatedMode
private SpeedLimitConfidence
private int
private int
private SaturatedMode
private int
private int
private boolean
private boolean
(package private) final PingSpaceMon
private float
(package private) final SpeedLimitListener
(package private) PingSpaceMapper
(package private) PingSpaceMapper
private int
private int
private int
private int
(package private) final LimitControl
private static final long
private final TransferMode
(package private) SpeedManagerPingMapper
static final String
static final String
private long
private SaturatedMode
private int
private SpeedLimitConfidence
private int
private int
private SaturatedMode
private int
static final String
static final String
(package private) boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addToPingMapData
(int lastMetricValue) adjustLimitsToSpec
(int currUploadLimit, int currDownloadLimit) It is likely the user adjusted the "line speed capacity" on the configuration panel.boolean
areSettingsInSpec
(int currUploadLimit, int currDownloadLimit) If the user changes the line capacity settings on the configuration panel and adjustment needs to occur even if the signal is NO-CHANGE-NEEDED.boolean
True if both are at limits.boolean
Are both the upload and download bandwidths usages is low? Otherwise false.boolean
void
betaLogPingMapperEstimates
(String name, SpeedManagerLimitEstimate transEst, boolean hadChockPing, SpeedManagerLimitEstimate permEst, PingSpaceMapper downMode, PingSpaceMapper seedMode) This is a lot of data, but is important debug info.calculateNewUnpinnedLimits
(float signalStrength) private int
calculateUnpinnedStepSize
(int currLimitMax) If setting is less then 100kBytes take 1 kByte steps.private SMUpdate
If a progressive download is currently active.void
Make a decision about unpinning either the upload or download limit.private int
choseBestLimit
(SpeedManagerLimitEstimate estimate, int currMaxLimit, SpeedLimitConfidence currConf) After a test is complete determine how condifent the client should be in it based on how different it is from the previous result.Call this method to end the limit testing.endLimitTesting
(int downloadCapacityGuess, int uploadCapacityGuess) int
int
int
int
int
int
boolean
Should return true if had a recent chocking ping.void
void
initPingSpaceMap
(int maxGoodPing, int minBadPing) boolean
boolean
Return true if we are confidence testing the limits.boolean
boolean
Determine if we have low confidence in this limit.boolean
private boolean
The criteria for download being unlimited is if the ConfigPanel has the "download == 0 " && "type==fixed"boolean
boolean
True if the upload bandwidth usage is HIGH or AT_LIMIT.boolean
boolean
protected void
void
Just log this data until we decide if it is useful.private void
Log debug info needed during beta period.private void
logPMData
(int oRate, SpeedLimitConfidence oConf, int nRate, float nConf, String type) void
modifyLimits
(float signalStrength, float multiple, int currUpLimit, int currDownLimit) Does the same as createNewLimit except it drops the upload rate first when in download mode.void
notifyDownload
(SpeedManagerLimitEstimate estimate) void
If we have a down-tick signal then resetTimer all the counters for increasing the limits.void
notifyUpload
(SpeedManagerLimitEstimate estimate) rampTestingLimit
(int uploadLimit, int downloadLimit) Ramp the upload and download rates higher, so ping-times are relevant.void
replaces - updateFromCOConfigManager()void
(package private) void
(package private) void
resetPinSearch
(SpeedManagerLimitEstimate estimate) void
void
setCurrentTransferRates
(int downRate, int upRate) void
setDownloadBandwidthMode
(int rate, int limit) void
setDownloadLimitSettingMode
(int currLimit) void
setRefLimits
(int uploadMax, int downloadMax) void
setRefLimits
(SpeedManagerLimitEstimate estUp, SpeedManagerLimitEstimate estDown) Make some choices about how usable the limits are before passing them on.void
setUploadBandwidthMode
(int rate, int limit) void
setUploadLimitSettingMode
(int currLimit) startLimitTesting
(int currUploadLimit, int currDownloadLimit) Call this method to start the limit testing.private void
void
void
void
updateLimitTestingData
(int downloadRate, int uploadRate) void
updateLimitTestingPing
(float lastMetric) New metric from the PingMapper is value between -1.0 and +1.0f.void
updateLimitTestingPing
(int lastMetric) Convert raw ping value to new metric.void
Splitting the limits our from other setting for SpeedManagerAlgorithmTI.void
-
Field Details
-
uploadLimitMax
private int uploadLimitMax -
uploadLimitMin
private int uploadLimitMin -
downloadLimitMax
private int downloadLimitMax -
downloadLimitMin
private int downloadLimitMin -
transferMode
-
uploadBandwidthStatus
-
downloadBandwidthStatus
-
uploadLimitSettingStatus
-
downloadLimitSettingStatus
-
uploadLimitConf
-
downloadLimitConf
-
clLastIncreaseTime
private long clLastIncreaseTime -
clFirstBadPingTime
private long clFirstBadPingTime -
currTestDone
private boolean currTestDone -
beginLimitTest
private boolean beginLimitTest -
highestUploadRate
private int highestUploadRate -
highestDownloadRate
private int highestDownloadRate -
preTestUploadCapacity
private int preTestUploadCapacity -
preTestUploadLimit
private int preTestUploadLimit -
preTestDownloadCapacity
private int preTestDownloadCapacity -
preTestDownloadLimit
private int preTestDownloadLimit -
UPLOAD_CONF_LIMIT_SETTING
- See Also:
-
DOWNLOAD_CONF_LIMIT_SETTING
- See Also:
-
UPLOAD_CHOKE_PING_COUNT
- See Also:
-
CONF_LIMIT_TEST_LENGTH
private static final long CONF_LIMIT_TEST_LENGTH- See Also:
-
isUploadMaxPinned
private boolean isUploadMaxPinned -
isDownloadMaxPinned
private boolean isDownloadMaxPinned -
uploadAtLimitStartTime
private long uploadAtLimitStartTime -
downloadAtLimitStartTime
private long downloadAtLimitStartTime -
uploadChokePingCount
private int uploadChokePingCount -
uploadPinCounter
private int uploadPinCounter -
TIME_AT_LIMIT_BEFORE_UNPINNING
private static final long TIME_AT_LIMIT_BEFORE_UNPINNING- See Also:
-
USED_UPLOAD_CAPACITY_DOWNLOAD_MODE
- See Also:
-
USED_UPLOAD_CAPACITY_SEEDING_MODE
- See Also:
-
percentUploadCapacityDownloadMode
private float percentUploadCapacityDownloadMode -
pingMapOfDownloadMode
PingSpaceMapper pingMapOfDownloadMode -
pingMapOfSeedingMode
PingSpaceMapper pingMapOfSeedingMode -
useVariancePingMap
boolean useVariancePingMap -
transientPingMap
SpeedManagerPingMapper transientPingMap -
longTermMonitor
-
slider
-
persistentMapListener
-
-
Constructor Details
-
SpeedLimitMonitor
-
-
Method Details
-
updateSettingsFromCOConfigManager
public void updateSettingsFromCOConfigManager()Splitting the limits our from other setting for SpeedManagerAlgorithmTI. -
updateFromCOConfigManager
public void updateFromCOConfigManager() -
readFromPersistentMap
public void readFromPersistentMap()replaces - updateFromCOConfigManager() -
saveToCOConfiguration
public void saveToCOConfiguration() -
logPMData
-
logPMDataEx
public void logPMDataEx() -
isSettingDownloadUnlimited
private boolean isSettingDownloadUnlimited()The criteria for download being unlimited is if the ConfigPanel has the "download == 0 " && "type==fixed"- Returns:
- - true
-
setDownloadBandwidthMode
public void setDownloadBandwidthMode(int rate, int limit) -
setUploadBandwidthMode
public void setUploadBandwidthMode(int rate, int limit) -
setDownloadLimitSettingMode
public void setDownloadLimitSettingMode(int currLimit) -
setUploadLimitSettingMode
public void setUploadLimitSettingMode(int currLimit) -
getUploadMaxLimit
public int getUploadMaxLimit() -
getDownloadMaxLimit
public int getDownloadMaxLimit() -
getUploadMinLimit
public int getUploadMinLimit() -
getDownloadMinLimit
public int getDownloadMinLimit() -
getUploadConfidence
-
getDownloadConfidence
-
getDownloadBandwidthMode
-
getUploadBandwidthMode
-
getDownloadLimitSettingMode
-
getUploadLimitSettingMode
-
updateTransferMode
public void updateTransferMode() -
getTransferModeAsString
-
getTransferMode
-
bandwidthUsageLow
public boolean bandwidthUsageLow()Are both the upload and download bandwidths usages is low? Otherwise false.- Returns:
- -
-
bandwidthUsageMedium
public boolean bandwidthUsageMedium()- Returns:
- -
-
bandwidthUsageAtLimit
public boolean bandwidthUsageAtLimit()True if both are at limits.- Returns:
- - true only if both the upload and download usages are at the limits.
-
isUploadBandwidthUsageHigh
public boolean isUploadBandwidthUsageHigh()True if the upload bandwidth usage is HIGH or AT_LIMIT.- Returns:
- -
-
isEitherLimitUnpinned
public boolean isEitherLimitUnpinned() -
modifyLimits
public SMUpdate modifyLimits(float signalStrength, float multiple, int currUpLimit, int currDownLimit) Does the same as createNewLimit except it drops the upload rate first when in download mode.- Parameters:
signalStrength
- -multiple
- -currUpLimit
- -currDownLimit
- -- Returns:
- -
-
checkActiveProgressiveDownloadLimit
If a progressive download is currently active. Then the download limit should not be allowed to go below that limit, regardless of anything else.- Parameters:
update
- -- Returns:
- -
-
logPinningInfo
private void logPinningInfo()Log debug info needed during beta period. -
calculateNewUnpinnedLimits
- Parameters:
signalStrength
- -- Returns:
- -
-
calculateUnpinnedStepSize
private int calculateUnpinnedStepSize(int currLimitMax) If setting is less then 100kBytes take 1 kByte steps. If setting is less then 500kBytes take 5 kByte steps. if setting is larger take 10 kBytes steps.- Parameters:
currLimitMax
- - current limit setting.- Returns:
- - set size for next change.
-
checkForUnpinningCondition
public void checkForUnpinningCondition()Make a decision about unpinning either the upload or download limit. This is based on the time we are saturating the limit without a down-tick signal. -
notifyOfDownSignal
public void notifyOfDownSignal()If we have a down-tick signal then resetTimer all the counters for increasing the limits. -
resetPinSearch
void resetPinSearch() -
resetPinSearch
-
isConfTestingLimits
public boolean isConfTestingLimits()Return true if we are confidence testing the limits.- Returns:
- - SMUpdate
-
isDownloadConfidenceLow
public boolean isDownloadConfidenceLow()Determine if we have low confidence in this limit.- Returns:
- - true if the confidence setting is LOW or NONE. Otherwise return true.
-
isUploadConfidenceLow
public boolean isUploadConfidenceLow() -
isDownloadConfidenceAbsolute
public boolean isDownloadConfidenceAbsolute() -
isUploadConfidenceAbsolute
public boolean isUploadConfidenceAbsolute() -
updateLimitTestingData
public void updateLimitTestingData(int downloadRate, int uploadRate) - Parameters:
downloadRate
- - currentUploadRate in bytes/secuploadRate
- - currentUploadRate in bytes/sec
-
updateLimitTestingPing
public void updateLimitTestingPing(int lastMetric) Convert raw ping value to new metric.- Parameters:
lastMetric
- -
-
updateLimitTestingPing
public void updateLimitTestingPing(float lastMetric) New metric from the PingMapper is value between -1.0 and +1.0f.- Parameters:
lastMetric
- -
-
startLimitTesting
Call this method to start the limit testing.- Parameters:
currUploadLimit
- -currDownloadLimit
- -- Returns:
- - SMUpdate
-
rampTestingLimit
Ramp the upload and download rates higher, so ping-times are relevant.- Parameters:
uploadLimit
- -downloadLimit
- -- Returns:
- -
-
triggerLimitTestingFlag
public void triggerLimitTestingFlag() -
isStartLimitTestFlagSet
public boolean isStartLimitTestFlagSet() -
isConfLimitTestFinished
public boolean isConfLimitTestFinished() -
endLimitTesting
-
endLimitTesting
Call this method to end the limit testing.- Returns:
- - SMUpdate
-
determineConfidenceLevel
After a test is complete determine how condifent the client should be in it based on how different it is from the previous result. If the new result is within 20% of the old result then give it a MED. If it is great then give it a LOW.- Returns:
- - what the new confidence interval should be.
-
areSettingsInSpec
public boolean areSettingsInSpec(int currUploadLimit, int currDownloadLimit) If the user changes the line capacity settings on the configuration panel and adjustment needs to occur even if the signal is NO-CHANGE-NEEDED. Test for that condition here.- Parameters:
currUploadLimit
- - reported upload capacity from the adaptercurrDownloadLimit
- - reported download capacity from the adapter.- Returns:
- - true if the "capacity" is lower then the current limit.
-
choseBestLimit
private int choseBestLimit(SpeedManagerLimitEstimate estimate, int currMaxLimit, SpeedLimitConfidence currConf) -
setRefLimits
Make some choices about how usable the limits are before passing them on.- Parameters:
estUp
- -estDown
- -
-
setRefLimits
public void setRefLimits(int uploadMax, int downloadMax) -
adjustLimitsToSpec
It is likely the user adjusted the "line speed capacity" on the configuration panel. We need to adjust the current limits down to adjust.- Parameters:
currUploadLimit
- -currDownloadLimit
- -- Returns:
- - Updates as needed.
-
log
-
initPingSpaceMap
public void initPingSpaceMap(int maxGoodPing, int minBadPing) -
initPingSpaceMap
public void initPingSpaceMap() -
betaLogPingMapperEstimates
public void betaLogPingMapperEstimates(String name, SpeedManagerLimitEstimate transEst, boolean hadChockPing, SpeedManagerLimitEstimate permEst, PingSpaceMapper downMode, PingSpaceMapper seedMode) This is a lot of data, but is important debug info.- Parameters:
name
- -transEst
- -hadChockPing
- -permEst
- -downMode
- -seedMode
- -
-
guessDownloadLimit
public int guessDownloadLimit() -
guessUploadLimit
public int guessUploadLimit() -
hadChockingPing
public boolean hadChockingPing()Should return true if had a recent chocking ping.- Returns:
- - true if
-
logPingMapData
public void logPingMapData()Just log this data until we decide if it is useful. -
setCurrentTransferRates
public void setCurrentTransferRates(int downRate, int upRate) -
resetPingSpace
public void resetPingSpace() -
addToPingMapData
public void addToPingMapData(int lastMetricValue) -
notifyUpload
- Specified by:
notifyUpload
in interfacePSMonitorListener
-
notifyDownload
- Specified by:
notifyDownload
in interfacePSMonitorListener
-
tempLogEstimate
-