Search in sources :

Example 16 with Rate

use of net.i2p.stat.Rate in project i2p.i2p by i2p.

the class CapacityCalculator method estimateCapacity.

/**
 * Compute a tunnel accept capacity-per-hour for the given period
 * This is perhaps the most critical part of the peer ranking and selection
 * system, so adjust with great care and testing to ensure good network
 * performance and prevent congestion collapse.
 *
 * The baseline or "growth factor" is 5.
 * Rejects will not reduce the baseline. Failures will.
 *
 * @param acceptStat Accept counter (1 = 1 accept)
 * @param rejectStat Reject counter (1 = 1 reject)
 * @param failedStat Failed counter (100 = 1 fail)
 *
 * Let A = accects, R = rejects, F = fails
 * @return estimated and adjusted accepts per hour, for the given period
 *         which is, more or less, max(0, 5 + (A * (A / (A + 2R))) - (4 * F))
 */
private static double estimateCapacity(RateStat acceptStat, RateStat rejectStat, RateStat failedStat, int period) {
    Rate curAccepted = acceptStat.getRate(period);
    Rate curRejected = rejectStat.getRate(period);
    Rate curFailed = failedStat.getRate(period);
    RateAverages ra = RateAverages.getTemp();
    double eventCount = 0;
    if (curAccepted != null) {
        eventCount = curAccepted.computeAverages(ra, false).getTotalEventCount();
        // and we don't want everybody to be at zero during times of congestion.
        if (eventCount > 0 && curRejected != null) {
            long rejected = curRejected.computeAverages(ra, false).getTotalEventCount();
            if (rejected > 0)
                eventCount *= eventCount / (eventCount + (2 * rejected));
        }
    }
    double stretch = ((double) ESTIMATE_PERIOD) / period;
    double val = eventCount * stretch;
    // We also don't want to drive everybody's capacity to zero, that isn't helpful.
    if (curFailed != null) {
        double failed = curFailed.computeAverages(ra, false).getTotalValues();
        if (failed > 0) {
            // if ( (period <= 10*60*1000) && (curFailed.getCurrentEventCount() > 0) )
            // return 0.0d; // their tunnels have failed in the last 0-10 minutes
            // else
            // .04 = 4.0 / 100.0 adjustment to failed
            val -= 0.04 * failed * stretch;
        }
    }
    val += GROWTH_FACTOR;
    if (val >= 0) {
        return val;
    } else {
        return 0.0d;
    }
}
Also used : Rate(net.i2p.stat.Rate) RateAverages(net.i2p.stat.RateAverages)

Example 17 with Rate

use of net.i2p.stat.Rate in project i2p.i2p by i2p.

the class CoalesceStatsEvent method timeReached.

public void timeReached() {
    int active = getContext().commSystem().countActivePeers();
    getContext().statManager().addRateData("router.activePeers", active, 60 * 1000);
    int activeSend = getContext().commSystem().countActiveSendPeers();
    getContext().statManager().addRateData("router.activeSendPeers", activeSend, 60 * 1000);
    int fast = getContext().profileOrganizer().countFastPeers();
    getContext().statManager().addRateData("router.fastPeers", fast, 60 * 1000);
    int highCap = getContext().profileOrganizer().countHighCapacityPeers();
    getContext().statManager().addRateData("router.highCapacityPeers", highCap, 60 * 1000);
    int integrated = getContext().peerManager().getPeersByCapability('f').size();
    getContext().statManager().addRateData("router.integratedPeers", integrated, 60 * 1000);
    getContext().statManager().addRateData("bw.sendRate", (long) getContext().bandwidthLimiter().getSendBps());
    getContext().statManager().addRateData("bw.recvRate", (long) getContext().bandwidthLimiter().getReceiveBps());
    getContext().statManager().addRateData("router.tunnelBacklog", getContext().tunnelManager().getInboundBuildQueueSize(), 60 * 1000);
    long used = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
    getContext().statManager().addRateData("router.memoryUsed", used);
    if (_maxMemory - used < LOW_MEMORY_THRESHOLD)
        Router.clearCaches();
    getContext().tunnelDispatcher().updateParticipatingStats(Router.COALESCE_TIME);
    getContext().statManager().coalesceStats();
    RateStat receiveRate = getContext().statManager().getRate("transport.receiveMessageSize");
    if (receiveRate != null) {
        Rate rate = receiveRate.getRate(60 * 1000);
        if (rate != null) {
            double bytes = rate.getLastTotalValue();
            double bps = (bytes * 1000.0d) / rate.getPeriod();
            getContext().statManager().addRateData("bw.receiveBps", (long) bps, 60 * 1000);
        }
    }
    RateStat sendRate = getContext().statManager().getRate("transport.sendMessageSize");
    if (sendRate != null) {
        Rate rate = sendRate.getRate(60 * 1000);
        if (rate != null) {
            double bytes = rate.getLastTotalValue();
            double bps = (bytes * 1000.0d) / rate.getPeriod();
            getContext().statManager().addRateData("bw.sendBps", (long) bps, 60 * 1000);
        }
    }
}
Also used : RateStat(net.i2p.stat.RateStat) Rate(net.i2p.stat.Rate)

