Class SpeedLimitMonitor
- java.lang.Object
-
- com.biglybt.core.speedmanager.impl.v2.SpeedLimitMonitor
-
- All Implemented Interfaces:
PSMonitorListener
public class SpeedLimitMonitor extends java.lang.Object implements 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 continously. #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
-
Constructor Summary
Constructors Constructor Description SpeedLimitMonitor(SpeedManager sm)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addToPingMapData(int lastMetricValue)
SMUpdate
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
bandwidthUsageAtLimit()
True if both are at limits.boolean
bandwidthUsageLow()
Are both the upload and download bandwidths usages is low? Otherwise false.boolean
bandwidthUsageMedium()
void
betaLogPingMapperEstimates(java.lang.String name, SpeedManagerLimitEstimate transEst, boolean hadChockPing, SpeedManagerLimitEstimate permEst, PingSpaceMapper downMode, PingSpaceMapper seedMode)
This is a lot of data, but is important debug info.SMUpdate
calculateNewUnpinnedLimits(float signalStrength)
private int
calculateUnpinnedStepSize(int currLimitMax)
If setting is less then 100kBytes take 1 kByte steps.private SMUpdate
checkActiveProgressiveDownloadLimit(SMUpdate update)
If a progressive download is currently active.void
checkForUnpinningCondition()
Make a decision about unpinning either the upload or download limit.private int
choseBestLimit(SpeedManagerLimitEstimate estimate, int currMaxLimit, SpeedLimitConfidence currConf)
SpeedLimitConfidence
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.SMUpdate
endLimitTesting()
Call this method to end the limit testing.SMUpdate
endLimitTesting(int downloadCapacityGuess, int uploadCapacityGuess)
SaturatedMode
getDownloadBandwidthMode()
java.lang.String
getDownloadConfidence()
SaturatedMode
getDownloadLimitSettingMode()
int
getDownloadMaxLimit()
int
getDownloadMinLimit()
TransferMode
getTransferMode()
java.lang.String
getTransferModeAsString()
SaturatedMode
getUploadBandwidthMode()
java.lang.String
getUploadConfidence()
SaturatedMode
getUploadLimitSettingMode()
int
getUploadMaxLimit()
int
getUploadMinLimit()
int
guessDownloadLimit()
int
guessUploadLimit()
boolean
hadChockingPing()
Should return true if had a recent chocking ping.void
initPingSpaceMap()
void
initPingSpaceMap(int maxGoodPing, int minBadPing)
boolean
isConfLimitTestFinished()
boolean
isConfTestingLimits()
Return true if we are confidence testing the limits.boolean
isDownloadConfidenceAbsolute()
boolean
isDownloadConfidenceLow()
Determine if we have low confidence in this limit.boolean
isEitherLimitUnpinned()
private boolean
isSettingDownloadUnlimited()
The criteria for download being unlimited is if the ConfigPanel has the "download == 0 " && "type==fixed"boolean
isStartLimitTestFlagSet()
boolean
isUploadBandwidthUsageHigh()
True if the upload bandwidth usage is HIGH or AT_LIMIT.boolean
isUploadConfidenceAbsolute()
boolean
isUploadConfidenceLow()
protected void
log(java.lang.String str)
void
logPingMapData()
Just log this data until we decide if it is useful.private void
logPinningInfo()
Log debug info needed during beta period.private void
logPMData(int oRate, SpeedLimitConfidence oConf, int nRate, float nConf, java.lang.String type)
void
logPMDataEx()
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.void
notifyDownload(SpeedManagerLimitEstimate estimate)
void
notifyOfDownSignal()
If we have a down-tick signal then resetTimer all the counters for increasing the limits.void
notifyUpload(SpeedManagerLimitEstimate estimate)
SMUpdate
rampTestingLimit(int uploadLimit, int downloadLimit)
Ramp the upload and download rates higher, so ping-times are relevant.void
readFromPersistentMap()
replaces - updateFromCOConfigManager()void
resetPingSpace()
(package private) void
resetPinSearch()
(package private) void
resetPinSearch(SpeedManagerLimitEstimate estimate)
void
saveToCOConfiguration()
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)
SMUpdate
startLimitTesting(int currUploadLimit, int currDownloadLimit)
Call this method to start the limit testing.private void
tempLogEstimate(SpeedManagerLimitEstimate est)
void
triggerLimitTestingFlag()
void
updateFromCOConfigManager()
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
updateSettingsFromCOConfigManager()
Splitting the limits our from other setting for SpeedManagerAlgorithmTI.void
updateTransferMode()
-
-
-
Field Detail
-
uploadLimitMax
private int uploadLimitMax
-
uploadLimitMin
private int uploadLimitMin
-
downloadLimitMax
private int downloadLimitMax
-
downloadLimitMin
private int downloadLimitMin
-
transferMode
private final TransferMode transferMode
-
uploadBandwidthStatus
private SaturatedMode uploadBandwidthStatus
-
downloadBandwidthStatus
private SaturatedMode downloadBandwidthStatus
-
uploadLimitSettingStatus
private SaturatedMode uploadLimitSettingStatus
-
downloadLimitSettingStatus
private SaturatedMode downloadLimitSettingStatus
-
uploadLimitConf
private SpeedLimitConfidence uploadLimitConf
-
downloadLimitConf
private SpeedLimitConfidence 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
public static final java.lang.String UPLOAD_CONF_LIMIT_SETTING
- See Also:
- Constant Field Values
-
DOWNLOAD_CONF_LIMIT_SETTING
public static final java.lang.String DOWNLOAD_CONF_LIMIT_SETTING
- See Also:
- Constant Field Values
-
UPLOAD_CHOKE_PING_COUNT
public static final java.lang.String UPLOAD_CHOKE_PING_COUNT
- See Also:
- Constant Field Values
-
CONF_LIMIT_TEST_LENGTH
private static final long CONF_LIMIT_TEST_LENGTH
- See Also:
- Constant Field Values
-
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:
- Constant Field Values
-
USED_UPLOAD_CAPACITY_DOWNLOAD_MODE
public static final java.lang.String USED_UPLOAD_CAPACITY_DOWNLOAD_MODE
- See Also:
- Constant Field Values
-
USED_UPLOAD_CAPACITY_SEEDING_MODE
public static final java.lang.String USED_UPLOAD_CAPACITY_SEEDING_MODE
- See Also:
- Constant Field Values
-
percentUploadCapacityDownloadMode
private float percentUploadCapacityDownloadMode
-
pingMapOfDownloadMode
PingSpaceMapper pingMapOfDownloadMode
-
pingMapOfSeedingMode
PingSpaceMapper pingMapOfSeedingMode
-
useVariancePingMap
boolean useVariancePingMap
-
transientPingMap
SpeedManagerPingMapper transientPingMap
-
longTermMonitor
final PingSpaceMon longTermMonitor
-
slider
final LimitControl slider
-
persistentMapListener
final SpeedLimitListener persistentMapListener
-
-
Constructor Detail
-
SpeedLimitMonitor
public SpeedLimitMonitor(SpeedManager sm)
-
-
Method Detail
-
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
private void logPMData(int oRate, SpeedLimitConfidence oConf, int nRate, float nConf, java.lang.String type)
-
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
public java.lang.String getUploadConfidence()
-
getDownloadConfidence
public java.lang.String getDownloadConfidence()
-
getDownloadBandwidthMode
public SaturatedMode getDownloadBandwidthMode()
-
getUploadBandwidthMode
public SaturatedMode getUploadBandwidthMode()
-
getDownloadLimitSettingMode
public SaturatedMode getDownloadLimitSettingMode()
-
getUploadLimitSettingMode
public SaturatedMode getUploadLimitSettingMode()
-
updateTransferMode
public void updateTransferMode()
-
getTransferModeAsString
public java.lang.String getTransferModeAsString()
-
getTransferMode
public TransferMode 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
private SMUpdate checkActiveProgressiveDownloadLimit(SMUpdate update)
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
public SMUpdate calculateNewUnpinnedLimits(float signalStrength)
- 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
void resetPinSearch(SpeedManagerLimitEstimate estimate)
-
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
public SMUpdate startLimitTesting(int currUploadLimit, int currDownloadLimit)
Call this method to start the limit testing.- Parameters:
currUploadLimit
- -currDownloadLimit
- -- Returns:
- - SMUpdate
-
rampTestingLimit
public SMUpdate rampTestingLimit(int uploadLimit, int downloadLimit)
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
public SMUpdate endLimitTesting(int downloadCapacityGuess, int uploadCapacityGuess)
-
endLimitTesting
public SMUpdate endLimitTesting()
Call this method to end the limit testing.- Returns:
- - SMUpdate
-
determineConfidenceLevel
public SpeedLimitConfidence 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
public void setRefLimits(SpeedManagerLimitEstimate estUp, SpeedManagerLimitEstimate estDown)
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
public SMUpdate adjustLimitsToSpec(int currUploadLimit, int currDownloadLimit)
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
protected void log(java.lang.String str)
-
initPingSpaceMap
public void initPingSpaceMap(int maxGoodPing, int minBadPing)
-
initPingSpaceMap
public void initPingSpaceMap()
-
betaLogPingMapperEstimates
public void betaLogPingMapperEstimates(java.lang.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
public void notifyUpload(SpeedManagerLimitEstimate estimate)
- Specified by:
notifyUpload
in interfacePSMonitorListener
-
notifyDownload
public void notifyDownload(SpeedManagerLimitEstimate estimate)
- Specified by:
notifyDownload
in interfacePSMonitorListener
-
tempLogEstimate
private void tempLogEstimate(SpeedManagerLimitEstimate est)
-
-