{"action":"created","issue":{"url":"https://api.github.com/repos/RobotWebTools/roslibjs/issues/155","labels_url":"https://api.github.com/repos/RobotWebTools/roslibjs/issues/155/labels{/name}","comments_url":"https://api.github.com/repos/RobotWebTools/roslibjs/issues/155/comments","events_url":"https://api.github.com/repos/RobotWebTools/roslibjs/issues/155/events","html_url":"https://github.com/RobotWebTools/roslibjs/issues/155","id":56840988,"number":155,"title":"Websocket should use BSON to properly support PointClouds and other binary data ","user":{"login":"pbeeson","id":3858374,"avatar_url":"https://avatars.githubusercontent.com/u/3858374?v=3","gravatar_id":"","url":"https://api.github.com/users/pbeeson","html_url":"https://github.com/pbeeson","followers_url":"https://api.github.com/users/pbeeson/followers","following_url":"https://api.github.com/users/pbeeson/following{/other_user}","gists_url":"https://api.github.com/users/pbeeson/gists{/gist_id}","starred_url":"https://api.github.com/users/pbeeson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pbeeson/subscriptions","organizations_url":"https://api.github.com/users/pbeeson/orgs","repos_url":"https://api.github.com/users/pbeeson/repos","events_url":"https://api.github.com/users/pbeeson/events{/privacy}","received_events_url":"https://api.github.com/users/pbeeson/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-02-06T17:23:00Z","updated_at":"2015-02-06T17:24:00Z","closed_at":null,"body":"I was using the rosbridge websocket server for a project, but we were sending LARGE amounts of point cloud data to a web page to be rendered.  It turns out of course that there were several issues.  The first of which is the fact that the roslibjs client side does keep up and memory leaks occur.  This was easily fixed by setting up a service to request large PC data via pulling instead of attaching to a broadcasting stream of hundread of MB of data a second.\r\n\r\nHowever, we quickly noticed that in roslibjs, the majority of the time taken to render the PoinCloud was in decoding the base64 encoding of the binary data.  After looking into this, it turns out that with VERY minimal changes, rosbridge and roslibjs can be set up to use BSON (just 'apt-get install python-bson' and get the bson.js) and point clouds can be passed as binary blobs with no problem.  We've been running this for weeks and see a speedup from 65ms to unpack and render a 3D point cloud from a Carnegie Robotics Multisense to a 15ms.  That's a HUGE performance increase.\r\n\r\nBelow I tack on the siff to show how simplt my changes are, and would like to encourage rosbridge and roslibjs devels to switch to using BSON for server to client message passing, while still using JSON for client to server message, service, param comms as that is typically very small amounts of data.\r\n\r\n```\r\npbeeson@tardis:~/projects/PROWL/code/rosworkspace$ diff -r rosbridge_suite/src ~/Desktop/rosbridge_suite-develop | grep -v pyc\r\nOnly in rosbridge_suite/src: CMakeLists.txt\r\ndiff -r rosbridge_suite/src/rosbridge_library/src/rosbridge_library/internal/message_conversion.py /home/pbeeson/Desktop/rosbridge_suite-develop/rosbridge_library/src/rosbridge_library/internal/message_conversion.py\r\n43d42\r\n< import bson\r\n104c103\r\n<             return bson.Binary(inst)\r\n---\r\n>             return standard_b64encode(inst)\r\ndiff -r rosbridge_suite/src/rosbridge_library/src/rosbridge_library/protocol.py /home/pbeeson/Desktop/rosbridge_suite-develop/rosbridge_library/src/rosbridge_library/protocol.py\r\n42d41\r\n< import bson\r\n264,265c263\r\n<             #return json.dumps(msg)\r\n<             return bson.BSON.encode(msg)\r\n---\r\n>             return json.dumps(msg)\r\ndiff -r rosbridge_suite/src/rosbridge_server/scripts/rosbridge_websocket /home/pbeeson/Desktop/rosbridge_suite-develop/rosbridge_server/scripts/rosbridge_websocket\r\n105c105\r\n<         IOLoop.instance().add_callback(partial(self.write_message, message, True))\r\n---\r\n>         IOLoop.instance().add_callback(partial(self.write_message, message))\r\ndiff -r rosbridge_suite/src/rosbridge_server/scripts/rosbridge_websocket.py /home/pbeeson/Desktop/rosbridge_suite-develop/rosbridge_server/scripts/rosbridge_websocket.py\r\n105c105\r\n<         IOLoop.instance().add_callback(partial(self.write_message, message, True))\r\n---\r\n>         IOLoop.instance().add_callback(partial(self.write_message, message))\r\n```\r\n\r\nAnd for roslib.js\r\n```\r\npbeeson@tardis:~/projects/PROWL/code/BrowserUI/modified$ diff roslib.js ~/Desktop/roslib.js \r\n1,2d0\r\n< var BSON = bson().BSON;\r\n< \r\n1092,1102c1090,1095\r\n< \tvar reader    = new FileReader();\r\n< \treader.onload  = function() {\r\n< \t    var uint8Array = new Uint8Array(this.result);\r\n< \t    var msg = BSON.deserialize(uint8Array);\r\n<   \t    if (msg.op === 'png') {\r\n< \t\tdecompressPng(msg, handleMessage);\r\n< \t    } else {\r\n< \t\thandleMessage(msg);\r\n< \t    }\r\n< \t}\r\n< \treader.readAsArrayBuffer(message.data);\r\n---\r\n>       var data = JSON.parse(typeof message === 'string' ? message : message.data);\r\n>       if (data.op === 'png') {\r\n>         decompressPng(data, handleMessage);\r\n>       } else {\r\n>         handleMessage(data);\r\n>       }\r\n```"},"comment":{"url":"https://api.github.com/repos/RobotWebTools/roslibjs/issues/comments/73277049","html_url":"https://github.com/RobotWebTools/roslibjs/issues/155#issuecomment-73277049","issue_url":"https://api.github.com/repos/RobotWebTools/roslibjs/issues/155","id":73277049,"user":{"login":"pbeeson","id":3858374,"avatar_url":"https://avatars.githubusercontent.com/u/3858374?v=3","gravatar_id":"","url":"https://api.github.com/users/pbeeson","html_url":"https://github.com/pbeeson","followers_url":"https://api.github.com/users/pbeeson/followers","following_url":"https://api.github.com/users/pbeeson/following{/other_user}","gists_url":"https://api.github.com/users/pbeeson/gists{/gist_id}","starred_url":"https://api.github.com/users/pbeeson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pbeeson/subscriptions","organizations_url":"https://api.github.com/users/pbeeson/orgs","repos_url":"https://api.github.com/users/pbeeson/repos","events_url":"https://api.github.com/users/pbeeson/events{/privacy}","received_events_url":"https://api.github.com/users/pbeeson/received_events","type":"User","site_admin":false},"created_at":"2015-02-06T17:24:00Z","updated_at":"2015-02-06T17:24:00Z","body":"Also added this as an issue in rosbridge_suite as it affects both server and client.\r\nhttps://github.com/RobotWebTools/rosbridge_suite/issues/169"}}