Added a count of how many socket events we see (sockets reporting ACCEPTable or
READable), tidied up some other bits. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5534 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -43,6 +43,9 @@ public class ConMgrStats extends SimpleStreamableObject
|
|||||||
/** The overflow queue size. This is a snapshot at the time the stats are requested. */
|
/** The overflow queue size. This is a snapshot at the time the stats are requested. */
|
||||||
public int overQueueSize;
|
public int overQueueSize;
|
||||||
|
|
||||||
|
/** The number of raw network events (sockets reporting ACCEPT or READY). */
|
||||||
|
public long eventCount;
|
||||||
|
|
||||||
/** The number of connection events since the server started up. */
|
/** The number of connection events since the server started up. */
|
||||||
public int connects;
|
public int connects;
|
||||||
|
|
||||||
@@ -59,10 +62,10 @@ public class ConMgrStats extends SimpleStreamableObject
|
|||||||
public long bytesOut;
|
public long bytesOut;
|
||||||
|
|
||||||
/** The number of messages read since the server started up. */
|
/** The number of messages read since the server started up. */
|
||||||
public int msgsIn;
|
public long msgsIn;
|
||||||
|
|
||||||
/** The number of messages written since the server started up. */
|
/** The number of messages written since the server started up. */
|
||||||
public int msgsOut;
|
public long msgsOut;
|
||||||
|
|
||||||
@Override // from Object
|
@Override // from Object
|
||||||
public Object clone ()
|
public Object clone ()
|
||||||
|
|||||||
@@ -231,6 +231,7 @@ public class ConnectionManager extends LoopingThread
|
|||||||
public void appendReport (StringBuilder report, long now, long sinceLast, boolean reset)
|
public void appendReport (StringBuilder report, long now, long sinceLast, boolean reset)
|
||||||
{
|
{
|
||||||
ConMgrStats stats = getStats();
|
ConMgrStats stats = getStats();
|
||||||
|
long eventCount = stats.eventCount - _lastStats.eventCount;
|
||||||
int connects = stats.connects - _lastStats.connects;
|
int connects = stats.connects - _lastStats.connects;
|
||||||
int disconnects = stats.disconnects - _lastStats.disconnects;
|
int disconnects = stats.disconnects - _lastStats.disconnects;
|
||||||
int closes = stats.closes - _lastStats.closes;
|
int closes = stats.closes - _lastStats.closes;
|
||||||
@@ -248,6 +249,7 @@ public class ConnectionManager extends LoopingThread
|
|||||||
|
|
||||||
report.append("* presents.net.ConnectionManager:\n");
|
report.append("* presents.net.ConnectionManager:\n");
|
||||||
report.append("- Network connections: ");
|
report.append("- Network connections: ");
|
||||||
|
report.append(eventCount).append(" events, ");
|
||||||
report.append(connects).append(" connects, ");
|
report.append(connects).append(" connects, ");
|
||||||
report.append(disconnects).append(" disconnects, ");
|
report.append(disconnects).append(" disconnects, ");
|
||||||
report.append(closes).append(" closes\n");
|
report.append(closes).append(" closes\n");
|
||||||
@@ -609,14 +611,15 @@ public class ConnectionManager extends LoopingThread
|
|||||||
protected void processIncomingEvents (long iterStamp)
|
protected void processIncomingEvents (long iterStamp)
|
||||||
{
|
{
|
||||||
Set<SelectionKey> ready = null;
|
Set<SelectionKey> ready = null;
|
||||||
|
int eventCount;
|
||||||
try {
|
try {
|
||||||
// log.debug("Selecting from " + StringUtil.toString(_selector.keys()) + " (" +
|
// log.debug("Selecting from " + StringUtil.toString(_selector.keys()) + " (" +
|
||||||
// SELECT_LOOP_TIME + ").");
|
// SELECT_LOOP_TIME + ").");
|
||||||
|
|
||||||
// check for incoming network events
|
// check for incoming network events
|
||||||
int ecount = _selector.select(SELECT_LOOP_TIME);
|
eventCount = _selector.select(SELECT_LOOP_TIME);
|
||||||
ready = _selector.selectedKeys();
|
ready = _selector.selectedKeys();
|
||||||
if (ecount == 0) {
|
if (eventCount == 0) {
|
||||||
if (ready.size() == 0) {
|
if (ready.size() == 0) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@@ -627,10 +630,9 @@ public class ConnectionManager extends LoopingThread
|
|||||||
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
if ("Invalid argument".equals(ioe.getMessage())) {
|
if ("Invalid argument".equals(ioe.getMessage())) {
|
||||||
// what is this, anyway?
|
log.warning("Failure select()ing.", ioe); // no stack trace needed
|
||||||
log.warning("Failure select()ing.", ioe);
|
|
||||||
} else {
|
} else {
|
||||||
log.warning("Failure select()ing [ioe=" + ioe + "].");
|
log.warning("Failure select()ing", "ioe", ioe);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -649,7 +651,7 @@ public class ConnectionManager extends LoopingThread
|
|||||||
_runtimeExceptionCount = 0;
|
_runtimeExceptionCount = 0;
|
||||||
|
|
||||||
// process those events
|
// process those events
|
||||||
// log.info("Ready set " + StringUtil.toString(ready) + ".");
|
long bytesIn = 0, msgsIn = 0;
|
||||||
for (SelectionKey selkey : ready) {
|
for (SelectionKey selkey : ready) {
|
||||||
NetEventHandler handler = null;
|
NetEventHandler handler = null;
|
||||||
try {
|
try {
|
||||||
@@ -667,12 +669,10 @@ public class ConnectionManager extends LoopingThread
|
|||||||
|
|
||||||
int got = handler.handleEvent(iterStamp);
|
int got = handler.handleEvent(iterStamp);
|
||||||
if (got != 0) {
|
if (got != 0) {
|
||||||
synchronized (this) {
|
bytesIn += got;
|
||||||
_stats.bytesIn += got;
|
// we know that the handlers only report having read bytes when they have a
|
||||||
// we know that the handlers only report having read bytes when they have a
|
// whole message, so we can count thusly
|
||||||
// whole message, so we can count thusly
|
msgsIn++;
|
||||||
_stats.msgsIn++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -684,6 +684,14 @@ public class ConnectionManager extends LoopingThread
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update our stats
|
||||||
|
synchronized (this) {
|
||||||
|
_stats.eventCount += eventCount;
|
||||||
|
_stats.bytesIn += bytesIn;
|
||||||
|
_stats.msgsIn += msgsIn;
|
||||||
|
}
|
||||||
|
|
||||||
ready.clear();
|
ready.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -896,8 +904,7 @@ public class ConnectionManager extends LoopingThread
|
|||||||
try {
|
try {
|
||||||
channel = listener.accept();
|
channel = listener.accept();
|
||||||
if (channel == null) {
|
if (channel == null) {
|
||||||
// in theory this shouldn't happen because we got an ACCEPT_READY event, but better
|
// in theory this shouldn't happen because we got an ACCEPT_READY event...
|
||||||
// safe than sorry
|
|
||||||
log.info("Psych! Got ACCEPT_READY, but no connection.");
|
log.info("Psych! Got ACCEPT_READY, but no connection.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -918,8 +925,8 @@ public class ConnectionManager extends LoopingThread
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
// no need to complain this happens in the normal course of events
|
// no need to generate a warning because this happens in the normal course of events
|
||||||
// log.warning("Failure accepting new connection.", ioe);
|
log.info("Failure accepting new connection: " + ioe);
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure we don't leak a socket if something went awry
|
// make sure we don't leak a socket if something went awry
|
||||||
|
|||||||
Reference in New Issue
Block a user