Skip to content

Commit

Permalink
Add param to enable ws per-message deflate (#365)
Browse files Browse the repository at this point in the history
* Add param to enable ws per-message deflate

Tornado has its own per-message deflate compression option, which
compresses each WebSocket message.  The compression level should be
roughly equivalent to PNG compression, depending on whether the message is
JSON or binary (CBOR).  The encoding/decoding time will be much faster
than protocol PNG compression.

This param should be enabled when wire size is important, e.g. not
connecting to localhost.
  • Loading branch information
mvollrath authored and Viktor Kunovski committed Nov 9, 2018
1 parent 5c423b8 commit c86fe4b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rosbridge_server/launch/rosbridge_websocket.launch
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<arg name="max_message_size" default="None" />
<arg name="unregister_timeout" default="10" />

<arg name="use_compression" default="false" />

<arg name="authenticate" default="false" />

<arg name="topics_glob" default="[*]" />
Expand All @@ -34,6 +36,7 @@
<param name="delay_between_messages" value="$(arg delay_between_messages)"/>
<param name="max_message_size" value="$(arg max_message_size)"/>
<param name="unregister_timeout" value="$(arg unregister_timeout)"/>
<param name="use_compression" value="$(arg use_compression)"/>

<param name="topics_glob" value="$(arg topics_glob)"/>
<param name="services_glob" value="$(arg services_glob)"/>
Expand All @@ -50,6 +53,7 @@
<param name="delay_between_messages" value="$(arg delay_between_messages)"/>
<param name="max_message_size" value="$(arg max_message_size)"/>
<param name="unregister_timeout" value="$(arg unregister_timeout)"/>
<param name="use_compression" value="$(arg use_compression)"/>

<param name="topics_glob" value="$(arg topics_glob)"/>
<param name="services_glob" value="$(arg services_glob)"/>
Expand Down
2 changes: 2 additions & 0 deletions rosbridge_server/scripts/rosbridge_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def shutdown_hook():
##################################################
retry_startup_delay = rospy.get_param('~retry_startup_delay', 2.0) # seconds

RosbridgeWebSocket.use_compression = rospy.get_param('~use_compression', False)

# get RosbridgeProtocol parameters
RosbridgeWebSocket.fragment_timeout = rospy.get_param('~fragment_timeout',
RosbridgeWebSocket.fragment_timeout)
Expand Down
11 changes: 11 additions & 0 deletions rosbridge_server/src/rosbridge_server/websocket_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class RosbridgeWebSocket(WebSocketHandler):
clients_connected = 0
client_count_pub = None
authenticate = False
use_compression = False

# The following are passed on to RosbridgeProtocol
# defragmentation.py:
Expand Down Expand Up @@ -126,3 +127,13 @@ def send_message(self, message):

def check_origin(self, origin):
return True

def get_compression_options(self):
# If this method returns None (the default), compression will be disabled.
# If it returns a dict (even an empty one), it will be enabled.
cls = self.__class__

if not cls.use_compression:
return None

return {}

0 comments on commit c86fe4b

Please sign in to comment.