Search in sources :

Example 16 with SpeedManagerLimitEstimate

use of com.biglybt.core.speedmanager.SpeedManagerLimitEstimate in project BiglyBT by BiglySoftware.

the class PingSpaceMon method getUploadEstCapacity.

// getUploadLimit
public static SpeedManagerLimitEstimate getUploadEstCapacity() {
    try {
        SMInstance pm = SMInstance.getInstance();
        SpeedManagerAlgorithmProviderAdapter adapter = pm.getAdapter();
        SpeedManager sm = adapter.getSpeedManager();
        SpeedManagerLimitEstimate upEstCapacity = sm.getEstimatedUploadCapacityBytesPerSec();
        return upEstCapacity;
    } catch (Throwable t) {
        // log this event and
        SpeedManagerLogger.log(t.toString());
        t.printStackTrace();
        // something to return 1 and -1.0f results.
        return new DefaultLimitEstimate();
    }
}
Also used : SpeedManager(com.biglybt.core.speedmanager.SpeedManager) SpeedManagerAlgorithmProviderAdapter(com.biglybt.core.speedmanager.impl.SpeedManagerAlgorithmProviderAdapter) SpeedManagerLimitEstimate(com.biglybt.core.speedmanager.SpeedManagerLimitEstimate)

Example 17 with SpeedManagerLimitEstimate

use of com.biglybt.core.speedmanager.SpeedManagerLimitEstimate in project BiglyBT by BiglySoftware.

the class PingSpaceMon method getUploadLimit.

/**
 * Get the current estimated upload limit from the ping mapper.
 * @param - true if the long-term persistent result should be used.
 * @return - SpeedManagerLimitEstimate.
 */
public static SpeedManagerLimitEstimate getUploadLimit(boolean persistent) {
    try {
        SMInstance pm = SMInstance.getInstance();
        SpeedManagerAlgorithmProviderAdapter adapter = pm.getAdapter();
        SpeedManagerPingMapper persistentMap = adapter.getPingMapper();
        SpeedManagerLimitEstimate upEst = persistentMap.getEstimatedUploadLimit(true);
        return upEst;
    } catch (Throwable t) {
        // log this event and
        SpeedManagerLogger.log(t.toString());
        t.printStackTrace();
        // something to return 1 and -1.0f results.
        return new DefaultLimitEstimate();
    }
}
Also used : SpeedManagerAlgorithmProviderAdapter(com.biglybt.core.speedmanager.impl.SpeedManagerAlgorithmProviderAdapter) SpeedManagerLimitEstimate(com.biglybt.core.speedmanager.SpeedManagerLimitEstimate) SpeedManagerPingMapper(com.biglybt.core.speedmanager.SpeedManagerPingMapper)

Example 18 with SpeedManagerLimitEstimate

use of com.biglybt.core.speedmanager.SpeedManagerLimitEstimate in project BiglyBT by BiglySoftware.

the class SpeedManagerPingMapperImpl method main.

public static void main(String[] args) {
    SpeedManagerPingMapperImpl pm = new SpeedManagerPingMapperImpl(null, "test", 100, true, false);
    Random rand = new Random();
    int[][] phases = { { 50, 0, 100000, 50 }, { 50, 100000, 200000, 200 }, { 50, 50000, 50000, 200 }, { 50, 0, 100000, 50 } };
    for (int i = 0; i < phases.length; i++) {
        int[] phase = phases[i];
        System.out.println("**** phase " + i);
        for (int j = 0; j < phase[0]; j++) {
            int x_base = phase[1];
            int x_var = phase[2];
            int r = phase[3];
            pm.addPing(x_base + rand.nextInt(x_var), x_base + rand.nextInt(x_var), rand.nextInt(r), false);
            SpeedManagerLimitEstimate up = pm.getEstimatedUploadLimit(false);
            SpeedManagerLimitEstimate down = pm.getEstimatedDownloadLimit(false);
            if (up != null && down != null) {
                System.out.println(up.getString() + "," + down.getString());
            }
        }
    }
}
Also used : SpeedManagerLimitEstimate(com.biglybt.core.speedmanager.SpeedManagerLimitEstimate)

Example 19 with SpeedManagerLimitEstimate

use of com.biglybt.core.speedmanager.SpeedManagerLimitEstimate in project BiglyBT by BiglySoftware.

the class DownloadManagerRateController method update.

