Fixed fundamental flaw with throttling code. Changed the client to adjust its message rate when it actually sends the throttle updated message. Otherwise the client starts sending at the new rate before the server knows about it. Keep the messages per second in the message.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5499 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Jamie Doornbos
2008-11-04 08:37:13 +00:00
parent ed002196b0
commit 14755a6cea
4 changed files with 40 additions and 2 deletions
@@ -414,8 +414,14 @@ public class Client extends EventDispatcher
internal function setOutgoingMessageThrottle (messagesPerSec :int) :void
{
_comm.postMessage(new ThrottleUpdatedMessage(messagesPerSec));
}
internal function finalizeOutgoingMessageThrottle (messagesPerSec :int) :void
{
// when the throttle update message goes out to the server
_outThrottle.reinit(messagesPerSec, 1000);
_comm.postMessage(new ThrottleUpdatedMessage());
log.info("Updated outgoing throttle", "messagesPerSec", messagesPerSec);
}
internal function getOutgoingMessageThrottle () :Throttle
@@ -45,6 +45,7 @@ import com.threerings.presents.net.AuthResponseData;
import com.threerings.presents.net.DownstreamMessage;
import com.threerings.presents.net.LogoffRequest;
import com.threerings.presents.net.UpstreamMessage;
import com.threerings.presents.net.ThrottleUpdatedMessage;
public class Communicator
{
@@ -192,6 +193,8 @@ public class Communicator
// if this was a logoff request, shutdown
if (msg is LogoffRequest) {
shutdown(null);
} else if (msg is ThrottleUpdatedMessage) {
_client.finalizeOutgoingMessageThrottle(ThrottleUpdatedMessage(msg).messagesPerSec);
}
}
}
@@ -21,10 +21,25 @@
package com.threerings.presents.net {
import com.threerings.io.ObjectOutputStream;
/**
* Notifies the server that the client has received its UpdateThrottleMessage.
*/
public class ThrottleUpdatedMessage extends UpstreamMessage
{
/** The number of messages allowed per second. */
public var messagesPerSec :int;
public function ThrottleUpdatedMessage (messagesPerSec :int = 0)
{
this.messagesPerSec = messagesPerSec;
}
override public function writeObject (outs :ObjectOutputStream) :void
{
super.writeObject(outs);
outs.writeInt(messagesPerSec);
}
}
}
@@ -26,5 +26,19 @@ package com.threerings.presents.net;
*/
public class ThrottleUpdatedMessage extends UpstreamMessage
{
// nothing needed
/** The number of messages allowed per second. */
public final int messagesPerSec;
/**
* Zero argument constructor used when unserializing an instance.
*/
public ThrottleUpdatedMessage ()
{
this.messagesPerSec = 0;
}
public ThrottleUpdatedMessage (int messagesPerSec)
{
this.messagesPerSec = messagesPerSec;
}
}