big ol' memory, cpu usage, and shutdown handling update. main changes include:

* rather than have all jobs created hooked into the clock for offset updates, have the jobQueue stay hooked up and update any active jobs accordingly (killing a memory leak of a JobTiming objects - one per job)
* dont go totally insane during shutdown and log like mad (though the clientApp things still log like mad, since they don't know the router is going down)
* adjust memory buffer sizes based on real world values so we don't have to expand/contract a lot
* dont display things that are completely useless (who cares what the first 32 bytes of a public key are?)
* reduce temporary object creation
* use more efficient collections at times
* on shutdown, log some state information (ready/timed jobs, pending messages, etc)
* explicit GC every 10 jobs.  yeah, not efficient, but just for now we'll keep 'er in there
* only reread the router config file if it changes (duh)
This commit is contained in:
jrandom
2004-05-16 04:54:50 +00:00
committed by zzz
parent 8c6bf5a1cc
commit ff0023a889
32 changed files with 195 additions and 99 deletions

View File

@ -69,10 +69,10 @@ public class PrivateKey extends DataStructureImpl {
buf.append("null key");
} else {
buf.append("size: ").append(_data.length);
int len = 32;
if (len > _data.length) len = _data.length;
buf.append(" first ").append(len).append(" bytes: ");
buf.append(DataHelper.toString(_data, len));
//int len = 32;
//if (len > _data.length) len = _data.length;
//buf.append(" first ").append(len).append(" bytes: ");
//buf.append(DataHelper.toString(_data, len));
}
buf.append("]");
return buf.toString();

View File

@ -68,10 +68,10 @@ public class PublicKey extends DataStructureImpl {
buf.append("null key");
} else {
buf.append("size: ").append(_data.length);
int len = 32;
if (len > _data.length) len = _data.length;
buf.append(" first ").append(len).append(" bytes: ");
buf.append(DataHelper.toString(_data, len));
//int len = 32;
//if (len > _data.length) len = _data.length;
//buf.append(" first ").append(len).append(" bytes: ");
//buf.append(DataHelper.toString(_data, len));
}
buf.append("]");
return buf.toString();

View File

@ -422,7 +422,7 @@ public class RouterInfo extends DataStructureImpl {
public String toString() {
if (_stringified != null) return _stringified;
StringBuffer buf = new StringBuffer(128);
StringBuffer buf = new StringBuffer(5*1024);
buf.append("[RouterInfo: ");
buf.append("\n\tIdentity: ").append(getIdentity());
buf.append("\n\tSignature: ").append(getSignature());

View File

@ -67,10 +67,10 @@ public class SessionKey extends DataStructureImpl {
buf.append("null key");
} else {
buf.append("size: ").append(_data.length);
int len = 32;
if (len > _data.length) len = _data.length;
buf.append(" first ").append(len).append(" bytes: ");
buf.append(DataHelper.toString(_data, len));
//int len = 32;
//if (len > _data.length) len = _data.length;
//buf.append(" first ").append(len).append(" bytes: ");
//buf.append(DataHelper.toString(_data, len));
}
buf.append("]");
return buf.toString();

View File

@ -73,10 +73,10 @@ public class Signature extends DataStructureImpl {
buf.append("null signature");
} else {
buf.append("size: ").append(_data.length);
int len = 32;
if (len > _data.length) len = _data.length;
buf.append(" first ").append(len).append(" bytes: ");
buf.append(DataHelper.toString(_data, len));
//int len = 32;
//if (len > _data.length) len = _data.length;
//buf.append(" first ").append(len).append(" bytes: ");
//buf.append(DataHelper.toString(_data, len));
}
buf.append("]");
return buf.toString();

View File

@ -69,10 +69,10 @@ public class SigningPrivateKey extends DataStructureImpl {
buf.append("null key");
} else {
buf.append("size: ").append(_data.length);
int len = 32;
if (len > _data.length) len = _data.length;
buf.append(" first ").append(len).append(" bytes: ");
buf.append(DataHelper.toString(_data, len));
//int len = 32;
//if (len > _data.length) len = _data.length;
//buf.append(" first ").append(len).append(" bytes: ");
//buf.append(DataHelper.toString(_data, len));
}
buf.append("]");
return buf.toString();

View File

@ -69,10 +69,10 @@ public class SigningPublicKey extends DataStructureImpl {
buf.append("null key");
} else {
buf.append("size: ").append(_data.length);
int len = 32;
if (len > _data.length) len = _data.length;
buf.append(" first ").append(len).append(" bytes: ");
buf.append(DataHelper.toString(_data, len));
//int len = 32;
//if (len > _data.length) len = _data.length;
//buf.append(" first ").append(len).append(" bytes: ");
//buf.append(DataHelper.toString(_data, len));
}
buf.append("]");
return buf.toString();

View File

@ -350,7 +350,7 @@ public class Rate {
}
public void store(OutputStream out, String prefix) throws IOException {
StringBuffer buf = new StringBuffer(2048);
StringBuffer buf = new StringBuffer(16*1048);
PersistenceHelper.add(buf, prefix, ".period", "Number of milliseconds in the period", _period);
PersistenceHelper.add(buf, prefix, ".creationDate",
"When was this rate created? (milliseconds since the epoch, GMT)", _creationDate);

View File

@ -76,7 +76,7 @@ public class RateStat {
private final static String NL = System.getProperty("line.separator");
public String toString() {
StringBuffer buf = new StringBuffer(512);
StringBuffer buf = new StringBuffer(4096);
buf.append(getGroupName()).append('.').append(getName()).append(": ").append(getDescription()).append('\n');
long periods[] = getPeriods();
Arrays.sort(periods);
@ -103,7 +103,7 @@ public class RateStat {
}
public void store(OutputStream out, String prefix) throws IOException {
StringBuffer buf = new StringBuffer(128);
StringBuffer buf = new StringBuffer(1024);
buf.append(NL);
buf.append("################################################################################").append(NL);
buf.append("# Rate: ").append(_groupName).append(": ").append(_statName).append(NL);
@ -112,7 +112,7 @@ public class RateStat {
out.write(buf.toString().getBytes());
buf = null;
for (int i = 0; i < _rates.length; i++) {
StringBuffer rbuf = new StringBuffer(256);
StringBuffer rbuf = new StringBuffer(1024);
rbuf.append("#######").append(NL);
rbuf.append("# Period : ").append(DataHelper.formatDuration(_rates[i].getPeriod())).append(" for rate ")
.append(_groupName).append(" - ").append(_statName).append(NL);

View File

@ -80,18 +80,20 @@ public class StatManager {
}
public void coallesceStats() {
for (Iterator iter = getFrequencyNames().iterator(); iter.hasNext();) {
String name = (String) iter.next();
FrequencyStat stat = getFrequency(name);
if (stat != null) {
stat.coallesceStats();
synchronized (_frequencyStats) {
for (Iterator iter = _frequencyStats.values().iterator(); iter.hasNext();) {
FrequencyStat stat = (FrequencyStat)iter.next();
if (stat != null) {
stat.coallesceStats();
}
}
}
for (Iterator iter = getRateNames().iterator(); iter.hasNext();) {
String name = (String) iter.next();
RateStat stat = getRate(name);
if (stat != null) {
stat.coallesceStats();
synchronized (_rateStats) {
for (Iterator iter = _rateStats.values().iterator(); iter.hasNext();) {
RateStat stat = (RateStat)iter.next();
if (stat != null) {
stat.coallesceStats();
}
}
}
}
@ -105,11 +107,11 @@ public class StatManager {
}
public Set getFrequencyNames() {
return Collections.unmodifiableSet(new HashSet(_frequencyStats.keySet()));
return new HashSet(_frequencyStats.keySet());
}
public Set getRateNames() {
return Collections.unmodifiableSet(new HashSet(_rateStats.keySet()));
return new HashSet(_rateStats.keySet());
}
/** is the given stat a monitored rate? */

View File

@ -18,7 +18,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
@ -68,7 +68,7 @@ public class LogManager {
private String _location;
private List _records;
private Set _limits;
private List _limits;
private Map _logs;
private LogWriter _writer;
@ -88,7 +88,7 @@ public class LogManager {
public LogManager(I2PAppContext context) {
_displayOnScreen = true;
_records = new ArrayList();
_limits = new HashSet();
_limits = new ArrayList(128);
_logs = new HashMap(128);
_defaultLimit = Log.DEBUG;
_configLastRead = 0;
@ -197,7 +197,6 @@ public class LogManager {
//
private void loadConfig() {
Properties p = new Properties();
File cfgFile = new File(_location);
if ((_configLastRead > 0) && (_configLastRead >= cfgFile.lastModified())) {
if (_log.shouldLog(Log.DEBUG))
@ -207,6 +206,7 @@ public class LogManager {
if (_log.shouldLog(Log.DEBUG))
_log.debug("Loading config from " + _location);
}
Properties p = new Properties();
FileInputStream fis = null;
try {
fis = new FileInputStream(cfgFile);
@ -293,7 +293,8 @@ public class LogManager {
LogLimit lim = new LogLimit(name, Log.getLevel(val));
//_log.debug("Limit found for " + name + " as " + val);
synchronized (_limits) {
_limits.add(lim);
if (!_limits.contains(lim))
_limits.add(lim);
}
}
}
@ -366,10 +367,10 @@ public class LogManager {
}
private List getLimits(Log log) {
ArrayList limits = new ArrayList();
ArrayList limits = new ArrayList(4);
synchronized (_limits) {
for (Iterator iter = _limits.iterator(); iter.hasNext();) {
LogLimit limit = (LogLimit) iter.next();
for (int i = 0; i < _limits.size(); i++) {
LogLimit limit = (LogLimit)_limits.get(i);
if (limit.matches(log)) limits.add(limit);
}
}
@ -395,6 +396,8 @@ public class LogManager {
List _removeAll() {
List vals = null;
synchronized (_records) {
if (_records.size() <= 0)
return null;
vals = new ArrayList(_records);
_records.clear();
}
@ -431,7 +434,7 @@ public class LogManager {
}
public void shutdown() {
_log.log(Log.CRIT, "Shutting down logger", new Exception("Shutdown"));
_log.log(Log.CRIT, "Shutting down logger");
_writer.flushRecords();
}

View File

@ -27,7 +27,7 @@ class LogRecordFormatter {
private final static int MAX_PRIORITY_LENGTH = 5;
public static String formatRecord(LogManager manager, LogRecord rec) {
StringBuffer buf = new StringBuffer();
StringBuffer buf = new StringBuffer(1024);
char format[] = manager._getFormat();
for (int i = 0; i < format.length; ++i) {
switch ((int) format[i]) {

View File

@ -53,6 +53,7 @@ class LogWriter implements Runnable {
public void flushRecords() {
try {
List records = _manager._removeAll();
if (records == null) return;
for (int i = 0; i < records.size(); i++) {
LogRecord rec = (LogRecord) records.get(i);
writeRecord(rec);
@ -64,13 +65,10 @@ class LogWriter implements Runnable {
System.err.println("Error flushing the records");
}
}
records.clear();
try {
Thread.sleep(30);
} catch (InterruptedException ie) {
}
} catch (Throwable t) {
t.printStackTrace();
} finally {
try { Thread.sleep(100); } catch (InterruptedException ie) {}
}
long now = Clock.getInstance().now();
if (now - _lastReadConfig > CONFIG_READ_ITERVAL) {