Track max queue size and total events dispatched in an extensible stats
object that can be (and is) provided to external callers. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3688 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -56,6 +56,20 @@ import com.threerings.presents.dobj.*;
|
|||||||
public class PresentsDObjectMgr
|
public class PresentsDObjectMgr
|
||||||
implements RootDObjectManager, RunQueue, PresentsServer.Reporter
|
implements RootDObjectManager, RunQueue, PresentsServer.Reporter
|
||||||
{
|
{
|
||||||
|
/** Contains operational statistics that are tracked by the
|
||||||
|
* distributed object manager for a particular period of time (e.g. 5
|
||||||
|
* minutes). The snapshot for the most recently completed period can
|
||||||
|
* be requested via {@link #getStats()}. . */
|
||||||
|
public static class Stats
|
||||||
|
{
|
||||||
|
/** The largest size of the distributed object queue during the
|
||||||
|
* period. */
|
||||||
|
public int maxQueueSize;
|
||||||
|
|
||||||
|
/** The number of events dispatched during the period. */
|
||||||
|
public int eventCount;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the dobjmgr and prepares it for operation.
|
* Creates the dobjmgr and prepares it for operation.
|
||||||
*/
|
*/
|
||||||
@@ -93,15 +107,6 @@ public class PresentsDObjectMgr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Configures this manager with a log to which runtime statistics will
|
|
||||||
* be recorded.
|
|
||||||
*/
|
|
||||||
public void setStatsLog (AuditLogger logger)
|
|
||||||
{
|
|
||||||
_statslog = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
// documentation inherited from interface
|
// documentation inherited from interface
|
||||||
public boolean isManager (DObject object)
|
public boolean isManager (DObject object)
|
||||||
{
|
{
|
||||||
@@ -189,6 +194,15 @@ public class PresentsDObjectMgr
|
|||||||
return (DObject)_objects.get(oid);
|
return (DObject)_objects.get(oid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the runtime statistics for the most recently completed
|
||||||
|
* reporting period.
|
||||||
|
*/
|
||||||
|
public Stats getStats ()
|
||||||
|
{
|
||||||
|
return _recent;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the thread invoking this method is the same thread
|
* Returns true if the thread invoking this method is the same thread
|
||||||
* that is doing distributed object event dispatch. Code that wishes
|
* that is doing distributed object event dispatch. Code that wishes
|
||||||
@@ -231,24 +245,22 @@ public class PresentsDObjectMgr
|
|||||||
long start = _timer.highResCounter();
|
long start = _timer.highResCounter();
|
||||||
long freq = _timer.highResFrequency();
|
long freq = _timer.highResFrequency();
|
||||||
|
|
||||||
if (_statslog != null) {
|
// keep track of the largest queue size we've seen
|
||||||
// keep track of the largest queue size we've seen
|
int queueSize = _evqueue.size();
|
||||||
int queueSize = _evqueue.size();
|
if (queueSize > _current.maxQueueSize) {
|
||||||
if (queueSize > _maxQueueSize) {
|
_current.maxQueueSize = queueSize;
|
||||||
_maxQueueSize = queueSize;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// report and reset our largest queue size once every 5 minutes
|
// report and reset our largest queue size once every 5 minutes
|
||||||
long startMillis = start * 1000 / freq;
|
long startMillis = start * 1000 / freq;
|
||||||
if (_nextQueueReport < startMillis) {
|
if (_nextStatsSnapshot < startMillis) {
|
||||||
if (_nextQueueReport != 0L) {
|
_recent = _current;
|
||||||
_statslog.log("max_dobj_queue_size " + _maxQueueSize);
|
_current = new Stats();
|
||||||
_maxQueueSize = queueSize;
|
if (_nextStatsSnapshot != 0L) {
|
||||||
_nextQueueReport += QUEUE_PROFILING_INTERVAL;
|
_current.maxQueueSize = queueSize;
|
||||||
|
_nextStatsSnapshot += STATS_SNAPSHOT_INTERVAL;
|
||||||
} else {
|
} else {
|
||||||
_nextQueueReport = startMillis + QUEUE_PROFILING_INTERVAL;
|
_nextStatsSnapshot = startMillis + STATS_SNAPSHOT_INTERVAL;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -419,6 +431,7 @@ public class PresentsDObjectMgr
|
|||||||
|
|
||||||
// track the number of events dispatched
|
// track the number of events dispatched
|
||||||
++_eventCount;
|
++_eventCount;
|
||||||
|
++_current.eventCount;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -717,11 +730,6 @@ public class PresentsDObjectMgr
|
|||||||
{
|
{
|
||||||
report.append("* presents.PresentsDObjectMgr:\n");
|
report.append("* presents.PresentsDObjectMgr:\n");
|
||||||
|
|
||||||
long processed = (_eventCount - _lastEventCount);
|
|
||||||
report.append("- Events since last report: ").append(processed);
|
|
||||||
report.append("\n");
|
|
||||||
_lastEventCount = _eventCount;
|
|
||||||
|
|
||||||
report.append("- Unit profiles: ").append(_profiles.size());
|
report.append("- Unit profiles: ").append(_profiles.size());
|
||||||
report.append("\n");
|
report.append("\n");
|
||||||
for (Iterator iter = _profiles.keySet().iterator(); iter.hasNext(); ) {
|
for (Iterator iter = _profiles.keySet().iterator(); iter.hasNext(); ) {
|
||||||
@@ -986,12 +994,6 @@ public class PresentsDObjectMgr
|
|||||||
/** Used to track the number of events dispatched over time. */
|
/** Used to track the number of events dispatched over time. */
|
||||||
protected long _eventCount = 0;
|
protected long _eventCount = 0;
|
||||||
|
|
||||||
/** Used to track the number of events dispatched over of time. */
|
|
||||||
protected long _lastEventCount = 0;
|
|
||||||
|
|
||||||
/** The last time at which we generated a report. */
|
|
||||||
protected long _lastReportStamp;
|
|
||||||
|
|
||||||
/** Track fatal errors so that we can stick a fork in ourselves if
|
/** Track fatal errors so that we can stick a fork in ourselves if
|
||||||
* things get too far out of hand. More than 30 fatal errors in the
|
* things get too far out of hand. More than 30 fatal errors in the
|
||||||
* span of a minute and we throw in the towel. */
|
* span of a minute and we throw in the towel. */
|
||||||
@@ -1015,14 +1017,11 @@ public class PresentsDObjectMgr
|
|||||||
/** Used to profile our events and runnable units. */
|
/** Used to profile our events and runnable units. */
|
||||||
protected HashMap _profiles = new HashMap();
|
protected HashMap _profiles = new HashMap();
|
||||||
|
|
||||||
/** Used to report runtime statistics. */
|
/** Used to track runtime statistics. */
|
||||||
protected AuditLogger _statslog;
|
protected Stats _recent = new Stats(), _current = _recent;
|
||||||
|
|
||||||
/** The largest queue size in the past minute. */
|
/** The time at which we last took a snapshot of our stats. */
|
||||||
protected long _maxQueueSize;
|
protected long _nextStatsSnapshot;
|
||||||
|
|
||||||
/** The time at which we last reported our max queue size. */
|
|
||||||
protected long _nextQueueReport;
|
|
||||||
|
|
||||||
/** The frequency with which we take a profiling sample. */
|
/** The frequency with which we take a profiling sample. */
|
||||||
protected static final int UNIT_PROFILING_INTERVAL = 100;
|
protected static final int UNIT_PROFILING_INTERVAL = 100;
|
||||||
@@ -1030,8 +1029,8 @@ public class PresentsDObjectMgr
|
|||||||
/** The default size of an oid list refs vector. */
|
/** The default size of an oid list refs vector. */
|
||||||
protected static final int DEFREFVEC_SIZE = 4;
|
protected static final int DEFREFVEC_SIZE = 4;
|
||||||
|
|
||||||
/** The frequency with which we report maximum queue size. */
|
/** The frequency with which we roll over our runtime stats. */
|
||||||
protected static final long QUEUE_PROFILING_INTERVAL = 5 * 60 * 1000L;
|
protected static final long STATS_SNAPSHOT_INTERVAL = 5 * 60 * 1000L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This table maps event classes to helper methods that perform some
|
* This table maps event classes to helper methods that perform some
|
||||||
|
|||||||
Reference in New Issue
Block a user