Example 18 with Rate

use of net.i2p.stat.Rate in project i2p.i2p by i2p.

the class RouterWatchdog method dumpStatus.

private void dumpStatus() {
    if (_log.shouldLog(Log.ERROR)) {
        /*
            Job cur = _context.jobQueue().getLastJob();
            if (cur != null) 
                _log.error("Most recent job: " + cur);
            _log.error("Last job began: " 
                       + DataHelper.formatDuration(_context.clock().now()-_context.jobQueue().getLastJobBegin())
                       + " ago");
            _log.error("Last job ended: " 
                       + DataHelper.formatDuration(_context.clock().now()-_context.jobQueue().getLastJobEnd())
                       + " ago");
            */
        _log.error("Ready and waiting jobs: " + _context.jobQueue().getReadyCount());
        _log.error("Job lag: " + _context.jobQueue().getMaxLag());
        _log.error("Participating tunnel count: " + _context.tunnelManager().getParticipatingCount());
        RateStat rs = _context.statManager().getRate("transport.sendProcessingTime");
        Rate r = null;
        if (rs != null)
            r = rs.getRate(60 * 1000);
        double processTime = (r != null ? r.getAverageValue() : 0);
        _log.error("1 minute send processing time: " + DataHelper.formatDuration((long) processTime));
        rs = _context.statManager().getRate("bw.sendBps");
        r = null;
        if (rs != null)
            r = rs.getRate(60 * 1000);
        double bps = (r != null ? r.getAverageValue() : 0);
        _log.error("Outbound send rate: " + DataHelper.formatSize((long) bps) + "Bps");
        long max = Runtime.getRuntime().maxMemory();
        long used = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
        _log.error("Memory: " + DataHelper.formatSize(used) + "B / " + DataHelper.formatSize(max) + 'B');
        if (_consecutiveErrors == 1) {
            _log.log(Log.CRIT, "Router appears hung, or there is severe network congestion.  Watchdog starts barking!");
            _context.router().eventLog().addEvent(EventLog.WATCHDOG);
            // This works on linux...
            // It won't on windows, and we can't call i2prouter.bat either, it does something
            // completely different...
            long now = _context.clock().now();
            if (now - _lastDump > MIN_DUMP_INTERVAL) {
                _lastDump = now;
                ThreadDump.dump(_context, 10);
            }
        }
    }
}
Also used : RateStat(net.i2p.stat.RateStat) Rate(net.i2p.stat.Rate)

Example 19 with Rate

use of net.i2p.stat.Rate in project i2p.i2p by i2p.

the class ProfileOrganizerRenderer method davg.

private String davg(DBHistory dbh, long rate, RateAverages ra) {
    RateStat rs = dbh.getFailedLookupRate();
    if (rs == null)
        return "0%";
    Rate r = rs.getRate(rate);
    if (r == null)
        return "0%";
    r.computeAverages(ra, false);
    if (ra.getTotalEventCount() <= 0)
        return "0%";
    double avg = 0.5 + 100 * ra.getAverage();
    return ((int) avg) + "%";
}
Also used : RateStat(net.i2p.stat.RateStat) Rate(net.i2p.stat.Rate)

Example 20 with Rate

use of net.i2p.stat.Rate in project i2p.i2p by i2p.

the class StatsGenerator method renderRate.

