1
0
Fork 0

Limit the update rate of the property change websocket

Of fast systems with 60fps sending many properties to web clients
may overrun the rendering capabilities of the browser. At some point
the web socket client halts the simulation by throtteling the network
connection.

Update rate is settable at startup setting to a double value
/sim/http/property-websocket/update-interval-secs
(default: 0.05 aka 20Hz)
This commit is contained in:
Torsten Dreyer 2016-10-26 11:02:24 +02:00
parent 8e451a05f1
commit 65b51b8d91
2 changed files with 16 additions and 2 deletions

View file

@ -118,7 +118,10 @@ static void handleExecCommand(cJSON* json)
}
PropertyChangeWebsocket::PropertyChangeWebsocket(PropertyChangeObserver * propertyChangeObserver)
: id(++nextid), _propertyChangeObserver(propertyChangeObserver)
: id(++nextid),
_propertyChangeObserver(propertyChangeObserver),
_minTriggerInterval(fgGetDouble("/sim/http/property-websocket/update-interval-secs", 0.05)), // default 20Hz
_lastTrigger(-1000)
{
}
@ -206,12 +209,21 @@ void PropertyChangeWebsocket::handleRequest(const HTTPRequest & request, Websock
void PropertyChangeWebsocket::poll(WebsocketWriter & writer)
{
double now = fgGetDouble("/sim/time/elapsed-sec");
if( _minTriggerInterval > .0 ) {
if( now - _lastTrigger <= _minTriggerInterval )
return;
_lastTrigger = now;
}
for (WatchedNodesList::iterator it = _watchedNodes.begin(); it != _watchedNodes.end(); ++it) {
SGPropertyNode_ptr node = *it;
string newValue;
if (_propertyChangeObserver->isChangedValue(node)) {
string out = JSON::toJsonString( false, node, 0, fgGetDouble("/sim/time/elapsed-sec") );
string out = JSON::toJsonString( false, node, 0, now );
SG_LOG(SG_NETWORK, SG_DEBUG, "PropertyChangeWebsocket::poll() new Value for " << node->getPath(true) << " '" << node->getStringValue() << "' #" << id << ": " << out );
writer.writeText( out );
}

View file

@ -51,6 +51,8 @@ private:
};
WatchedNodesList _watchedNodes;
double _minTriggerInterval;
double _lastTrigger;
};
}