static void update() {
    tick_count++;
    if ((!enable_limit_handling) || pm_map.size() == 0 || NetworkManager.isSeedingOnlyUploadRate() || NetworkManager.getMaxUploadRateBPSNormal() != 0 || core == null || speed_manager == null || speed_manager.getSpeedTester() == null) {
        rate_limit = 0;
        return;
    }
    int num_complete = 0;
    int num_incomplete = 0;
    int num_interesting = 0;
    int i_up_total = 0;
    int c_up_total = 0;
    long mono_now = SystemTime.getMonotonousTime();
    for (Map.Entry<PEPeerManager, PMState> entry : pm_map.entrySet()) {
        PEPeerManager pm = entry.getKey();
        PMState state = entry.getValue();
        boolean is_complete = !pm.hasDownloadablePiece();
        PEPeerManagerStats pm_stats = pm.getStats();
        long up_bytes = pm_stats.getTotalDataBytesSentNoLan() + pm_stats.getTotalProtocolBytesSentNoLan();
        long diff = state.setBytesUp(up_bytes);
        if (is_complete) {
            num_complete++;
            c_up_total += diff;
        } else {
            num_incomplete++;
            i_up_total += diff;
            if (state.isInteresting(mono_now)) {
                num_interesting++;
            }
        }
        if (state.isComplete() != is_complete) {
            if (is_complete) {
                pm.addRateLimiter(limiter, true);
            } else {
                pm.removeRateLimiter(limiter, true);
            }
            state.setComplete(is_complete);
        }
    }
    if (num_incomplete == 0 || num_complete == 0 || num_interesting == 0) {
        rate_limit = 0;
        return;
    }
    boolean skipped_tick = false;
    if (last_tick_processed != tick_count - 1) {
        pm_last_bad_limit = 0;
        latest_choke = 0;
        wait_until_tick = 0;
        ticks_to_sample_start = 0;
        sample_num = 0;
        incomplete_samples = 0;
        complete_samples = 0;
        skipped_tick = true;
    }
    last_tick_processed = tick_count;
    if (skipped_tick || tick_count < wait_until_tick) {
        return;
    }
    try {
        long real_now = SystemTime.getCurrentTime();
        SpeedManagerPingMapper mapper = speed_manager.getActiveMapper();
        if (rate_limit == 0) {
            rate_limit = speed_manager.getEstimatedUploadCapacityBytesPerSec().getBytesPerSec();
            if (rate_limit == 0) {
                rate_limit = DEFAULT_UP_LIMIT;
            }
        }
        SpeedManagerLimitEstimate last_bad = mapper.getLastBadUploadLimit();
        if (last_bad != null) {
            int last_bad_limit = last_bad.getBytesPerSec();
            if (last_bad_limit != pm_last_bad_limit) {
                pm_last_bad_limit = last_bad_limit;
                SpeedManagerLimitEstimate[] bad_ups = mapper.getBadUploadHistory();
                int total = last_bad.getBytesPerSec();
                int count = 1;
                for (SpeedManagerLimitEstimate bad : bad_ups) {
                    long t = bad.getWhen();
                    if (real_now - t <= 30 * 1000 && bad.getBytesPerSec() != last_bad_limit) {
                        total += bad.getBytesPerSec();
                        count++;
                    }
                }
                latest_choke = total / count;
                int new_rate_limit;
                if (rate_limit == 0) {
                    new_rate_limit = latest_choke / 2;
                } else {
                    new_rate_limit = rate_limit / 2;
                }
                if (new_rate_limit < slack_bytes_per_sec) {
                    new_rate_limit = slack_bytes_per_sec;
                }
                rate_limit = new_rate_limit;
                wait_until_tick = tick_count + WAIT_AFTER_CHOKE_TICKS;
                ticks_to_sample_start = 0;
                sample_num = 0;
                complete_samples = 0;
                incomplete_samples = 0;
                last_rate_limit = 0;
                return;
            }
        }
        if (ticks_to_sample_start > 0) {
            ticks_to_sample_start--;
        } else if (sample_num < SAMPLE_COUNT) {
            complete_samples += c_up_total;
            incomplete_samples += i_up_total;
            sample_num++;
        } else {
            double incomplete_average = incomplete_samples / SAMPLE_COUNT;
            double complete_average = complete_samples / SAMPLE_COUNT;
            double overall_average = (complete_samples + incomplete_samples) / SAMPLE_COUNT;
            int action = -1;
            try {
                if (last_rate_limit == 0) {
                    action = 1;
                } else {
                    double overall_change = overall_average - last_overall_average;
                    if (overall_change < 0) {
                        if (rate_limit < last_rate_limit) {
                            // System.out.println( "average decreased" );
                            action = 1;
                        } else {
                            action = 0;
                        }
                    } else {
                        double last_ratio = last_incomplete_average / last_complete_average;
                        double ratio = incomplete_average / complete_average;
                        if (rate_limit < last_rate_limit && ratio >= last_ratio) {
                            action = -1;
                        } else if (rate_limit > last_rate_limit && ratio <= last_ratio) {
                            double i_up_change = incomplete_average - last_incomplete_average;
                            if (i_up_change >= 1024) {
                                action = -1;
                            } else {
                                action = 1;
                            }
                        } else {
                            action = 1;
                        }
                    }
                }
            } finally {
                int new_rate_limit;
                if (action > 0) {
                    int ceiling = latest_choke == 0 ? DEFAULT_UP_LIMIT : latest_choke;
                    int diff = (ceiling - rate_limit) / 4;
                    if (diff > MAX_UP_DIFF) {
                        diff = MAX_UP_DIFF;
                    } else if (diff < MIN_DIFF) {
                        diff = MIN_DIFF;
                    }
                    new_rate_limit = rate_limit + diff;
                    if (new_rate_limit > 100 * 1024 * 1024) {
                        new_rate_limit = 100 * 1024 * 1024;
                    }
                } else if (action < 0) {
                    int diff = rate_limit / 5;
                    if (diff > MAX_DOWN_DIFF) {
                        diff = MAX_DOWN_DIFF;
                    } else if (diff < MIN_DIFF) {
                        diff = MIN_DIFF;
                    }
                    new_rate_limit = rate_limit - diff;
                    if (new_rate_limit < slack_bytes_per_sec) {
                        new_rate_limit = slack_bytes_per_sec;
                    }
                } else {
                    new_rate_limit = rate_limit;
                }
                last_rate_limit = rate_limit;
                last_overall_average = overall_average;
                last_complete_average = complete_average;
                last_incomplete_average = incomplete_average;
                rate_limit = new_rate_limit;
                sample_num = 0;
                complete_samples = 0;
                incomplete_samples = 0;
            }
        }
    } finally {
    // System.out.println( "rate=" + DisplayFormatters.formatByteCountToKiBEtcPerSec( rate_limit ) + ", last_choke=" + latest_choke );
    }
}
Also used : SpeedManagerLimitEstimate(com.biglybt.core.speedmanager.SpeedManagerLimitEstimate) PEPeerManagerStats(com.biglybt.core.peer.PEPeerManagerStats) SpeedManagerPingMapper(com.biglybt.core.speedmanager.SpeedManagerPingMapper) PEPeerManager(com.biglybt.core.peer.PEPeerManager) HashMap(java.util.HashMap) Map(java.util.Map)

