Changeset 171f0d2


Ignore:
Timestamp:
Jul 17, 2013 9:13:19 PM (7 years ago)
Author:
zab2 <zab2@…>
Branches:
master
Children:
1e2fb4b
Parents:
8937c4b
Message:

Implement RTT update on first ack

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • apps/streaming/java/src/net/i2p/client/streaming/ConnectionOptions.java

    r8937c4b r171f0d2  
    5252    private int _maxConns;
    5353    private boolean _disableRejectLog;
    54 
     54    private double _alpha;
     55    private double _beta;
     56    private double _kappa;
     57   
     58    /** state of a connection */
     59    enum AckInit {
     60        INIT, // just created
     61        FIRST, // first received ack
     62        STEADY
     63    }
     64   
     65    /** LOCKING: this */
     66    private AckInit _initState = AckInit.INIT;
     67   
    5568    // NOTE - almost all the options are below, but see
    5669    // I2PSocketOptions in ministreaming for a few more
     
    6679    public static final int INACTIVITY_ACTION_SEND = 2;
    6780   
     81    /*
     82     * These values are specified in RFC 6298
     83     * Do not change unless you know what you're doing
     84     */
     85    private static final double TCP_ALPHA = 1.0/8;
     86    private static final double TCP_BETA = 1.0/4;
     87    private static final double TCP_KAPPA = 4;
     88    private static final String PROP_TCP_ALPHA= "i2p.streaming.alpha";
     89    private static final String PROP_TCP_BETA= "i2p.streaming.beta";
     90    private static final String PROP_TCP_KAPPA = "i2p.streaming.kappa";
     91   
     92    private static final String PROP_INITIAL_RTO = "i2p.streaming.initialRTO";
     93    private static final int INITIAL_RTO = 12000;
     94   
    6895    public static final String PROP_CONNECT_DELAY = "i2p.streaming.connectDelay";
    6996    public static final String PROP_PROFILE = "i2p.streaming.profile";
    7097    public static final String PROP_MAX_MESSAGE_SIZE = "i2p.streaming.maxMessageSize";
    7198    public static final String PROP_MAX_RESENDS = "i2p.streaming.maxResends";
    72     public static final String PROP_INITIAL_RTT = "i2p.streaming.initialRTT";
    7399    public static final String PROP_INITIAL_RESEND_DELAY = "i2p.streaming.initialResendDelay";
    74100    public static final String PROP_INITIAL_ACK_DELAY = "i2p.streaming.initialAckDelay";
     
    296322            setConnectDelay(opts.getConnectDelay());
    297323            setProfile(opts.getProfile());
     324            setRTTDev(opts.getRTTDev());
    298325            setRTT(opts.getRTT());
    299326            setRequireFullySigned(opts.getRequireFullySigned());
     
    333360        setProfile(getInt(opts, PROP_PROFILE, PROFILE_BULK));
    334361        setMaxMessageSize(getInt(opts, PROP_MAX_MESSAGE_SIZE, DEFAULT_MAX_MESSAGE_SIZE));
    335         setRTT(getInt(opts, PROP_INITIAL_RTT, DEFAULT_INITIAL_RTT));
    336362        setReceiveWindow(getInt(opts, PROP_INITIAL_RECEIVE_WINDOW, 1));
    337363        setResendDelay(getInt(opts, PROP_INITIAL_RESEND_DELAY, 1000));
     
    361387        _maxTotalConnsPerDay = getInt(opts, PROP_MAX_TOTAL_CONNS_DAY, 0);
    362388        _maxConns = getInt(opts, PROP_MAX_STREAMS, 0);
     389       
     390        _alpha = getDouble(opts, PROP_TCP_ALPHA, TCP_ALPHA);
     391        _beta = getDouble(opts, PROP_TCP_BETA, TCP_BETA);
     392        _kappa = getDouble(opts, PROP_TCP_KAPPA, TCP_KAPPA);
     393       
     394        _rto = getInt(opts, PROP_INITIAL_RTO, INITIAL_RTO);
    363395    }
    364396   
     
    378410        if (opts.containsKey(PROP_MAX_MESSAGE_SIZE))
    379411            setMaxMessageSize(getInt(opts, PROP_MAX_MESSAGE_SIZE, Packet.MAX_PAYLOAD_SIZE));
    380         if (opts.containsKey(PROP_INITIAL_RTT))
    381             setRTT(getInt(opts, PROP_INITIAL_RTT, DEFAULT_INITIAL_RTT));
    382412        if (opts.containsKey(PROP_INITIAL_RECEIVE_WINDOW))
    383413            setReceiveWindow(getInt(opts, PROP_INITIAL_RECEIVE_WINDOW, 1));
     
    428458        if (opts.containsKey(PROP_MAX_STREAMS))
    429459            _maxConns = getInt(opts, PROP_MAX_STREAMS, 0);
     460       
     461        _alpha = getDouble(opts, PROP_TCP_ALPHA, TCP_ALPHA);
     462        _beta = getDouble(opts, PROP_TCP_BETA, TCP_BETA);
     463        _kappa = getDouble(opts, PROP_TCP_KAPPA, TCP_KAPPA);
     464        _rto = getInt(opts, PROP_INITIAL_RTO, INITIAL_RTO);
    430465    }
    431466   
     
    518553    public int getRTT() { return _rtt; }
    519554    public void setRTT(int ms) {
    520         if (_rto == 0) { // TODO: move this out
    521             _rttDev = ms / 2;
    522             _rto = ms + ms / 2;
    523         }
    524555        synchronized (_trend) {
    525556            _trend[0] = _trend[1];
     
    545576    void setRTTDev(int rttDev) { _rttDev = rttDev; }
    546577   
     578    /**
     579     * mark these options as loaded from cache.
     580     * affects the calculation of RTO
     581     */
     582    synchronized void loadedFromCache() {
     583        _initState = AckInit.STEADY;
     584    }
     585   
     586    /**
     587     * computes RTO based on formula in RFC
     588     */
     589    synchronized void computeRTO() {
     590        switch(_initState) {
     591        case INIT :
     592            throw new IllegalStateException();
     593        case FIRST :
     594            _rttDev = _rtt / 2;
     595            _rto = _rtt + _rtt / 2;
     596            break;
     597        case STEADY :
     598            _rto = _rtt + (int) (_rttDev * _kappa);
     599            break;
     600        }
     601       
     602        if (_rto < Connection.MIN_RESEND_DELAY)
     603            _rto = (int)Connection.MIN_RESEND_DELAY;
     604        else if (_rto > Connection.MAX_RESEND_DELAY)
     605            _rto = (int)Connection.MAX_RESEND_DELAY;
     606    }
     607   
    547608    /**
    548609     * If we have 3 consecutive rtt increases, we are trending upwards (1), or if we have
     
    561622    }
    562623   
    563     /** rtt = rtt*RTT_DAMPENING + (1-RTT_DAMPENING)*currentPacketRTT */
    564     /** This is the value specified in RFC 2988, let's try it */
    565     private static final double RTT_DAMPENING = 0.875;
    566    
    567     public void updateRTT(int measuredValue) {
    568         // the rttDev calculation matches that recommended in RFC 2988 (beta = 1/4)
    569         _rttDev = _rttDev + (int)(0.25d*(Math.abs(measuredValue-_rtt)-_rttDev));
    570         int smoothed = (int)(RTT_DAMPENING*_rtt + (1-RTT_DAMPENING)*measuredValue);       
    571         // K = 4
    572         _rto = smoothed + (_rttDev<<2);
    573         if (_rto < Connection.MIN_RESEND_DELAY)
    574             _rto = (int)Connection.MIN_RESEND_DELAY;
    575         else if (_rto > Connection.MAX_RESEND_DELAY)
    576             _rto = (int)Connection.MAX_RESEND_DELAY;
    577 
    578         setRTT(smoothed);
     624    public synchronized void updateRTT(int measuredValue) {
     625        switch(_initState) {
     626        case INIT:
     627            _initState = AckInit.FIRST;
     628            setRTT(measuredValue); // no smoothing first sample
     629            break;
     630        case FIRST:
     631            _initState = AckInit.STEADY;
     632        case STEADY:
     633            // calculation matches that recommended in RFC 6298
     634            _rttDev = (int) ((1-_beta) *_rttDev  + _beta * Math.abs(measuredValue-_rtt));
     635            int smoothed = (int)((1-_alpha)*_rtt + _alpha*measuredValue);       
     636            setRTT(smoothed);
     637        }
     638        computeRTO();
    579639    }
    580640   
  • apps/streaming/java/src/net/i2p/client/streaming/TCBShare.java

    r8937c4b r171f0d2  
    100100                       " wdw: " + wdw );
    101101        }
     102        opts.loadedFromCache();
    102103        opts.setRTT(rtt);
    103104        opts.setRTTDev(rttDev);
    104105        opts.setWindowSize(wdw);
     106        opts.computeRTO();
    105107    }
    106108
  • router/java/src/net/i2p/router/RouterVersion.java

    r8937c4b r171f0d2  
    2222
    2323    /** for example "-test" */
    24     public final static String EXTRA = "";
     24    public final static String EXTRA = "-979";
    2525    public final static String FULL_VERSION = VERSION + "-" + BUILD + EXTRA;
    2626    public static void main(String args[]) {
Note: See TracChangeset for help on using the changeset viewer.