From 9cbed63ac7b11c2a6867213dd670be136de47f62 Mon Sep 17 00:00:00 2001 From: Jamie Doornbos Date: Mon, 19 Jan 2009 22:50:28 +0000 Subject: [PATCH] Share the Reporter implementation of PresentsInvoker so that the PresentsAuthInvoker is reported too. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5637 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../presents/server/PresentsAuthInvoker.java | 8 +- .../presents/server/PresentsInvoker.java | 86 +-------------- .../presents/server/ReportingInvoker.java | 104 ++++++++++++++++++ 3 files changed, 110 insertions(+), 88 deletions(-) create mode 100644 src/java/com/threerings/presents/server/ReportingInvoker.java diff --git a/src/java/com/threerings/presents/server/PresentsAuthInvoker.java b/src/java/com/threerings/presents/server/PresentsAuthInvoker.java index ce9a3a996..8f759721b 100644 --- a/src/java/com/threerings/presents/server/PresentsAuthInvoker.java +++ b/src/java/com/threerings/presents/server/PresentsAuthInvoker.java @@ -24,19 +24,17 @@ package com.threerings.presents.server; import com.google.inject.Inject; import com.google.inject.Singleton; -import com.samskivert.util.Invoker; - /** * A separate invoker thread on which we perform client authentication. This allows the normal * server operation to proceed even in the event that our authentication services have gone down * and attempts to authenticate cause long timeouts and blockage. */ @Singleton -public class PresentsAuthInvoker extends Invoker +public class PresentsAuthInvoker extends ReportingInvoker { - @Inject public PresentsAuthInvoker (PresentsDObjectMgr omgr) + @Inject public PresentsAuthInvoker (PresentsDObjectMgr omgr, ReportManager repmgr) { - super("presents.AuthInvoker", omgr); + super("presents.AuthInvoker", omgr, repmgr); setDaemon(true); } } diff --git a/src/java/com/threerings/presents/server/PresentsInvoker.java b/src/java/com/threerings/presents/server/PresentsInvoker.java index 8cfc9d359..47b62cd59 100644 --- a/src/java/com/threerings/presents/server/PresentsInvoker.java +++ b/src/java/com/threerings/presents/server/PresentsInvoker.java @@ -25,7 +25,6 @@ import com.google.inject.Inject; import com.google.inject.Singleton; import com.samskivert.util.Invoker; -import com.samskivert.util.StringUtil; import static com.threerings.presents.Log.log; @@ -33,18 +32,15 @@ import static com.threerings.presents.Log.log; * Extends the generic {@link Invoker} and integrates it a bit more into the Presents system. */ @Singleton -public class PresentsInvoker extends Invoker - implements ShutdownManager.Shutdowner, ReportManager.Reporter +public class PresentsInvoker extends ReportingInvoker + implements ShutdownManager.Shutdowner { @Inject public PresentsInvoker (PresentsDObjectMgr omgr, ShutdownManager shutmgr, ReportManager repmgr) { - super("presents.Invoker", omgr); + super("presents.Invoker", omgr, repmgr); _omgr = omgr; shutmgr.registerShutdowner(this); - if (PERF_TRACK) { - repmgr.registerReporter(this); - } } @Override // from Invoker @@ -54,73 +50,6 @@ public class PresentsInvoker extends Invoker _queue.append(new ShutdownUnit()); } - // from interface ReportManager.Reporter - public void appendReport (StringBuilder buf, long now, long sinceLast, boolean reset) - { - buf.append("* presents.util.Invoker:\n"); - int qsize = _queue.size(); - buf.append("- Queue size: ").append(qsize).append("\n"); - synchronized (this) { - buf.append("- Max queue size: ").append(_maxQueueSize).append("\n"); - buf.append("- Units executed: ").append(_unitsRun); - long runPerSec = (sinceLast == 0) ? 0 : 1000*_unitsRun/sinceLast; - buf.append(" (").append(runPerSec).append("/s)\n"); - if (_currentUnit != null) { - String uname = StringUtil.safeToString(_currentUnit); - buf.append("- Current unit: ").append(uname).append(" "); - buf.append(now-_currentUnitStart).append("ms\n"); - } - if (reset) { - _maxQueueSize = qsize; - _unitsRun = 0; - } - } - - if (PresentsDObjectMgr.UNIT_PROF_ENABLED) { - for (Object key : _tracker.keySet()) { - UnitProfile profile = _tracker.get(key); - if (key instanceof Class) { - key = StringUtil.shortClassName((Class)key); - } - buf.append(" ").append(key).append(" "); - buf.append(profile).append("\n"); - if (reset) { - profile.clear(); - } - } - } - } - - @Override // from Invoker - protected void willInvokeUnit (Unit unit, long start) - { - super.willInvokeUnit(unit, start); - - int queueSize = _queue.size(); - synchronized (this) { - // keep track of the largest queue size we've seen - if (queueSize > _maxQueueSize) { - _maxQueueSize = queueSize; - } - - // note the currently invoking unit - _currentUnit = unit; - _currentUnitStart = start; - } - } - - @Override // from Invoker - protected void didInvokeUnit (Unit unit, long start) - { - super.didInvokeUnit(unit, start); - - synchronized (this) { - // clear out our currently invoking unit - _currentUnit = null; - _currentUnitStart = 0L; - } - } - @Override // from Invoker protected void didShutdown () { @@ -234,13 +163,4 @@ public class PresentsInvoker extends Invoker /** The server we're working for. */ @Inject protected PresentsServer _server; - - /** The largest queue size since our last report. */ - protected long _maxQueueSize; - - /** Records the currently invoking unit. */ - protected Object _currentUnit; - - /** The time at which our current unit started. */ - protected long _currentUnitStart; } diff --git a/src/java/com/threerings/presents/server/ReportingInvoker.java b/src/java/com/threerings/presents/server/ReportingInvoker.java new file mode 100644 index 000000000..36233f0f0 --- /dev/null +++ b/src/java/com/threerings/presents/server/ReportingInvoker.java @@ -0,0 +1,104 @@ +// +// $Id$ + +package com.threerings.presents.server; + +import com.samskivert.util.Invoker; +import com.samskivert.util.RunQueue; +import com.samskivert.util.StringUtil; + +/** + * Extends invoker with a reporter implementation that shows current queue status, maximum + * historical size and the results of unit profiling if enabled. + */ +public class ReportingInvoker extends Invoker + implements ReportManager.Reporter +{ + /** + * Creates a new reporting invoker. The instance will be registered with the report manager + * if profiling is enabled ({@link Invoker#PERF_TRACK}). + */ + public ReportingInvoker (String name, RunQueue resultsQueue, ReportManager repmgr) + { + super(name, resultsQueue); + if (PERF_TRACK) { + repmgr.registerReporter(this); + } + } + + // from interface ReportManager.Reporter + public void appendReport (StringBuilder buf, long now, long sinceLast, boolean reset) + { + buf.append("* " + getName() + ":\n"); + int qsize = _queue.size(); + buf.append("- Queue size: ").append(qsize).append("\n"); + synchronized (this) { + buf.append("- Max queue size: ").append(_maxQueueSize).append("\n"); + buf.append("- Units executed: ").append(_unitsRun); + long runPerSec = (sinceLast == 0) ? 0 : 1000*_unitsRun/sinceLast; + buf.append(" (").append(runPerSec).append("/s)\n"); + if (_currentUnit != null) { + String uname = StringUtil.safeToString(_currentUnit); + buf.append("- Current unit: ").append(uname).append(" "); + buf.append(now-_currentUnitStart).append("ms\n"); + } + if (reset) { + _maxQueueSize = qsize; + _unitsRun = 0; + } + } + + if (PresentsDObjectMgr.UNIT_PROF_ENABLED) { + for (Object key : _tracker.keySet()) { + UnitProfile profile = _tracker.get(key); + if (key instanceof Class) { + key = StringUtil.shortClassName((Class)key); + } + buf.append(" ").append(key).append(" "); + buf.append(profile).append("\n"); + if (reset) { + profile.clear(); + } + } + } + } + + @Override // from Invoker + protected void willInvokeUnit (Unit unit, long start) + { + super.willInvokeUnit(unit, start); + + int queueSize = _queue.size(); + synchronized (this) { + // keep track of the largest queue size we've seen + if (queueSize > _maxQueueSize) { + _maxQueueSize = queueSize; + } + + // note the currently invoking unit + _currentUnit = unit; + _currentUnitStart = start; + } + } + + @Override // from Invoker + protected void didInvokeUnit (Unit unit, long start) + { + super.didInvokeUnit(unit, start); + + synchronized (this) { + // clear out our currently invoking unit + _currentUnit = null; + _currentUnitStart = 0L; + } + } + + /** The largest queue size since our last report. */ + protected long _maxQueueSize; + + /** Records the currently invoking unit. */ + protected Object _currentUnit; + + /** The time at which our current unit started. */ + protected long _currentUnitStart; +}