Example 20 with SpeedManagerLimitEstimate

use of com.biglybt.core.speedmanager.SpeedManagerLimitEstimate in project BiglyBT by BiglySoftware.

the class SpeedTestSetLimitPanel method setDefaultConfidenceLevelEx.

// 
/**
 * @param transferRateKBPS -
 * @param testRan -
 * @param isUpload -
 * @param values -
 * @return - index of dropdown that matches or -1 to indicate no match.
 */
private int setDefaultConfidenceLevelEx(int transferRateKBPS, boolean testRan, boolean isUpload, String[] values) {
    float retValType;
    SpeedManagerLimitEstimate est;
    if (isUpload) {
        est = speedManager.getEstimatedUploadCapacityBytesPerSec();
    } else {
        est = speedManager.getEstimatedDownloadCapacityBytesPerSec();
    }
    float originalEstType = est.getEstimateType();
    // if it was previous Fixed leave it alone.
    if (originalEstType == SpeedManagerLimitEstimate.TYPE_MANUAL) {
        retValType = originalEstType;
    } else if (!testRan) {
        // if no test was run leave then confidence level alone.
        retValType = originalEstType;
    } else if (isUpload) {
        // Since cable modems can burst data, need to downgrade rating for uploads (unfortunately)
        retValType = SpeedManagerLimitEstimate.TYPE_ESTIMATED;
    } else if (transferRateKBPS < 550 && transferRateKBPS > 450) {
        retValType = SpeedManagerLimitEstimate.TYPE_ESTIMATED;
    } else {
        // Otherwise we can rate result as measured.
        retValType = SpeedManagerLimitEstimate.TYPE_MEASURED;
    }
    String cType = helper.typeToText(retValType);
    // find the index for this string.
    if (cType == null) {
        return -1;
    }
    for (int i = 0; i < values.length; i++) {
        if (cType.equalsIgnoreCase(values[i])) {
            return i;
        }
    }
    return -1;
}
Also used : SpeedManagerLimitEstimate(com.biglybt.core.speedmanager.SpeedManagerLimitEstimate)

Aggregations

SpeedManagerLimitEstimate (com.biglybt.core.speedmanager.SpeedManagerLimitEstimate)22 SpeedManagerAlgorithmProviderAdapter (com.biglybt.core.speedmanager.impl.SpeedManagerAlgorithmProviderAdapter)9 SpeedManagerPingMapper (com.biglybt.core.speedmanager.SpeedManagerPingMapper)7 SpeedManager (com.biglybt.core.speedmanager.SpeedManager)6 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 Label (org.eclipse.swt.widgets.Label)2 LogEvent (com.biglybt.core.logging.LogEvent)1 PEPeerManager (com.biglybt.core.peer.PEPeerManager)1 PEPeerManagerStats (com.biglybt.core.peer.PEPeerManagerStats)1 LimitToTextHelper (com.biglybt.core.speedmanager.LimitToTextHelper)1 SpeedManagerListener (com.biglybt.core.speedmanager.SpeedManagerListener)1 Parameter (com.biglybt.pif.ui.config.Parameter)1 TransferStatsView (com.biglybt.ui.swt.views.stats.TransferStatsView)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 MouseAdapter (org.eclipse.swt.events.MouseAdapter)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1