Client side message throttling. The server is configured with a hard limit, it
communicates that limit to the client which queues outgoing messages so that it does not exceed the limit. When the throttle is changed, the server does not apply the new throttle until the client has ACKed it to avoid edge cases where the client is up against the limit when the throttle changes. ActionScript side of all of this forthcoming as well as more testing. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5422 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -118,7 +118,12 @@ public class TestClient
|
||||
{
|
||||
object.addListener(this);
|
||||
log.info("Object available: " + object);
|
||||
object.setBar("lawl!");
|
||||
object.postMessage("lawl!");
|
||||
|
||||
// try blowing through our message limit
|
||||
for (int ii = 0; ii < 2*Client.DEFAULT_MAX_MSG_RATE[0]+5; ii++) {
|
||||
object.postMessage("ZOMG!", new Integer(ii));
|
||||
}
|
||||
}
|
||||
|
||||
public void requestFailed (int oid, ObjectAccessException cause)
|
||||
@@ -133,8 +138,8 @@ public class TestClient
|
||||
{
|
||||
log.info("Got event [event=" + event + "].");
|
||||
|
||||
// request that we log off
|
||||
_client.logoff(true);
|
||||
// // request that we log off
|
||||
// _client.logoff(true);
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
// $Id$
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
/**
|
||||
* Test class to exercise the code in {@link VariableThrottle}.
|
||||
*/
|
||||
public class TestVariableThrottle
|
||||
{
|
||||
/**
|
||||
* Exercise the code in {@link VariableThrottle}.
|
||||
*/
|
||||
public static void main (String[] args)
|
||||
{
|
||||
testUpdate(4);
|
||||
testUpdate(5);
|
||||
testUpdate(6);
|
||||
testUpdate(7);
|
||||
testUpdate(8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the {@link VariableThrottle#updateOpLimit} function a few times, interspersed with
|
||||
* calls to add operations. Prints the operations contained in the throttle after each change.
|
||||
*/
|
||||
public static void testUpdate (int opCount)
|
||||
{
|
||||
// set up a throttle for 5 ops per millisecond
|
||||
TestThrottle throttle = new TestThrottle(5, 1);
|
||||
System.out.println("Testing updates with " + opCount + " operations");
|
||||
long time = 0;
|
||||
for (int ii = 0; ii < opCount; ++ii) {
|
||||
throttle.throttleOp(time += 1);
|
||||
}
|
||||
System.out.println(" " + throttle.opsToString());
|
||||
throttle.updateOpLimit(10);
|
||||
for (int ii = 0; ii < opCount; ++ii) {
|
||||
throttle.throttleOp(time += 1);
|
||||
}
|
||||
System.out.println(" " + throttle.opsToString());
|
||||
throttle.updateOpLimit(5);
|
||||
System.out.println(" " + throttle.opsToString());
|
||||
for (int ii = 0; ii < opCount; ++ii) {
|
||||
throttle.throttleOp(time += 1);
|
||||
}
|
||||
System.out.println(" " + throttle.opsToString());
|
||||
throttle.updateOpLimit(10);
|
||||
System.out.println(" " + throttle.opsToString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a string representation of all operation time stamps, starting from the oldest.
|
||||
*/
|
||||
public static class TestThrottle extends VariableThrottle
|
||||
{
|
||||
public TestThrottle (int maxOps, long period)
|
||||
{
|
||||
super(maxOps, period);
|
||||
}
|
||||
|
||||
public String opsToString ()
|
||||
{
|
||||
String hist = String.valueOf(_ops[_lastOp]);
|
||||
for (int ii = 1; ii < _ops.length; ++ii) {
|
||||
long tn = _ops[(_lastOp + ii) % _ops.length];
|
||||
hist += ", " + String.valueOf(tn);
|
||||
}
|
||||
return hist;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user