Reduce the memory footprint of Rate objects by changing longs to ints and doubles to floats

This commit is contained in:
zab2
2015-11-06 20:19:43 +00:00
parent 6bb156a436
commit ca4642e0f0

View File

@@ -14,19 +14,19 @@ import net.i2p.data.DataHelper;
*/ */
public class Rate { public class Rate {
//private final static Log _log = new Log(Rate.class); //private final static Log _log = new Log(Rate.class);
private double _currentTotalValue; private float _currentTotalValue;
// was long, save space // was long, save space
private int _currentEventCount; private int _currentEventCount;
private long _currentTotalEventTime; private int _currentTotalEventTime;
private double _lastTotalValue; private float _lastTotalValue;
// was long, save space // was long, save space
private int _lastEventCount; private int _lastEventCount;
private long _lastTotalEventTime; private int _lastTotalEventTime;
private double _extremeTotalValue; private float _extremeTotalValue;
// was long, save space // was long, save space
private int _extremeEventCount; private int _extremeEventCount;
private long _extremeTotalEventTime; private int _extremeTotalEventTime;
private double _lifetimeTotalValue; private float _lifetimeTotalValue;
private long _lifetimeEventCount; private long _lifetimeEventCount;
private long _lifetimeTotalEventTime; private long _lifetimeTotalEventTime;
private RateSummaryListener _summaryListener; private RateSummaryListener _summaryListener;
@@ -227,10 +227,10 @@ public class Rate {
// ok ok, lets coalesce // ok ok, lets coalesce
// how much were we off by? (so that we can sample down the measured values) // how much were we off by? (so that we can sample down the measured values)
double periodFactor = measuredPeriod / (double)_period; float periodFactor = measuredPeriod / (float)_period;
_lastTotalValue = _currentTotalValue / periodFactor; _lastTotalValue = _currentTotalValue / periodFactor;
_lastEventCount = (int) (0.499999 + (_currentEventCount / periodFactor)); _lastEventCount = (int) (0.499999 + (_currentEventCount / periodFactor));
_lastTotalEventTime = (long) (_currentTotalEventTime / periodFactor); _lastTotalEventTime = (int) (_currentTotalEventTime / periodFactor);
_lastCoalesceDate = now; _lastCoalesceDate = now;
if (_currentEventCount == 0) if (_currentEventCount == 0)
correctedTotalValue = 0; correctedTotalValue = 0;
@@ -244,7 +244,7 @@ public class Rate {
_extremeTotalEventTime = _lastTotalEventTime; _extremeTotalEventTime = _lastTotalEventTime;
} }
_currentTotalValue = 0.0D; _currentTotalValue = 0.0f;
_currentEventCount = 0; _currentEventCount = 0;
_currentTotalEventTime = 0; _currentTotalEventTime = 0;
} }
@@ -505,16 +505,16 @@ public class Rate {
_period = PersistenceHelper.getInt(props, prefix, ".period"); _period = PersistenceHelper.getInt(props, prefix, ".period");
_creationDate = PersistenceHelper.getLong(props, prefix, ".creationDate"); _creationDate = PersistenceHelper.getLong(props, prefix, ".creationDate");
_lastCoalesceDate = PersistenceHelper.getLong(props, prefix, ".lastCoalesceDate"); _lastCoalesceDate = PersistenceHelper.getLong(props, prefix, ".lastCoalesceDate");
_currentTotalValue = PersistenceHelper.getDouble(props, prefix, ".currentTotalValue"); _currentTotalValue = (float)PersistenceHelper.getDouble(props, prefix, ".currentTotalValue");
_currentEventCount = PersistenceHelper.getInt(props, prefix, ".currentEventCount"); _currentEventCount = PersistenceHelper.getInt(props, prefix, ".currentEventCount");
_currentTotalEventTime = PersistenceHelper.getLong(props, prefix, ".currentTotalEventTime"); _currentTotalEventTime = (int)PersistenceHelper.getLong(props, prefix, ".currentTotalEventTime");
_lastTotalValue = PersistenceHelper.getDouble(props, prefix, ".lastTotalValue"); _lastTotalValue = (float)PersistenceHelper.getDouble(props, prefix, ".lastTotalValue");
_lastEventCount = PersistenceHelper.getInt(props, prefix, ".lastEventCount"); _lastEventCount = PersistenceHelper.getInt(props, prefix, ".lastEventCount");
_lastTotalEventTime = PersistenceHelper.getLong(props, prefix, ".lastTotalEventTime"); _lastTotalEventTime = (int)PersistenceHelper.getLong(props, prefix, ".lastTotalEventTime");
_extremeTotalValue = PersistenceHelper.getDouble(props, prefix, ".extremeTotalValue"); _extremeTotalValue = (float)PersistenceHelper.getDouble(props, prefix, ".extremeTotalValue");
_extremeEventCount = PersistenceHelper.getInt(props, prefix, ".extremeEventCount"); _extremeEventCount = PersistenceHelper.getInt(props, prefix, ".extremeEventCount");
_extremeTotalEventTime = PersistenceHelper.getLong(props, prefix, ".extremeTotalEventTime"); _extremeTotalEventTime = (int)PersistenceHelper.getLong(props, prefix, ".extremeTotalEventTime");
_lifetimeTotalValue = PersistenceHelper.getDouble(props, prefix, ".lifetimeTotalValue"); _lifetimeTotalValue = (float)PersistenceHelper.getDouble(props, prefix, ".lifetimeTotalValue");
_lifetimeEventCount = PersistenceHelper.getLong(props, prefix, ".lifetimeEventCount"); _lifetimeEventCount = PersistenceHelper.getLong(props, prefix, ".lifetimeEventCount");
_lifetimeTotalEventTime = PersistenceHelper.getLong(props, prefix, ".lifetimeTotalEventTime"); _lifetimeTotalEventTime = PersistenceHelper.getLong(props, prefix, ".lifetimeTotalEventTime");