The throttle update cannot be applied in a Runnable, or we get a race condition against the frames coming in from network. The actual _throttle is only ever access from the network thread, so only _pendingThrottles needs extra care.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5501 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -190,7 +190,9 @@ public class PresentsClient
|
|||||||
@EventThread
|
@EventThread
|
||||||
public void setIncomingMessageThrottle (int messagesPerSec)
|
public void setIncomingMessageThrottle (int messagesPerSec)
|
||||||
{
|
{
|
||||||
|
synchronized(_pendingThrottles) {
|
||||||
_pendingThrottles.add(messagesPerSec);
|
_pendingThrottles.add(messagesPerSec);
|
||||||
|
}
|
||||||
postMessage(new UpdateThrottleMessage(messagesPerSec));
|
postMessage(new UpdateThrottleMessage(messagesPerSec));
|
||||||
// when we get a ThrottleUpdatedMessage from the client, we'll apply the new throttle
|
// when we get a ThrottleUpdatedMessage from the client, we'll apply the new throttle
|
||||||
}
|
}
|
||||||
@@ -849,24 +851,24 @@ public class PresentsClient
|
|||||||
*/
|
*/
|
||||||
protected void throttleUpdated ()
|
protected void throttleUpdated ()
|
||||||
{
|
{
|
||||||
_omgr.postRunnable(new Runnable() {
|
int messagesPerSec;
|
||||||
public void run () {
|
synchronized(_pendingThrottles) {
|
||||||
if (_pendingThrottles.size() == 0) {
|
if (_pendingThrottles.size() == 0) {
|
||||||
log.warning("Received throttleUpdated but have no pending throttles",
|
log.warning("Received throttleUpdated but have no pending throttles",
|
||||||
"client", this);
|
"client", this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int messagesPerSec = _pendingThrottles.remove(0);
|
messagesPerSec = _pendingThrottles.remove(0);
|
||||||
|
}
|
||||||
|
|
||||||
log.info("Applying updated throttle", "client", this, "msgsPerSec", messagesPerSec);
|
log.info("Applying updated throttle", "client", this, "msgsPerSec", messagesPerSec);
|
||||||
// we set our hard throttle over a 10 second period instead of a 1 second period to
|
// We set our hard throttle over a 10 second period instead of a 1 second period to
|
||||||
// account for periods of network congestion that might cause otherwise properly
|
// account for periods of network congestion that might cause otherwise properly
|
||||||
// throttled messages to bunch up while they're "on the wire"; we also add a one
|
// throttled messages to bunch up while they're "on the wire"; we also add a one
|
||||||
// message buffer so that if the client is right up against the limit, we don't end
|
// message buffer so that if the client is right up against the limit, we don't end
|
||||||
// up quibbling over a couple of milliseconds
|
// up quibbling over a couple of milliseconds
|
||||||
_throttle.reinit(10*messagesPerSec+1, 10*1000L);
|
_throttle.reinit(10*messagesPerSec+1, 10*1000L);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString ()
|
public String toString ()
|
||||||
|
|||||||
Reference in New Issue
Block a user