Skip to content

Commit

Permalink
Merge pull request labgrid-project#1318 from Bastian-Krause/bst/incre…
Browse files Browse the repository at this point in the history
…ase-msg-payload

Support more exported resources by adjusting WebSocket message limits/fragmentation
  • Loading branch information
Bastian-Krause committed Feb 5, 2024
2 parents be315c0 + 54b1518 commit 00f466c
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .crossbar/config-anonymous.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ workers:
directory: ../web
ws:
type: websocket
options:
auto_fragment_size: 65536
auth:
anonymous:
type: static
Expand Down
1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
'autobahn',
'autobahn.asyncio',
'autobahn.asyncio.wamp',
'autobahn.asyncio.websocket',
'autobahn.wamp',
'autobahn.wamp.types',
'autobahn.twisted',
Expand Down
3 changes: 2 additions & 1 deletion labgrid/remote/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from autobahn.asyncio.wamp import ApplicationSession

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

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


class Error(Exception):
Expand Down
34 changes: 34 additions & 0 deletions labgrid/remote/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'ReservationState',
'Reservation',
'enable_tcp_nodelay',
'monkey_patch_max_msg_payload_size_ws_option',
]

TAG_KEY = re.compile(r"[a-z][a-z0-9_]+")
Expand Down Expand Up @@ -312,3 +313,36 @@ def enable_tcp_nodelay(session):
"""
s = session._transport.transport.get_extra_info('socket')
s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, True)


def monkey_patch_max_msg_payload_size_ws_option():
"""
The default maxMessagePayloadSize in autobahn is 1M. For larger setups with a big number of
exported resources, this becomes the limiting factor.
Increase maxMessagePayloadSize in WampWebSocketClientFactory.setProtocolOptions() by monkey
patching it, so autobahn.asyncio.wamp.ApplicationRunner effectively sets the increased value.
This function must be called before ApplicationRunner is instanciated.
"""
from autobahn.asyncio.websocket import WampWebSocketClientFactory

original_method = WampWebSocketClientFactory.setProtocolOptions

def set_protocol_options(*args, **kwargs):
new_max_message_payload_size = 10485760

# maxMessagePayloadSize given as positional arg
args = list(args)
try:
args[9] = max((args[9], new_max_message_payload_size))
except IndexError:
pass

# maxMessagePayloadSize given as kwarg
kwarg_name = "maxMessagePayloadSize"
if kwarg_name in kwargs and kwargs[kwarg_name] is not None:
kwargs[kwarg_name] = max((kwargs[kwarg_name], new_max_message_payload_size))

return original_method(*args, **kwargs)

WampWebSocketClientFactory.setProtocolOptions = set_protocol_options
3 changes: 3 additions & 0 deletions labgrid/remote/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
from ..util import atomic_replace, yaml


monkey_patch_max_msg_payload_size_ws_option()


class Action(Enum):
ADD = 0
DEL = 1
Expand Down
4 changes: 3 additions & 1 deletion labgrid/remote/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
from autobahn.asyncio.wamp import ApplicationRunner, ApplicationSession

from .config import ResourceConfig
from .common import ResourceEntry, enable_tcp_nodelay
from .common import ResourceEntry, enable_tcp_nodelay, monkey_patch_max_msg_payload_size_ws_option
from ..util import get_free_port, labgrid_version


monkey_patch_max_msg_payload_size_ws_option()

__version__ = labgrid_version()
exports: Dict[str, Type[ResourceEntry]] = {}
reexec = False
Expand Down

0 comments on commit 00f466c

Please sign in to comment.