com.aelitis.azureus.core.speedmanager.impl.v2
Class SpeedLimitMonitor

java.lang.Object
  extended by com.aelitis.azureus.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
static java.lang.String DOWNLOAD_CONF_LIMIT_SETTING
           
static java.lang.String UPLOAD_CHOKE_PING_COUNT
           
static java.lang.String UPLOAD_CONF_LIMIT_SETTING
           
static java.lang.String USED_UPLOAD_CAPACITY_DOWNLOAD_MODE
           
static java.lang.String USED_UPLOAD_CAPACITY_SEEDING_MODE
           
 
Constructor Summary
SpeedLimitMonitor(SpeedManager sm)
           
 
Method Summary
 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)
           
 void checkForUnpinningCondition()
          Make a decision about unpinning either the upload or download limit.
 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()
           
 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.
 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()
           
 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.
 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()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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

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
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()

logPMDataEx

public void logPMDataEx()

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:
-

calculateNewUnpinnedLimits

public SMUpdate calculateNewUnpinnedLimits(float signalStrength)
Parameters:
signalStrength - -
Returns:
-

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.


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/sec
uploadRate - - 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 adapter
currDownloadLimit - - reported download capacity from the adapter.
Returns:
- true if the "capacity" is lower then the current limit.

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 interface PSMonitorListener

notifyDownload

public void notifyDownload(SpeedManagerLimitEstimate estimate)
Specified by:
notifyDownload in interface PSMonitorListener