* Timers: Log cleanup

This commit is contained in:
zzz
2011-02-15 15:25:16 +00:00
parent 8fa49968ed
commit 4d59570df2
6 changed files with 24 additions and 15 deletions

View File

@ -5,10 +5,10 @@ import java.util.List;
import net.i2p.I2PAppContext; import net.i2p.I2PAppContext;
class Executor implements Runnable { class Executor implements Runnable {
private I2PAppContext _context; private final I2PAppContext _context;
private Log _log; private Log _log;
private final List _readyEvents; private final List _readyEvents;
private SimpleStore runn; private final SimpleStore runn;
public Executor(I2PAppContext ctx, Log log, List events, SimpleStore x) { public Executor(I2PAppContext ctx, Log log, List events, SimpleStore x) {
_context = ctx; _context = ctx;
@ -31,9 +31,10 @@ class Executor implements Runnable {
try { try {
evt.timeReached(); evt.timeReached();
} catch (Throwable t) { } catch (Throwable t) {
log("wtf, event borked: " + evt, t); log("Executing task " + evt + " exited unexpectedly, please report", t);
} }
long time = _context.clock().now() - before; long time = _context.clock().now() - before;
// FIXME _log won't be non-null unless we already had a CRIT
if ( (time > 1000) && (_log != null) && (_log.shouldLog(Log.WARN)) ) if ( (time > 1000) && (_log != null) && (_log.shouldLog(Log.WARN)) )
_log.warn("wtf, event execution took " + time + ": " + evt); _log.warn("wtf, event execution took " + time + ": " + evt);
} }

View File

@ -30,10 +30,10 @@ public class SimpleScheduler {
public static SimpleScheduler getInstance() { return _instance; } public static SimpleScheduler getInstance() { return _instance; }
private static final int MIN_THREADS = 2; private static final int MIN_THREADS = 2;
private static final int MAX_THREADS = 4; private static final int MAX_THREADS = 4;
private I2PAppContext _context; private final I2PAppContext _context;
private Log _log; private final Log _log;
private ScheduledThreadPoolExecutor _executor; private final ScheduledThreadPoolExecutor _executor;
private String _name; private final String _name;
private int _count; private int _count;
private final int _threads; private final int _threads;
@ -42,7 +42,6 @@ public class SimpleScheduler {
_context = I2PAppContext.getGlobalContext(); _context = I2PAppContext.getGlobalContext();
_log = _context.logManager().getLog(SimpleScheduler.class); _log = _context.logManager().getLog(SimpleScheduler.class);
_name = name; _name = name;
_count = 0;
long maxMemory = Runtime.getRuntime().maxMemory(); long maxMemory = Runtime.getRuntime().maxMemory();
_threads = (int) Math.max(MIN_THREADS, Math.min(MAX_THREADS, 1 + (maxMemory / (32*1024*1024)))); _threads = (int) Math.max(MIN_THREADS, Math.min(MAX_THREADS, 1 + (maxMemory / (32*1024*1024))));
_executor = new ScheduledThreadPoolExecutor(_threads, new CustomThreadFactory()); _executor = new ScheduledThreadPoolExecutor(_threads, new CustomThreadFactory());
@ -139,7 +138,7 @@ public class SimpleScheduler {
try { try {
_timedEvent.timeReached(); _timedEvent.timeReached();
} catch (Throwable t) { } catch (Throwable t) {
_log.log(Log.CRIT, _name + " wtf, event borked: " + _timedEvent, t); _log.log(Log.CRIT, _name + ": Scheduled task " + _timedEvent + " exited unexpectedly, please report", t);
} }
long time = System.currentTimeMillis() - before; long time = System.currentTimeMillis() - before;
if (time > 1000 && _log.shouldLog(Log.WARN)) if (time > 1000 && _log.shouldLog(Log.WARN))

View File

@ -14,6 +14,8 @@ import net.i2p.I2PAppContext;
* appropriate time. The method that is fired however should NOT block (otherwise * appropriate time. The method that is fired however should NOT block (otherwise
* they b0rk the timer). * they b0rk the timer).
* *
* WARNING - Deprecated.
* This is an inefficient mess. Use SimpleScheduler or SimpleTimer2 if possible.
*/ */
public class SimpleTimer { public class SimpleTimer {
private static final SimpleTimer _instance = new SimpleTimer(); private static final SimpleTimer _instance = new SimpleTimer();

View File

@ -29,10 +29,10 @@ public class SimpleTimer2 {
public static SimpleTimer2 getInstance() { return _instance; } public static SimpleTimer2 getInstance() { return _instance; }
private static final int MIN_THREADS = 2; private static final int MIN_THREADS = 2;
private static final int MAX_THREADS = 4; private static final int MAX_THREADS = 4;
private I2PAppContext _context; private final I2PAppContext _context;
private static Log _log; // static so TimedEvent can use it private static Log _log; // static so TimedEvent can use it
private ScheduledThreadPoolExecutor _executor; private final ScheduledThreadPoolExecutor _executor;
private String _name; private final String _name;
private int _count; private int _count;
private final int _threads; private final int _threads;
@ -223,7 +223,7 @@ public class SimpleTimer2 {
try { try {
timeReached(); timeReached();
} catch (Throwable t) { } catch (Throwable t) {
_log.log(Log.CRIT, _pool + " wtf, event borked: " + this, t); _log.log(Log.CRIT, _pool + ": Timed task " + this + " exited unexpectedly, please report", t);
} }
long time = System.currentTimeMillis() - before; long time = System.currentTimeMillis() - before;
if (time > 500 && _log.shouldLog(Log.WARN)) if (time > 500 && _log.shouldLog(Log.WARN))

View File

@ -1,9 +1,15 @@
2011-02-15 zzz
* i2psnark: Details link shuffle, mostly restore 0.8.3 behavior
* Profiles: Punish rejections more, in an attempt to spread the
load more through the network
* Timers: Log cleanup
2011-02-14 Mathiasdm 2011-02-14 Mathiasdm
* Fix headless issue without reboot * Fix headless issue without reboot
2011-02-13 zzz 2011-02-13 zzz
* Connect Client: Minor NPE fix cleanup * Connect Client: Minor NPE fix cleanup
* JobQueue: Prevet NPE at shutdown (thanks liberty) * JobQueue: Prevent NPE at shutdown (thanks liberty)
* GeoIP: Prevent startup NPE (ticket #413, thanks RN) * GeoIP: Prevent startup NPE (ticket #413, thanks RN)
* NetDB: Prevent ExpireLeaseJob NPE (thanks sponge) * NetDB: Prevent ExpireLeaseJob NPE (thanks sponge)
@ -21,6 +27,7 @@
* I2CP: Correctly close internal connections on the router side * I2CP: Correctly close internal connections on the router side
when closed by the client, was causing massive memory leak when closed by the client, was causing massive memory leak
for internal clients using lots of sessions (thanks sponge) for internal clients using lots of sessions (thanks sponge)
(ticket #397)
* i2psnark: * i2psnark:
- Improved magnet link parsing, use tr parameter if present - Improved magnet link parsing, use tr parameter if present
* i2ptunnel: Change shared clients default for new clients to false * i2ptunnel: Change shared clients default for new clients to false

View File

@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */ /** deprecated */
public final static String ID = "Monotone"; public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION; public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 11; public final static long BUILD = 12;
/** for example "-test" */ /** for example "-test" */
public final static String EXTRA = ""; public final static String EXTRA = "";