|
18 | 18 | 'ReservationState', |
19 | 19 | 'Reservation', |
20 | 20 | 'enable_tcp_nodelay', |
| 21 | + 'monkey_patch_max_msg_payload_size_ws_option', |
21 | 22 | ] |
22 | 23 |
|
23 | 24 | TAG_KEY = re.compile(r"[a-z][a-z0-9_]+") |
@@ -312,3 +313,36 @@ def enable_tcp_nodelay(session): |
312 | 313 | """ |
313 | 314 | s = session._transport.transport.get_extra_info('socket') |
314 | 315 | 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 |
0 commit comments