Skip to content

Commit 00f466c

Browse files
Merge pull request #1318 from Bastian-Krause/bst/increase-msg-payload
Support more exported resources by adjusting WebSocket message limits/fragmentation
2 parents be315c0 + 54b1518 commit 00f466c

6 files changed

Lines changed: 45 additions & 2 deletions

File tree

.crossbar/config-anonymous.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ workers:
2828
directory: ../web
2929
ws:
3030
type: websocket
31+
options:
32+
auto_fragment_size: 65536
3133
auth:
3234
anonymous:
3335
type: static

doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@
186186
'autobahn',
187187
'autobahn.asyncio',
188188
'autobahn.asyncio.wamp',
189+
'autobahn.asyncio.websocket',
189190
'autobahn.wamp',
190191
'autobahn.wamp.types',
191192
'autobahn.twisted',

labgrid/remote/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from autobahn.asyncio.wamp import ApplicationSession
2424

2525
from .common import (ResourceEntry, ResourceMatch, Place, Reservation, ReservationState, TAG_KEY,
26-
TAG_VAL, enable_tcp_nodelay)
26+
TAG_VAL, enable_tcp_nodelay, monkey_patch_max_msg_payload_size_ws_option)
2727
from .. import Environment, Target, target_factory
2828
from ..exceptions import NoDriverFoundError, NoResourceFoundError, InvalidConfigError
2929
from ..resource.remote import RemotePlaceManager, RemotePlace
@@ -34,6 +34,7 @@
3434
from ..logging import basicConfig, StepLogger
3535

3636
txaio.config.loop = asyncio.get_event_loop() # pylint: disable=no-member
37+
monkey_patch_max_msg_payload_size_ws_option()
3738

3839

3940
class Error(Exception):

labgrid/remote/common.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
'ReservationState',
1919
'Reservation',
2020
'enable_tcp_nodelay',
21+
'monkey_patch_max_msg_payload_size_ws_option',
2122
]
2223

2324
TAG_KEY = re.compile(r"[a-z][a-z0-9_]+")
@@ -312,3 +313,36 @@ def enable_tcp_nodelay(session):
312313
"""
313314
s = session._transport.transport.get_extra_info('socket')
314315
s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, True)
316+
317+
318+
def monkey_patch_max_msg_payload_size_ws_option():
319+
"""
320+
The default maxMessagePayloadSize in autobahn is 1M. For larger setups with a big number of
321+
exported resources, this becomes the limiting factor.
322+
Increase maxMessagePayloadSize in WampWebSocketClientFactory.setProtocolOptions() by monkey
323+
patching it, so autobahn.asyncio.wamp.ApplicationRunner effectively sets the increased value.
324+
325+
This function must be called before ApplicationRunner is instanciated.
326+
"""
327+
from autobahn.asyncio.websocket import WampWebSocketClientFactory
328+
329+
original_method = WampWebSocketClientFactory.setProtocolOptions
330+
331+
def set_protocol_options(*args, **kwargs):
332+
new_max_message_payload_size = 10485760
333+
334+
# maxMessagePayloadSize given as positional arg
335+
args = list(args)
336+
try:
337+
args[9] = max((args[9], new_max_message_payload_size))
338+
except IndexError:
339+
pass
340+
341+
# maxMessagePayloadSize given as kwarg
342+
kwarg_name = "maxMessagePayloadSize"
343+
if kwarg_name in kwargs and kwargs[kwarg_name] is not None:
344+
kwargs[kwarg_name] = max((kwargs[kwarg_name], new_max_message_payload_size))
345+
346+
return original_method(*args, **kwargs)
347+
348+
WampWebSocketClientFactory.setProtocolOptions = set_protocol_options

labgrid/remote/coordinator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
from ..util import atomic_replace, yaml
2020

2121

22+
monkey_patch_max_msg_payload_size_ws_option()
23+
24+
2225
class Action(Enum):
2326
ADD = 0
2427
DEL = 1

labgrid/remote/exporter.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
from autobahn.asyncio.wamp import ApplicationRunner, ApplicationSession
1919

2020
from .config import ResourceConfig
21-
from .common import ResourceEntry, enable_tcp_nodelay
21+
from .common import ResourceEntry, enable_tcp_nodelay, monkey_patch_max_msg_payload_size_ws_option
2222
from ..util import get_free_port, labgrid_version
2323

2424

25+
monkey_patch_max_msg_payload_size_ws_option()
26+
2527
__version__ = labgrid_version()
2628
exports: Dict[str, Type[ResourceEntry]] = {}
2729
reexec = False

0 commit comments

Comments
 (0)