Don't require that ConnectionManager be a Reporter

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6377 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Charlie Groves
2010-12-15 00:31:29 +00:00
parent 2b90dee9f7
commit f12887ae87
5 changed files with 117 additions and 97 deletions
@@ -31,8 +31,6 @@ import com.google.inject.Singleton;
import com.samskivert.util.Lifecycle;
import com.samskivert.util.Tuple;
import com.threerings.presents.server.ReportManager;
import com.threerings.nio.conman.Connection;
import com.threerings.nio.conman.ConnectionManager;
import com.threerings.nio.conman.ServerSocketChannelAcceptor;
@@ -47,10 +45,10 @@ import static com.threerings.NaryaLog.log;
public class PolicyServer extends ConnectionManager
{
@Inject
public PolicyServer (Lifecycle cycle, ReportManager mgr)
public PolicyServer (Lifecycle cycle)
throws IOException
{
super(cycle, mgr);
super(cycle);
}
/**
@@ -1,32 +1,8 @@
//
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
// http://code.google.com/p/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.nio.conman;
package com.threerings.presents.data;
import com.samskivert.util.StringUtil;
import com.threerings.io.SimpleStreamableObject;
/**
* Used to track and report stats on the connection manager.
*/
public class ConMgrStats extends SimpleStreamableObject
public class ConMgrStats
implements Cloneable
{
/** The number of mapped connections. This is a snapshot at the time the stats are requested. */
@@ -35,12 +11,10 @@ public class ConMgrStats extends SimpleStreamableObject
/** The number of net event handlers. This is a snapshot at the time the stats are requested. */
public int handlerCount;
/** The size of the queue of waiting to auth sockets. This is a snapshot at the time the stats
* are requested. */
public int authQueueSize;
/** The size of the queue of waiting to die sockets. This is a snapshot at the time the stats
* are requested. */
/**
* The size of the queue of waiting to die sockets. This is a snapshot at the time the stats
* are requested.
*/
public int deathQueueSize;
/** The outgoing queue size. This is a snapshot at the time the stats are requested. */
@@ -73,11 +47,17 @@ public class ConMgrStats extends SimpleStreamableObject
/** The number of messages written since the server started up. */
public long msgsOut;
@Override // from Object
@Override
public String toString ()
{
return StringUtil.fieldsToString(this);
}
@Override
public ConMgrStats clone ()
{
try {
return (ConMgrStats) super.clone();
return (ConMgrStats)super.clone();
} catch (CloneNotSupportedException cnse) {
throw new AssertionError(cnse);
}
@@ -43,8 +43,6 @@ import com.samskivert.util.LoopingThread;
import com.samskivert.util.Queue;
import com.samskivert.util.Tuple;
import com.threerings.presents.data.ConMgrStats;
import com.threerings.presents.server.ReportManager;
import com.threerings.nio.SelectorIterable;
import static com.threerings.NaryaLog.log;
@@ -59,17 +57,16 @@ import static com.threerings.NaryaLog.log;
* {@link #handleAcceptedSocket} method
*/
public abstract class ConnectionManager extends LoopingThread
implements Lifecycle.ShutdownComponent, ReportManager.Reporter
implements Lifecycle.ShutdownComponent
{
/**
* Creates a connection manager instance.
*/
public ConnectionManager (Lifecycle cycle, ReportManager repmgr)
public ConnectionManager (Lifecycle cycle)
throws IOException
{
super("ConnectionManager");
cycle.addComponent(this);
repmgr.registerReporter(this);
_selector = Selector.open();
}
@@ -134,51 +131,6 @@ public abstract class ConnectionManager extends LoopingThread
_deathq.append(conn);
}
// from interface ReportManager.Reporter
public void appendReport (StringBuilder report, long now, long sinceLast, boolean reset)
{
ConMgrStats stats = getStats();
long eventCount = stats.eventCount - _lastStats.eventCount;
int connects = stats.connects - _lastStats.connects;
int disconnects = stats.disconnects - _lastStats.disconnects;
int closes = stats.closes - _lastStats.closes;
long bytesIn = stats.bytesIn - _lastStats.bytesIn;
long bytesOut = stats.bytesOut - _lastStats.bytesOut;
long msgsIn = stats.msgsIn - _lastStats.msgsIn;
long msgsOut = stats.msgsOut - _lastStats.msgsOut;
if (reset) {
_lastStats = stats;
}
// make sure we don't div0 if this method somehow gets called twice in
// the same millisecond
sinceLast = Math.max(sinceLast, 1L);
report.append("* presents.net.ConnectionManager:\n");
report.append("- Network connections: ");
report.append(stats.connectionCount).append(" connections, ");
report.append(stats.handlerCount).append(" handlers\n");
report.append("- Network activity: ");
report.append(eventCount).append(" events, ");
report.append(connects).append(" connects, ");
report.append(disconnects).append(" disconnects, ");
report.append(closes).append(" closes\n");
report.append("- Network input: ");
report.append(bytesIn).append(" bytes, ");
report.append(msgsIn).append(" msgs, ");
report.append(msgsIn*1000/sinceLast).append(" mps, ");
long avgIn = (msgsIn == 0) ? 0 : (bytesIn/msgsIn);
report.append(avgIn).append(" avg size, ");
report.append(bytesIn*1000/sinceLast).append(" bps\n");
report.append("- Network output: ");
report.append(bytesOut).append(" bytes, ");
report.append(msgsOut).append(" msgs, ");
report.append(msgsOut*1000/sinceLast).append(" mps, ");
long avgOut = (msgsOut == 0) ? 0 : (bytesOut/msgsOut);
report.append(avgOut).append(" avg size, ");
report.append(bytesOut*1000/sinceLast).append(" bps\n");
}
@Override // from LoopingThread
protected void willStart ()
{
@@ -671,9 +623,6 @@ public abstract class ConnectionManager extends LoopingThread
/** Our current runtime stats. */
protected ConMgrStats _stats = new ConMgrStats();
/** A snapshot of our runtime stats as of our last report. */
protected ConMgrStats _lastStats = new ConMgrStats();
/** Used to periodically report connection manager activity when in debug mode. */
protected long _lastDebugStamp;
@@ -0,0 +1,42 @@
//
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
// http://code.google.com/p/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.presents.data;
import com.threerings.io.Streamable;
import com.threerings.nio.conman.ConMgrStats;
/**
* Used to track and report stats on the connection manager.
*/
public class PresentsConMgrStats extends ConMgrStats
implements Streamable
{
/** The size of the queue of waiting to auth sockets. This is a snapshot at the time the stats
* are requested. */
public int authQueueSize;
@Override // from Object
public PresentsConMgrStats clone ()
{
return (PresentsConMgrStats)super.clone();
}
}
@@ -49,7 +49,7 @@ import com.threerings.io.UnreliableObjectOutputStream;
import com.threerings.presents.annotation.AuthInvoker;
import com.threerings.presents.client.Client;
import com.threerings.presents.data.ConMgrStats;
import com.threerings.presents.data.PresentsConMgrStats;
import com.threerings.presents.net.Message;
import com.threerings.presents.net.PongResponse;
import com.threerings.presents.net.Transport;
@@ -69,20 +69,68 @@ import static com.threerings.presents.Log.log;
@Singleton
public class PresentsConnectionManager extends ConnectionManager
implements ReportManager.Reporter
{
@Inject
public PresentsConnectionManager (Lifecycle cycle, ReportManager repmgr)
throws IOException
{
super(cycle, repmgr);
super(cycle);
repmgr.registerReporter(this);
_stats = new PresentsConMgrStats();
}
@Override
public synchronized ConMgrStats getStats ()
public synchronized PresentsConMgrStats getStats ()
{
_stats.authQueueSize = _authq.size();
return super.getStats();
((PresentsConMgrStats)_stats).authQueueSize = _authq.size();
return ((PresentsConMgrStats)super.getStats());
}
// from interface ReportManager.Reporter
public void appendReport (StringBuilder report, long now, long sinceLast, boolean reset)
{
PresentsConMgrStats stats = getStats();
long eventCount = stats.eventCount - _lastStats.eventCount;
int connects = stats.connects - _lastStats.connects;
int disconnects = stats.disconnects - _lastStats.disconnects;
int closes = stats.closes - _lastStats.closes;
long bytesIn = stats.bytesIn - _lastStats.bytesIn;
long bytesOut = stats.bytesOut - _lastStats.bytesOut;
long msgsIn = stats.msgsIn - _lastStats.msgsIn;
long msgsOut = stats.msgsOut - _lastStats.msgsOut;
if (reset) {
_lastStats = stats;
}
// make sure we don't div0 if this method somehow gets called twice in
// the same millisecond
sinceLast = Math.max(sinceLast, 1L);
report.append("* presents.net.ConnectionManager:\n");
report.append("- Network connections: ");
report.append(stats.connectionCount).append(" connections, ");
report.append(stats.handlerCount).append(" handlers\n");
report.append("- Network activity: ");
report.append(eventCount).append(" events, ");
report.append(connects).append(" connects, ");
report.append(disconnects).append(" disconnects, ");
report.append(closes).append(" closes\n");
report.append("- Network input: ");
report.append(bytesIn).append(" bytes, ");
report.append(msgsIn).append(" msgs, ");
report.append(msgsIn*1000/sinceLast).append(" mps, ");
long avgIn = (msgsIn == 0) ? 0 : (bytesIn/msgsIn);
report.append(avgIn).append(" avg size, ");
report.append(bytesIn*1000/sinceLast).append(" bps\n");
report.append("- Network output: ");
report.append(bytesOut).append(" bytes, ");
report.append(msgsOut).append(" msgs, ");
report.append(msgsOut*1000/sinceLast).append(" mps, ");
long avgOut = (msgsOut == 0) ? 0 : (bytesOut/msgsOut);
report.append(avgOut).append(" avg size, ");
report.append(bytesOut*1000/sinceLast).append(" bps\n");
}
/**
@@ -485,6 +533,9 @@ public class PresentsConnectionManager extends ConnectionManager
@Inject protected ClientManager _clmgr;
@Inject protected PresentsDObjectMgr _omgr;
/** A snapshot of our runtime stats as of our last report. */
protected PresentsConMgrStats _lastStats = new PresentsConMgrStats();
protected Queue<Tuple<PresentsConnection, byte[]>> _dataq = Queue.newQueue();
protected ByteBuffer _databuf = ByteBuffer.allocateDirect(Client.MAX_DATAGRAM_SIZE);
}