Trouble publishing large data from Unity using WebSocketSharp quickly

Hi!

I’m trying to send occupancy grid information from Unity to the Ros robot software (I’m simulating a robot’s environment and then passing the corresponding occupancy grid to the actual robot’s path planning system to test how it performs). This requires me to send an occupancy grid message with a grid size of 400x400 at 15Hz, as this is how the robot functions in the real world. Unfortunately, I’m having trouble sending these large messages (~320KB) fast enough, and am only successfully publishing to a topic at 5Hz.

I’m monitoring the performance of WebSocketSharp’s SendAsync() function, and for every 15 messages I try to send per second, only 5 respond with a success message. I’m pretty confident this is a data size issue, as smaller grid sizes pose no problem, and the problem gets worse as I try to pass larger arrays in the message.

I worked hard to isolate the problem to just be due to the websocket, which required serializing my json string in an efficient way. My unity project runs at around 60Hz, so I don’t think the issue is there (of course changing the SendAsync websocket call to just Send() makes the project run at 5Hz as the code waits for success messages).

Any ideas on how to speed up performance on sending large messages through the web socket using WebSocketSharp? Is there anything WebSocketSharp might be doing to cause this issue for me when I start working with large message sizes? It is currently just publishing to my localhost:9090, so shouldn’t be any network problems (I’d think). I went into WebSocketSharp and stopped it from fragmenting/chunking my message, which actually increased my sending rate to 6Hz – so it seems like this is some ‘overhead’ issue in WebSocketSharp per message.

Also, any ideas on how to shrink my message size? The size comes out to around 320KB because the json message with a 160,000 character array is written to a string and then converted to bytes (messages are required to be in json for communicating with Ros through RosBridge – at least I think).

Thank you! Any help is much, much appreciated! I’ve been really pulling my hair out over this as I just don’t see what could be the issue here.

You could consider sparse arrays. Is every element of the grid of 400x400 changing 15 times a second? If not, you could just send the differential. Are you on Wifi or Cable? It looks like you would need at least 5 Mb/sec. I trust you tested at 15Hz with a very short payload to compare.