Changeset e974d3b


Ignore:
Timestamp:
Nov 22, 2012 8:53:03 PM (7 years ago)
Author:
zab <zab@…>
Branches:
master
Children:
1e830287
Parents:
d5d70f1 (diff), 7c96044 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

propagate from branch 'i2p.i2p.zab.782' (head 64415601890b9c494a8f06379f9feefbc855e07c)

to branch 'i2p.i2p' (head 0e92cf3a3844e7b738ca9c2486112867fc663b6f)

Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/src/net/i2p/router/web/ProfileOrganizerRenderer.java

    rd5d70f1 re974d3b  
    1717import net.i2p.router.peermanager.ProfileOrganizer;
    1818import net.i2p.stat.Rate;
     19import net.i2p.stat.RateAverages;
    1920import net.i2p.stat.RateStat;
    2021
     
    172173            if (prof.getIsFailing()) buf.append(' ').append(_("Failing"));
    173174            if (_context.commSystem().wasUnreachable(peer)) buf.append(' ').append(_("Unreachable"));
     175            RateAverages ra = RateAverages.getTemp();
    174176            Rate failed = prof.getTunnelHistory().getFailedRate().getRate(30*60*1000);
    175             long fails = failed.getCurrentEventCount() + failed.getLastEventCount();
     177            long fails = failed.computeAverages(ra, false).getTotalEventCount();
    176178            if (fails > 0) {
    177179                Rate accepted = prof.getTunnelCreateResponseTime().getRate(30*60*1000);
    178                 long total = fails + accepted.getCurrentEventCount() + accepted.getLastEventCount();
     180                long total = fails + accepted.computeAverages(ra, false).getTotalEventCount();
    179181                if (total / fails <= 10)   // hide if < 10%
    180182                    buf.append(' ').append(fails).append('/').append(total).append(' ').append(_("Test Fails"));
     
    219221        buf.append("<th class=\"smallhead\">").append(_("1d Fail Rate")).append("</th>");
    220222        buf.append("</tr>");
     223        RateAverages ra = RateAverages.getTemp();
    221224        for (Iterator<PeerProfile> iter = integratedPeers.iterator(); iter.hasNext();) {
    222225            PeerProfile prof = iter.next();
     
    241244            time = now - prof.getLastSendFailed();
    242245            buf.append("<td align=\"right\">").append(DataHelper.formatDuration2(time)).append("</td>");
    243             buf.append("<td align=\"right\">").append(avg(prof, 10*60*1000l)).append("</td>");
    244             buf.append("<td align=\"right\">").append(avg(prof, 60*60*1000l)).append("</td>");
    245             buf.append("<td align=\"right\">").append(avg(prof, 24*60*60*1000l)).append("</td>");
     246            buf.append("<td align=\"right\">").append(avg(prof, 10*60*1000l, ra)).append("</td>");
     247            buf.append("<td align=\"right\">").append(avg(prof, 60*60*1000l, ra)).append("</td>");
     248            buf.append("<td align=\"right\">").append(avg(prof, 24*60*60*1000l, ra)).append("</td>");
    246249            DBHistory dbh = prof.getDBHistory();
    247250            if (dbh != null) {
     
    254257                time = now - dbh.getLastStoreFailed();
    255258                buf.append("<td align=\"right\">").append(DataHelper.formatDuration2(time)).append("</td>");
    256                 buf.append("<td align=\"right\">").append(davg(dbh, 60*60*1000l)).append("</td>");
    257                 buf.append("<td align=\"right\">").append(davg(dbh, 24*60*60*1000l)).append("</td>");
     259                buf.append("<td align=\"right\">").append(davg(dbh, 60*60*1000l, ra)).append("</td>");
     260                buf.append("<td align=\"right\">").append(davg(dbh, 24*60*60*1000l, ra)).append("</td>");
    258261            } else {
    259262                for (int i = 0; i < 6; i++)
     
    341344    private final static String NA = HelperBase._x("n/a");
    342345
    343     private String avg (PeerProfile prof, long rate) {
     346    private String avg (PeerProfile prof, long rate, RateAverages ra) {
    344347            RateStat rs = prof.getDbResponseTime();
    345348            if (rs == null)
     
    348351            if (r == null)
    349352                return _(NA);
    350             long c = r.getCurrentEventCount() + r.getLastEventCount();
    351             if (c == 0)
     353            r.computeAverages(ra, false);
     354            if (ra.getTotalEventCount() == 0)
    352355                return _(NA);
    353             double d = r.getCurrentTotalValue() + r.getLastTotalValue();
    354             return DataHelper.formatDuration2(Math.round(d/c));
    355     }
    356 
    357     private String davg (DBHistory dbh, long rate) {
     356            return DataHelper.formatDuration2(Math.round(ra.getAverage()));
     357    }
     358
     359    private String davg (DBHistory dbh, long rate, RateAverages ra) {
    358360            RateStat rs = dbh.getFailedLookupRate();
    359361            if (rs == null)
     
    362364            if (r == null)
    363365                return "0%";
    364             long c = r.getCurrentEventCount() + r.getLastEventCount();
    365             if (c <= 0)
     366            r.computeAverages(ra, false);
     367            if (ra.getTotalEventCount() <= 0)
    366368                return "0%";
    367             double avg = 0.5 + 100 * (r.getCurrentTotalValue() + r.getLastTotalValue()) / c;
     369            double avg = 0.5 + 100 * ra.getAverage();
    368370            return ((int) avg) + "%";
    369371    }
  • core/java/src/net/i2p/stat/Rate.java

    rd5d70f1 re974d3b  
    1515public class Rate {
    1616    //private final static Log _log = new Log(Rate.class);
    17     private volatile double _currentTotalValue;
     17    private double _currentTotalValue;
    1818    // was long, save space
    19     private volatile int _currentEventCount;
    20     private volatile long _currentTotalEventTime;
    21     private volatile double _lastTotalValue;
     19    private int _currentEventCount;
     20    private long _currentTotalEventTime;
     21    private double _lastTotalValue;
    2222    // was long, save space
    23     private volatile int _lastEventCount;
    24     private volatile long _lastTotalEventTime;
    25     private volatile double _extremeTotalValue;
     23    private int _lastEventCount;
     24    private long _lastTotalEventTime;
     25    private double _extremeTotalValue;
    2626    // was long, save space
    27     private volatile int _extremeEventCount;
    28     private volatile long _extremeTotalEventTime;
    29     private volatile double _lifetimeTotalValue;
    30     private volatile long _lifetimeEventCount;
    31     private volatile long _lifetimeTotalEventTime;
     27    private int _extremeEventCount;
     28    private long _extremeTotalEventTime;
     29    private double _lifetimeTotalValue;
     30    private long _lifetimeEventCount;
     31    private long _lifetimeTotalEventTime;
    3232    private RateSummaryListener _summaryListener;
    3333    private RateStat _stat;
    3434
    35     private volatile long _lastCoalesceDate;
     35    private long _lastCoalesceDate;
    3636    private long _creationDate;
    3737    // was long, save space
     
    4242
    4343    /** in the current (partial) period, what is the total value acrued through all events? */
    44     public double getCurrentTotalValue() {
     44    public synchronized double getCurrentTotalValue() {
    4545        return _currentTotalValue;
    4646    }
    4747
    4848    /** in the current (partial) period, how many events have occurred? */
    49     public long getCurrentEventCount() {
     49    public synchronized long getCurrentEventCount() {
    5050        return _currentEventCount;
    5151    }
    5252
    5353    /** in the current (partial) period, how much of the time has been spent doing the events? */
    54     public long getCurrentTotalEventTime() {
     54    public synchronized long getCurrentTotalEventTime() {
    5555        return _currentTotalEventTime;
    5656    }
    5757
    5858    /** in the last full period, what was the total value acrued through all events? */
    59     public double getLastTotalValue() {
     59    public synchronized double getLastTotalValue() {
    6060        return _lastTotalValue;
    6161    }
    6262
    6363    /** in the last full period, how many events occurred? */
    64     public long getLastEventCount() {
     64    public synchronized long getLastEventCount() {
    6565        return _lastEventCount;
    6666    }
    6767
    6868    /** in the last full period, how much of the time was spent doing the events? */
    69     public long getLastTotalEventTime() {
     69    public synchronized long getLastTotalEventTime() {
    7070        return _lastTotalEventTime;
    7171    }
    7272
    7373    /** what was the max total value acrued in any period?  */
    74     public double getExtremeTotalValue() {
     74    public synchronized double getExtremeTotalValue() {
    7575        return _extremeTotalValue;
    7676    }
     
    8080     * Note that this is not necesarily the highest event count; that isn't tracked.
    8181     */
    82     public long getExtremeEventCount() {
     82    public synchronized long getExtremeEventCount() {
    8383        return _extremeEventCount;
    8484    }
    8585
    8686    /** when the max(totalValue) was achieved, how much of the time was spent doing the events? */
    87     public long getExtremeTotalEventTime() {
     87    public synchronized long getExtremeTotalEventTime() {
    8888        return _extremeTotalEventTime;
    8989    }
    9090
    9191    /** since rate creation, what was the total value acrued through all events?  */
    92     public double getLifetimeTotalValue() {
     92    public synchronized double getLifetimeTotalValue() {
    9393        return _lifetimeTotalValue;
    9494    }
    9595
    9696    /** since rate creation, how many events have occurred? */
    97     public long getLifetimeEventCount() {
     97    public synchronized long getLifetimeEventCount() {
    9898        return _lifetimeEventCount;
    9999    }
    100100
    101101    /** since rate creation, how much of the time was spent doing the events? */
    102     public long getLifetimeTotalEventTime() {
     102    public synchronized long getLifetimeTotalEventTime() {
    103103        return _lifetimeTotalEventTime;
    104104    }
    105105
    106106    /** when was the rate last coalesced? */
    107     public long getLastCoalesceDate() {
     107    public synchronized long getLastCoalesceDate() {
    108108        return _lastCoalesceDate;
    109109    }
    110110
    111111    /** when was this rate created? */
    112     public long getCreationDate() {
     112    public synchronized long getCreationDate() {
    113113        return _creationDate;
    114114    }
    115115
    116116    /** how large should this rate's cycle be? */
    117     public long getPeriod() {
     117    public synchronized long getPeriod() {
    118118        return _period;
    119119    }
     
    161161     * and the various get*Saturation*() and get*EventTime() methods will return zero.
    162162     */
    163     public void addData(long value) {
    164         synchronized (this) {
    165             _currentTotalValue += value;
    166             _currentEventCount++;
    167             _lifetimeTotalValue += value;
    168             _lifetimeEventCount++;
    169         }
     163    public synchronized void addData(long value) {
     164        _currentTotalValue += value;
     165        _currentEventCount++;
     166        _lifetimeTotalValue += value;
     167        _lifetimeEventCount++;
    170168    }
    171169
     
    203201     * @param eventDuration how long it took to accrue this data (set to 0 if it was instantaneous)
    204202     */
    205     public void addData(long value, long eventDuration) {
    206         synchronized (this) {
    207             _currentTotalValue += value;
    208             _currentEventCount++;
    209             _currentTotalEventTime += eventDuration;
    210 
    211             _lifetimeTotalValue += value;
    212             _lifetimeEventCount++;
    213             _lifetimeTotalEventTime += eventDuration;
    214         }
     203    public synchronized void addData(long value, long eventDuration) {
     204        _currentTotalValue += value;
     205        _currentEventCount++;
     206        _currentTotalEventTime += eventDuration;
     207
     208        _lifetimeTotalValue += value;
     209        _lifetimeEventCount++;
     210        _lifetimeTotalEventTime += eventDuration;
    215211    }
    216212
     
    262258    /**
    263259     * What was the average value across the events in the last period?
    264      *
    265      * Warning - unsynchronized, might glitch during coalesce, caller may prevent by synchronizing on this.
    266      */
    267     public double getAverageValue() {
     260     */
     261    public synchronized double getAverageValue() {
    268262        int lec = _lastEventCount;  // avoid race NPE
    269263        if ((_lastTotalValue != 0) && (lec > 0))
     
    276270     * During the extreme period (i.e. the period with the highest total value),
    277271     * what was the average value?
    278      *
    279      * Warning - unsynchronized, might glitch during coalesce, caller may prevent by synchronizing on this.
    280      */
    281     public double getExtremeAverageValue() {
     272     */
     273    public synchronized double getExtremeAverageValue() {
    282274        if ((_extremeTotalValue != 0) && (_extremeEventCount > 0))
    283275            return _extremeTotalValue / _extremeEventCount;
     
    288280    /**
    289281     * What was the average value across the events since the stat was created?
    290      *
    291      * Warning - unsynchronized, might glitch during coalesce, caller may prevent by synchronizing on this.
    292      */
    293     public double getLifetimeAverageValue() {
     282     */
     283    public synchronized double getLifetimeAverageValue() {
    294284        if ((_lifetimeTotalValue != 0) && (_lifetimeEventCount > 0))
    295285            return _lifetimeTotalValue / _lifetimeEventCount;
     
    298288    }
    299289
     290    /**
     291     * @return the average or lifetime average depending on last event count
     292     * @since 0.9.4
     293     */
     294    public synchronized double getAvgOrLifetimeAvg() {
     295        if (getLastEventCount() > 0)
     296            return getAverageValue();
     297        return getLifetimeAverageValue();
     298    }
     299   
    300300    /**
    301301     * During the last period, how much of the time was spent actually processing events in proportion
     
    304304     * @return ratio, or 0 if event times aren't used
    305305     */
    306     public double getLastEventSaturation() {
     306    public synchronized double getLastEventSaturation() {
    307307        if ((_lastEventCount > 0) && (_lastTotalEventTime > 0)) {
    308308            /*double eventTime = (double) _lastTotalEventTime / (double) _lastEventCount;
     
    322322     * in proportion to how many events could have occurred if there were no intervals?
    323323     *
    324      * Warning - unsynchronized, might glitch during coalesce, caller may prevent by synchronizing on this.
    325      *
    326324     * @return ratio, or 0 if the statistic doesn't use event times
    327325     */
    328     public double getExtremeEventSaturation() {
     326    public synchronized double getExtremeEventSaturation() {
    329327        if ((_extremeEventCount > 0) && (_extremeTotalEventTime > 0)) {
    330328            double eventTime = (double) _extremeTotalEventTime / (double) _extremeEventCount;
     
    339337     * to how many events could have occurred if there were no intervals?
    340338     *
    341      * Warning - unsynchronized, might glitch during coalesce, caller may prevent by synchronizing on this.
    342      *
    343339     * @return ratio, or 0 if event times aren't used
    344340     */
    345     public double getLifetimeEventSaturation() {
     341    public synchronized double getLifetimeEventSaturation() {
    346342        if ((_lastEventCount > 0) && (_lifetimeTotalEventTime > 0)) {
    347343            double eventTime = (double) _lifetimeTotalEventTime / (double) _lifetimeEventCount;
     
    355351
    356352    /** how many periods have we already completed? */
    357     public long getLifetimePeriods() {
     353    public synchronized long getLifetimePeriods() {
    358354        long lifetime = now() - _creationDate;
    359355        double periods = lifetime / (double) _period;
     
    365361     * if events were constant?
    366362     *
    367      * Warning - unsynchronized, might glitch during coalesce, caller may prevent by synchronizing on this.
    368      *
    369363     * @return max total value, or 0 if event times aren't used
    370364     */
    371     public double getLastSaturationLimit() {
     365    public synchronized double getLastSaturationLimit() {
    372366        if ((_lastTotalValue != 0) && (_lastEventCount > 0) && (_lastTotalEventTime > 0)) {
    373367            double saturation = getLastEventSaturation();
     
    384378     * sent if events were constant?
    385379     *
    386      * Warning - unsynchronized, might glitch during coalesce, caller may prevent by synchronizing on this.
    387      *
    388380     * @return event total at saturation, or 0 if no event times are measured
    389381     */
    390     public double getExtremeSaturationLimit() {
     382    public synchronized double getExtremeSaturationLimit() {
    391383        if ((_extremeTotalValue != 0) && (_extremeEventCount > 0) && (_extremeTotalEventTime > 0)) {
    392384            double saturation = getExtremeEventSaturation();
     
    403395     * the extreme period (i.e. the period with the highest total value),
    404396     * Warning- returns ratio, not percentage (i.e. it is not multiplied by 100 here)
    405      *
    406      * Warning - unsynchronized, might glitch during coalesce, caller may prevent by synchronizing on this.
    407      */
    408     public double getPercentageOfExtremeValue() {
     397     */
     398    public synchronized double getPercentageOfExtremeValue() {
    409399        if ((_lastTotalValue != 0) && (_extremeTotalValue != 0))
    410400            return _lastTotalValue / _extremeTotalValue;
     
    416406     * How large was the last period's value as compared to the lifetime average value?
    417407     * Warning- returns ratio, not percentage (i.e. it is not multiplied by 100 here)
    418      *
    419      * Warning - unsynchronized, might glitch during coalesce, caller may prevent by synchronizing on this.
    420      */
    421     public double getPercentageOfLifetimeValue() {
     408     */
     409    public synchronized double getPercentageOfLifetimeValue() {
    422410        if ((_lastTotalValue != 0) && (_lifetimeTotalValue != 0)) {
    423411            double lifetimePeriodValue = _period * (_lifetimeTotalValue / (now() - _creationDate));
     
    427415        return 0.0D;
    428416    }
    429 
    430     public void store(String prefix, StringBuilder buf) throws IOException {
     417   
     418    /**
     419     * @return a thread-local temp object containing computed averages.
     420     * @since 0.9.4
     421     */
     422    public RateAverages computeAverages() {
     423        return computeAverages(RateAverages.getTemp(),false);
     424    }
     425   
     426    /**
     427     * @param out where to store the computed averages. 
     428     * @param useLifetime whether the lifetime average should be used if
     429     * there are no events.
     430     * @return the same RateAverages object for chaining
     431     * @since 0.9.4
     432     */
     433    public synchronized RateAverages computeAverages(RateAverages out, boolean useLifetime) {
     434        out.reset();
     435       
     436        final long total = _currentEventCount + _lastEventCount;
     437        out.setTotalEventCount(total);
     438       
     439        if (total <= 0) {
     440            final double avg = useLifetime ? getLifetimeAverageValue() : getAverageValue();
     441            out.setAverage(avg);
     442        } else {
     443
     444            if (_currentEventCount > 0)
     445                out.setCurrent( getCurrentTotalValue() / _currentEventCount );
     446            if (_lastEventCount > 0)
     447                out.setLast( getLastTotalValue() / _lastEventCount );
     448
     449            out.setTotalValues(getCurrentTotalValue() + getLastTotalValue());
     450            out.setAverage( out.getTotalValues()  / total );
     451        }
     452        return out;
     453    }
     454
     455    public synchronized void store(String prefix, StringBuilder buf) throws IOException {
    431456        PersistenceHelper.addTime(buf, prefix, ".period", "Length of the period:", _period);
    432457        PersistenceHelper.addDate(buf, prefix, ".creationDate",
     
    477502     * @throws IllegalArgumentException if the data was formatted incorrectly
    478503     */
    479     public void load(Properties props, String prefix, boolean treatAsCurrent) throws IllegalArgumentException {
     504    public synchronized void load(Properties props, String prefix, boolean treatAsCurrent) throws IllegalArgumentException {
    480505        _period = PersistenceHelper.getInt(props, prefix, ".period");
    481506        _creationDate = PersistenceHelper.getLong(props, prefix, ".creationDate");
     
    505530     */
    506531    @Override
    507     public boolean equals(Object obj) {
     532    public synchronized boolean equals(Object obj) {
    508533        if ((obj == null) || !(obj instanceof Rate)) return false;
    509534        if (obj == this) return true;
     
    520545     */
    521546    @Override
    522     public int hashCode() {
     547    public synchronized int hashCode() {
    523548        return DataHelper.hashCode(_stat) ^ _period ^ ((int) _creationDate);
    524549    }
    525550
    526551    @Override
    527     public String toString() {
     552    public synchronized String toString() {
    528553        StringBuilder buf = new StringBuilder(2048);
    529554        buf.append("\n\t total value: ").append(getLastTotalValue());
     
    555580        return System.currentTimeMillis(); //Clock.getInstance().now();
    556581    }
    557 
    558 /******
    559     public static void main(String args[]) {
    560         Rate rate = new Rate(1000);
    561         for (int i = 0; i < 50; i++) {
    562             try {
    563                 Thread.sleep(20);
    564             } catch (InterruptedException ie) { // nop
    565             }
    566             rate.addData(i * 100, 20);
    567         }
    568         rate.coalesce();
    569         StringBuilder buf = new StringBuilder(1024);
    570         try {
    571             rate.store("rate.test", buf);
    572             byte data[] = buf.toString().getBytes();
    573             _log.error("Stored rate: size = " + data.length + "\n" + buf.toString());
    574 
    575             Properties props = new Properties();
    576             props.load(new java.io.ByteArrayInputStream(data));
    577 
    578             //_log.error("Properties loaded: \n" + props);
    579 
    580             Rate r = new Rate(props, "rate.test", true);
    581 
    582             _log.error("Comparison after store/load: " + r.equals(rate));
    583         } catch (Throwable t) {
    584             _log.error("b0rk", t);
    585         }
    586         try {
    587             Thread.sleep(5000);
    588         } catch (InterruptedException ie) { // nop
    589         }
    590     }
    591 ******/
    592582}
  • router/java/src/net/i2p/router/RouterThrottleImpl.java

    rd5d70f1 re974d3b  
    44import net.i2p.router.peermanager.TunnelHistory;
    55import net.i2p.stat.Rate;
     6import net.i2p.stat.RateAverages;
    67import net.i2p.stat.RateStat;
    78import net.i2p.util.Log;
    8 import net.i2p.util.SimpleScheduler;
    99import net.i2p.util.SimpleTimer;
    1010
     
    4141
    4242    private static final long REJECT_STARTUP_TIME = 20*60*1000;
    43 
     43   
    4444    public RouterThrottleImpl(RouterContext context) {
    4545        _context = context;
     
    120120        // reject here if lag too high???
    121121       
     122        RateAverages ra = RateAverages.getTemp();
     123       
    122124        // TODO
    123125        // This stat is highly dependent on transport mix.
     
    134136        //Reject tunnels if the time to process messages and send them is too large. Too much time implies congestion.
    135137        if(r != null) {
    136             long current = r.getCurrentEventCount();
    137             long last = r.getLastEventCount();
    138             long total = current + last;
    139             double avgSendProcessingTime = 0;
    140             double currentSendProcessingTime = 0;
    141             double lastSendProcessingTime = 0;
     138            r.computeAverages(ra,false);
    142139           
    143             //Calculate times
    144             if(total > 0) {
    145                 if(current > 0)
    146                     currentSendProcessingTime = r.getCurrentTotalValue() / current;
    147                 if(last > 0)
    148                     lastSendProcessingTime = r.getLastTotalValue() / last;
    149                 avgSendProcessingTime =  (r.getCurrentTotalValue() + r.getLastTotalValue()) / total;
    150             } else {
    151                 avgSendProcessingTime = r.getAverageValue();
    152                 //if(_log.shouldLog(Log.WARN))
    153                 //    _log.warn("No events occurred. Using 1 minute average to look at message delay.");
    154             }
    155 
    156140            int maxProcessingTime = _context.getProperty(PROP_MAX_PROCESSINGTIME, DEFAULT_MAX_PROCESSINGTIME);
    157141
    158142            //Set throttling if necessary
    159             if((avgSendProcessingTime > maxProcessingTime*0.9
    160                     || currentSendProcessingTime > maxProcessingTime
    161                     || lastSendProcessingTime > maxProcessingTime)) {
     143            if((ra.getAverage() > maxProcessingTime*0.9
     144                    || ra.getCurrent() > maxProcessingTime
     145                    || ra.getLast() > maxProcessingTime)) {
    162146                if(_log.shouldLog(Log.WARN)) {
    163147                    _log.warn("Refusing tunnel request due to sendProcessingTime " +
    164                               ((int)currentSendProcessingTime) + " / " +
    165                               ((int)lastSendProcessingTime) + " / " +
    166                               ((int)avgSendProcessingTime) + " / " +
     148                              ((int)ra.getCurrent()) + " / " +
     149                              ((int)ra.getLast()) + " / " +
     150                              ((int)ra.getAverage()) + " / " +
    167151                              maxProcessingTime +
    168152                              " current/last/avg/max ms");
     
    182166            Rate avgTunnels = _context.statManager().getRate("tunnel.participatingTunnels").getRate(10*60*1000);
    183167            if (avgTunnels != null) {
    184                 double avg = 0;
    185                 if (avgTunnels.getLastEventCount() > 0)
    186                     avg = avgTunnels.getAverageValue();
    187                 else
    188                     avg = avgTunnels.getLifetimeAverageValue();
     168               
     169                double avg = avgTunnels.getAvgOrLifetimeAvg();
     170               
    189171                int min = getMinThrottleTunnels();
    190172                if (avg < min)
     
    223205        if ( (tunnelTestTime1m != null) && (tunnelTestTime10m != null) && (tunnelTestTime1m.getLastEventCount() > 0) ) {
    224206            double avg1m = tunnelTestTime1m.getAverageValue();
    225             double avg10m = 0;
    226             if (tunnelTestTime10m.getLastEventCount() > 0)
    227                 avg10m = tunnelTestTime10m.getAverageValue();
    228             else
    229                 avg10m = tunnelTestTime10m.getLifetimeAverageValue();
     207            double avg10m = tunnelTestTime10m.getAvgOrLifetimeAvg();
    230208
    231209            if (avg10m < 5000)
     
    273251        if (rs != null) {
    274252            r = rs.getRate(60*1000);
    275             if (r != null) {
    276                 long count = r.getLastEventCount() + r.getCurrentEventCount();
    277                 if (count > 0)
    278                     messagesPerTunnel = (r.getLastTotalValue() + r.getCurrentTotalValue()) / count;
    279                 else
    280                     messagesPerTunnel = r.getLifetimeAverageValue();
    281             }
     253            if (r != null)
     254                messagesPerTunnel = r.computeAverages(ra, true).getAverage();
    282255        }
    283256        if (messagesPerTunnel < DEFAULT_MESSAGES_PER_TUNNEL_ESTIMATE)
  • router/java/src/net/i2p/router/peermanager/CapacityCalculator.java

    rd5d70f1 re974d3b  
    33import net.i2p.I2PAppContext;
    44import net.i2p.stat.Rate;
     5import net.i2p.stat.RateAverages;
    56import net.i2p.stat.RateStat;
    67
     
    123124        Rate curRejected = rejectStat.getRate(period);
    124125        Rate curFailed = failedStat.getRate(period);
     126        RateAverages ra = RateAverages.getTemp();
    125127
    126128        double eventCount = 0;
    127129        if (curAccepted != null) {
    128             eventCount = curAccepted.getCurrentEventCount() + curAccepted.getLastEventCount();
     130            eventCount = curAccepted.computeAverages(ra, false).getTotalEventCount();
    129131            // Punish for rejections.
    130132            // We don't want to simply do eventCount -= rejected or we get to zero with 50% rejection,
    131133            // and we don't want everybody to be at zero during times of congestion.
    132134            if (eventCount > 0 && curRejected != null) {
    133                 long rejected = curRejected.getCurrentEventCount() + curRejected.getLastEventCount();
     135                long rejected = curRejected.computeAverages(ra,false).getTotalEventCount();
    134136                if (rejected > 0)
    135137                    eventCount *= eventCount / (eventCount + (2 * rejected));
     
    145147        // We also don't want to drive everybody's capacity to zero, that isn't helpful.
    146148        if (curFailed != null) {
    147             double failed = curFailed.getCurrentTotalValue() + curFailed.getLastTotalValue();
     149            double failed = curFailed.computeAverages(ra, false).getTotalValues();
    148150            if (failed > 0) {
    149151                //if ( (period <= 10*60*1000) && (curFailed.getCurrentEventCount() > 0) )
  • router/java/src/net/i2p/router/tunnel/pool/ExploratoryPeerSelector.java

    rd5d70f1 re974d3b  
    179179        if (r == null)
    180180            return 0;
    181         return (int) (r.getLastEventCount() + r.getCurrentEventCount());
     181        return (int) (r.computeAverages().getTotalEventCount());
    182182    }
    183183}
  • router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java

    rd5d70f1 re974d3b  
    2020import net.i2p.router.tunnel.HopConfig;
    2121import net.i2p.stat.Rate;
     22import net.i2p.stat.RateAverages;
    2223import net.i2p.stat.RateStat;
    2324import net.i2p.util.Log;
     
    332333                Rate sr = s.getRate(10*60*1000);
    333334                if (er != null && rr != null && sr != null) {
    334                     long ec = er.getCurrentEventCount() + er.getLastEventCount();
    335                     long rc = rr.getCurrentEventCount() + rr.getLastEventCount();
    336                     long sc = sr.getCurrentEventCount() + sr.getLastEventCount();
     335                    RateAverages ra = RateAverages.getTemp();
     336                    long ec = er.computeAverages(ra, false).getTotalEventCount();
     337                    long rc = rr.computeAverages(ra, false).getTotalEventCount();
     338                    long sc = sr.computeAverages(ra, false).getTotalEventCount();
    337339                    long tot = ec + rc + sc;
    338340                    if (tot >= BUILD_TRIES_QUANTITY_OVERRIDE) {
     
    367369                Rate sr = s.getRate(10*60*1000);
    368370                if (er != null && rr != null && sr != null) {
    369                     long ec = er.getCurrentEventCount() + er.getLastEventCount();
    370                     long rc = rr.getCurrentEventCount() + rr.getLastEventCount();
    371                     long sc = sr.getCurrentEventCount() + sr.getLastEventCount();
     371                    RateAverages ra = RateAverages.getTemp();
     372                    long ec = er.computeAverages(ra, false).getTotalEventCount();
     373                    long rc = rr.computeAverages(ra, false).getTotalEventCount();
     374                    long sc = sr.computeAverages(ra, false).getTotalEventCount();
    372375                    long tot = ec + rc + sc;
    373376                    if (tot >= BUILD_TRIES_LENGTH_OVERRIDE) {
Note: See TracChangeset for help on using the changeset viewer.