Changeset ff4d575


Ignore:
Timestamp:
Dec 4, 2015 9:25:25 PM (5 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
997ef73
Parents:
68c3121
Message:

Profiles:

  • Change doubles to floats to save memory
  • Move fields to top

Sybil tool: Tweaks

Files:
3 edited

Legend:

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

    r68c3121 rff4d575  
    391391        }
    392392        Collections.sort(foo, new FooComparator(oc));
     393        boolean found = false;
    393394        DecimalFormat fmt = new DecimalFormat("#0.00");
    394395        for (Integer ii : foo) {
     
    410411                if ((ip[2] & 0xff) != i2)
    411412                    continue;
     413                found = true;
    412414                renderRouterInfo(buf, info, null, false, false);
    413415                double point = POINTS24 * (count - 1);
     
    415417            }
    416418        }
     419        if (!found)
     420            buf.append("<p>None</p>");
    417421        out.write(buf.toString());
    418422        out.flush();
     
    438442        }
    439443        Collections.sort(foo, new FooComparator(oc));
     444        boolean found = false;
    440445        DecimalFormat fmt = new DecimalFormat("#0.00");
    441446        for (Integer ii : foo) {
     
    454459                if ((ip[1] & 0xff) != i1)
    455460                    continue;
     461                found = true;
    456462                renderRouterInfo(buf, info, null, false, false);
    457463                double point = POINTS16 * (count - 1);
     
    459465            }
    460466        }
     467        if (!found)
     468            buf.append("<p>None</p>");
    461469        out.write(buf.toString());
    462470        out.flush();
  • router/java/src/net/i2p/router/peermanager/PeerProfile.java

    r68c3121 rff4d575  
    4141    private long _lastFailedSend;
    4242    private long _lastHeardFrom;
    43     private double _tunnelTestResponseTimeAvg;
     43    private float _tunnelTestResponseTimeAvg;
    4444    // periodic rates
    4545    //private RateStat _sendSuccessSize = null;
     
    5555    private int _integrationBonus;
    5656    // calculation values
    57     private double _speedValue;
    58     private double _capacityValue;
    59     private double _integrationValue;
     57    // floats to save some space
     58    private float _speedValue;
     59    private float _capacityValue;
     60    private float _integrationValue;
    6061    private boolean _isFailing;
    6162    // new calculation values, to be updated
    62     private double _speedValueNew;
    63     private double _capacityValueNew;
     63    // floats to save some space
     64    private float _speedValueNew;
     65    private float _capacityValueNew;
    6466    // are we in coalescing state?
    6567    private boolean _coalescing;
     
    7274    //private int _consecutiveBanlists;
    7375    private final int _distance;
     76
     77    /** keep track of the fastest 3 throughputs */
     78    private static final int THROUGHPUT_COUNT = 3;
     79    /**
     80     * fastest 1 minute throughput, in bytes per minute, ordered with fastest
     81     * first.  this is not synchronized, as we don't *need* perfection, and we only
     82     * reorder/insert values on coallesce
     83     */
     84    private final float _peakThroughput[] = new float[THROUGHPUT_COUNT];
     85    private volatile long _peakThroughputCurrentTotal;
     86    private final float _peakTunnelThroughput[] = new float[THROUGHPUT_COUNT];
     87    /** total number of bytes pushed through a single tunnel in a 1 minute period */
     88    private final float _peakTunnel1mThroughput[] = new float[THROUGHPUT_COUNT];
     89    /** once a day, on average, cut the measured throughtput values in half */
     90    /** let's try once an hour times 3/4 */
     91    private static final int DROP_PERIOD_MINUTES = 60;
     92    private static final float DEGRADE_FACTOR = 0.75f;
     93    private long _lastCoalesceDate = System.currentTimeMillis();
    7494   
    7595    /**
     
    301321     *
    302322     */
    303     public double getSpeedValue() { return _speedValue; }
     323    public float getSpeedValue() { return _speedValue; }
    304324    /**
    305325     * How many tunnels do we think this peer can handle over the next hour?
    306326     *
    307327     */
    308     public double getCapacityValue() { return _capacityValue; }
     328    public float getCapacityValue() { return _capacityValue; }
    309329    /**
    310330     * How well integrated into the network is this peer (as measured by how much they've
     
    312332     *
    313333     */
    314     public double getIntegrationValue() { return _integrationValue; }
     334    public float getIntegrationValue() { return _integrationValue; }
    315335    /**
    316336     * is this peer actively failing (aka not worth touching)?
     
    319339    public boolean getIsFailing() { return _isFailing; }
    320340
    321     public double getTunnelTestTimeAverage() { return _tunnelTestResponseTimeAvg; }
    322     void setTunnelTestTimeAverage(double avg) { _tunnelTestResponseTimeAvg = avg; }
     341    public float getTunnelTestTimeAverage() { return _tunnelTestResponseTimeAvg; }
     342    void setTunnelTestTimeAverage(float avg) { _tunnelTestResponseTimeAvg = avg; }
    323343   
    324344    void updateTunnelTestTimeAverage(long ms) {
     
    328348        // weighted since we want to let the average grow quickly and shrink slowly
    329349        if (ms < _tunnelTestResponseTimeAvg)
    330             _tunnelTestResponseTimeAvg = 0.95*_tunnelTestResponseTimeAvg + .05*ms;
     350            _tunnelTestResponseTimeAvg = 0.95f * _tunnelTestResponseTimeAvg + .05f * ms;
    331351        else
    332             _tunnelTestResponseTimeAvg = 0.75*_tunnelTestResponseTimeAvg + .25*ms;
     352            _tunnelTestResponseTimeAvg = 0.75f * _tunnelTestResponseTimeAvg + .25f * ms;
    333353       
    334354        if (_log.shouldLog(Log.INFO))
     
    337357    }
    338358
    339     /** keep track of the fastest 3 throughputs */
    340     private static final int THROUGHPUT_COUNT = 3;
    341     /**
    342      * fastest 1 minute throughput, in bytes per minute, ordered with fastest
    343      * first.  this is not synchronized, as we don't *need* perfection, and we only
    344      * reorder/insert values on coallesce
    345      */
    346     private final double _peakThroughput[] = new double[THROUGHPUT_COUNT];
    347     private volatile long _peakThroughputCurrentTotal;
    348     public double getPeakThroughputKBps() {
    349         double rv = 0;
     359    public float getPeakThroughputKBps() {
     360        float rv = 0;
    350361        for (int i = 0; i < THROUGHPUT_COUNT; i++)
    351362            rv += _peakThroughput[i];
    352         rv /= (60d*1024d*THROUGHPUT_COUNT);
     363        rv /= (60 * 1024 * THROUGHPUT_COUNT);
    353364        return rv;
    354365    }
    355     public void setPeakThroughputKBps(double kBps) {
     366    public void setPeakThroughputKBps(float kBps) {
    356367        _peakThroughput[0] = kBps*60*1024;
    357368        //for (int i = 0; i < THROUGHPUT_COUNT; i++)
     
    360371    void dataPushed(int size) { _peakThroughputCurrentTotal += size; }
    361372   
    362     private final double _peakTunnelThroughput[] = new double[THROUGHPUT_COUNT];
    363373    /** the tunnel pushed that much data in its lifetime */
    364374    void tunnelDataTransferred(long tunnelByteLifetime) {
    365         double lowPeak = _peakTunnelThroughput[THROUGHPUT_COUNT-1];
     375        float lowPeak = _peakTunnelThroughput[THROUGHPUT_COUNT-1];
    366376        if (tunnelByteLifetime > lowPeak) {
    367377            synchronized (_peakTunnelThroughput) {
     
    377387        }
    378388    }
    379     public double getPeakTunnelThroughputKBps() {
    380         double rv = 0;
     389    public float getPeakTunnelThroughputKBps() {
     390        float rv = 0;
    381391        for (int i = 0; i < THROUGHPUT_COUNT; i++)
    382392            rv += _peakTunnelThroughput[i];
    383         rv /= (10d*60d*1024d*THROUGHPUT_COUNT);
     393        rv /= (10 * 60 * 1024 * THROUGHPUT_COUNT);
    384394        return rv;
    385395    }
    386     public void setPeakTunnelThroughputKBps(double kBps) {
    387         _peakTunnelThroughput[0] = kBps*60d*10d*1024d;
    388     }
    389    
    390     /** total number of bytes pushed through a single tunnel in a 1 minute period */
    391     private final double _peakTunnel1mThroughput[] = new double[THROUGHPUT_COUNT];
     396    public void setPeakTunnelThroughputKBps(float kBps) {
     397        _peakTunnelThroughput[0] = kBps * (60 * 10 * 1024);
     398    }
     399   
    392400    /** the tunnel pushed that much data in a 1 minute period */
    393401    void dataPushed1m(int size) {
    394         double lowPeak = _peakTunnel1mThroughput[THROUGHPUT_COUNT-1];
     402        float lowPeak = _peakTunnel1mThroughput[THROUGHPUT_COUNT-1];
    395403        if (size > lowPeak) {
    396404            synchronized (_peakTunnel1mThroughput) {
     
    420428     *         once a day by coalesceThroughput(). This seems way too seldom.
    421429     */
    422     public double getPeakTunnel1mThroughputKBps() {
    423         double rv = 0;
     430    public float getPeakTunnel1mThroughputKBps() {
     431        float rv = 0;
    424432        for (int i = 0; i < THROUGHPUT_COUNT; i++)
    425433            rv += _peakTunnel1mThroughput[i];
    426         rv /= (60d*1024d*THROUGHPUT_COUNT);
     434        rv /= (60 * 1024 * THROUGHPUT_COUNT);
    427435        return rv;
    428436    }
    429     public void setPeakTunnel1mThroughputKBps(double kBps) {
     437    public void setPeakTunnel1mThroughputKBps(float kBps) {
    430438        _peakTunnel1mThroughput[0] = kBps*60*1024;
    431439    }
     
    500508    }
    501509
    502     /** once a day, on average, cut the measured throughtput values in half */
    503     /** let's try once an hour times 3/4 */
    504     private static final int DROP_PERIOD_MINUTES = 60;
    505     private static final double DEGRADE_FACTOR = 0.75;
    506     private long _lastCoalesceDate = System.currentTimeMillis();
    507510    private void coalesceThroughput() {
    508511        long now = System.currentTimeMillis();
     
    510513        if (measuredPeriod >= 60*1000) {
    511514            long tot = _peakThroughputCurrentTotal;
    512             double lowPeak = _peakThroughput[THROUGHPUT_COUNT-1];
     515            float lowPeak = _peakThroughput[THROUGHPUT_COUNT-1];
    513516            if (tot > lowPeak) {
    514517                for (int i = 0; i < THROUGHPUT_COUNT; i++) {
     
    594597    }
    595598   
    596     private double calculateSpeed() { return SpeedCalculator.calc(this); }
    597     private double calculateCapacity() { return CapacityCalculator.calc(this); }
    598     private double calculateIntegration() { return IntegrationCalculator.calc(this); }
     599    private float calculateSpeed() { return (float) SpeedCalculator.calc(this); }
     600    private float calculateCapacity() { return (float) CapacityCalculator.calc(this); }
     601    private float calculateIntegration() { return (float) IntegrationCalculator.calc(this); }
    599602    /** deprecated - unused - always false */
    600603    private boolean calculateIsFailing() { return false; }
  • router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java

    r68c3121 rff4d575  
    171171   
    172172    /** @since 0.8.5 */
    173     private static void add(StringBuilder buf, String name, double val, String description) {
     173    private static void add(StringBuilder buf, String name, float val, String description) {
    174174        buf.append("# ").append(name).append(NL).append("# ").append(description).append(NL);
    175175        buf.append(name).append('=').append(val).append(NL).append(NL);
     
    273273            profile.setLastSendFailed(getLong(props, "lastFailedSend"));
    274274            profile.setLastHeardFrom(getLong(props, "lastHeardFrom"));
    275             profile.setTunnelTestTimeAverage(getDouble(props, "tunnelTestTimeAverage"));
    276             profile.setPeakThroughputKBps(getDouble(props, "tunnelPeakThroughput"));
    277             profile.setPeakTunnelThroughputKBps(getDouble(props, "tunnelPeakTunnelThroughput"));
    278             profile.setPeakTunnel1mThroughputKBps(getDouble(props, "tunnelPeakTunnel1mThroughput"));
     275            profile.setTunnelTestTimeAverage(getFloat(props, "tunnelTestTimeAverage"));
     276            profile.setPeakThroughputKBps(getFloat(props, "tunnelPeakThroughput"));
     277            profile.setPeakTunnelThroughputKBps(getFloat(props, "tunnelPeakTunnelThroughput"));
     278            profile.setPeakTunnel1mThroughputKBps(getFloat(props, "tunnelPeakTunnel1mThroughput"));
    279279           
    280280            profile.getTunnelHistory().load(props);
     
    369369            try {
    370370                return Long.parseLong(val);
    371             } catch (NumberFormatException nfe) {
    372                 return 0;
    373             }
     371            } catch (NumberFormatException nfe) {}
    374372        }
    375373        return 0;
    376374    }
    377375
    378     private final static double getDouble(Properties props, String key) {
     376    private final static float getFloat(Properties props, String key) {
    379377        String val = props.getProperty(key);
    380378        if (val != null) {
    381379            try {
    382                 return Double.parseDouble(val);
    383             } catch (NumberFormatException nfe) {
    384                 return 0.0;
    385             }
    386         }
    387         return 0.0;
     380                return Float.parseFloat(val);
     381            } catch (NumberFormatException nfe) {}
     382        }
     383        return 0.0f;
    388384    }
    389385   
Note: See TracChangeset for help on using the changeset viewer.