private void renderRate(String name, StringBuilder buf, boolean showAll) {
    RateStat rate = _context.statManager().getRate(name);
    String d = rate.getDescription();
    if (!"".equals(d)) {
        buf.append("<span class=\"statsLongName\"><i>");
        buf.append(d);
        buf.append("</i></span><br>");
    }
    if (rate.getLifetimeEventCount() <= 0) {
        buf.append("<ul><li class=\"noevents\">").append(_t("No lifetime events")).append("</li></ul>\n");
        return;
    }
    long now = _context.clock().now();
    long[] periods = rate.getPeriods();
    Arrays.sort(periods);
    buf.append("<ul>");
    for (int i = 0; i < periods.length; i++) {
        Rate curRate = rate.getRate(periods[i]);
        if (curRate.getLastCoalesceDate() <= curRate.getCreationDate())
            break;
        buf.append("<li>");
        renderPeriod(buf, periods[i], _t("rate"));
        if (curRate.getLastEventCount() > 0) {
            buf.append(_t("Average")).append(": ");
            buf.append(num(curRate.getAverageValue()));
            buf.append("; ");
            buf.append(_t("Highest average"));
            buf.append(": ");
            buf.append(num(curRate.getExtremeAverageValue()));
            buf.append(". ");
            // Don't bother to translate
            if (showAll) {
                buf.append("Highest total in a period: ");
                buf.append(num(curRate.getExtremeTotalValue()));
                buf.append(". ");
            }
            // Don't bother to translate
            if (showAll && curRate.getLifetimeTotalEventTime() > 0) {
                buf.append("Saturation: ");
                buf.append(pct(curRate.getLastEventSaturation()));
                buf.append("; Saturated limit: ");
                buf.append(num(curRate.getLastSaturationLimit()));
                buf.append("; Peak saturation: ");
                buf.append(pct(curRate.getExtremeEventSaturation()));
                buf.append("; Peak saturated limit: ");
                buf.append(num(curRate.getExtremeSaturationLimit()));
                buf.append(". ");
            }
            buf.append("<span class=\"nowrap\">");
            buf.append(ngettext("There was 1 event in this period.", "There were {0} events in this period.", (int) curRate.getLastEventCount()));
            buf.append("</span> <span class=\"nowrap\">");
            buf.append(_t("The period ended {0} ago.", DataHelper.formatDuration2(now - curRate.getLastCoalesceDate())));
            buf.append("</span>");
        } else {
            buf.append(" <i>").append(_t("No events")).append(" </i>");
        }
        long numPeriods = curRate.getLifetimePeriods();
        if (numPeriods > 0) {
            double avgFrequency = curRate.getLifetimeEventCount() / (double) numPeriods;
            buf.append("&nbsp;<span class=\"nowrap\">(").append(_t("Average event count")).append(": ");
            buf.append(num(avgFrequency));
            buf.append("; ").append(_t("Events in peak period")).append(": ");
            // This isn't really the highest event count, but the event count during the period with the highest total value.
            buf.append(curRate.getExtremeEventCount());
            buf.append(")</span>");
        }
        if (curRate.getSummaryListener() != null) {
            buf.append("<br><span class=\"statsViewGraphs\"><a href=\"graph?stat=").append(name).append('.').append(periods[i]);
            buf.append("&amp;w=600&amp;h=200\">").append(_t("Graph Data")).append("</a> - ");
            buf.append(" <a href=\"graph?stat=").append(name).append('.').append(periods[i]);
            buf.append("&amp;w=600&amp;h=200&amp;showEvents=true\">").append(_t("Graph Event Count")).append("</a></span>");
        // This can really blow up your browser if you click on it
        // buf.append(" - <a href=\"viewstat.jsp?stat=").append(name);
        // buf.append("&amp;period=").append(periods[i]);
        // buf.append("&amp;format=xml\">").append(_t("Export Data as XML")).append("</a>");
        }
        buf.append("</li>\n");
    }
    // Display the strict average
    buf.append("<li><b>").append(_t("Lifetime average value")).append(":</b> ");
    buf.append(num(rate.getLifetimeAverageValue()));
    buf.append(" (");
    buf.append(ngettext("1 event", "{0} events", (int) rate.getLifetimeEventCount()));
    buf.append(")<br></li>" + "</ul>" + "<br>\n");
}
Also used : RateStat(net.i2p.stat.RateStat) Rate(net.i2p.stat.Rate)

Aggregations

Rate (net.i2p.stat.Rate)29 RateStat (net.i2p.stat.RateStat)24 RateAverages (net.i2p.stat.RateAverages)6 Hash (net.i2p.data.Hash)5 RouterInfo (net.i2p.data.router.RouterInfo)5 PeerProfile (net.i2p.router.peermanager.PeerProfile)4 TreeSet (java.util.TreeSet)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 DBHistory (net.i2p.router.peermanager.DBHistory)2 HashSet (java.util.HashSet)1 StringTokenizer (java.util.StringTokenizer)1 RouterAddress (net.i2p.data.router.RouterAddress)1 CommSystemFacade (net.i2p.router.CommSystemFacade)1 RouterContext (net.i2p.router.RouterContext)1 TunnelInfo (net.i2p.router.TunnelInfo)1 MaskedIPSet (net.i2p.router.util.MaskedIPSet)1 SummaryListener (net.i2p.router.web.SummaryListener)1 FrequencyStat (net.i2p.stat.FrequencyStat)1 ConvertToHash (net.i2p.util.ConvertToHash)1