WebSockets very, very slow when sending ~1800 characters #5926
Replies: 1 comment
-
Posted at 2017-12-03 by MortenMoulder Okay, so I've opted for the "net" module instead as a socket server. It's much, much, much faster! I can easily do 50ms now without issues.
I had to hack it up a bit, because I send so many characters. I saw that the Works amazingly fast! Posted at 2017-12-03 by Wilberforce Each of your pixels is represented as 15 characters. You could make this shorter by: a. Removing spaces Posted at 2017-12-03 by MortenMoulder The problem wasn't the data being sent, the problem was WebSockets being slow as hell. I can do this probably faster than 20ms now using raw TCP socket. But yes, that's a good point. Posted at 2017-12-04 by @gfwilliams Yes, I'd just send as binary. I think most likely it's the masking/unmasking that happens for Websockets. That's done in JS with a repeated append at the moment, which is probably the reason for the slowness - but having to parse the JSON each time won't help either. The masking could reasonably easily be rewritten using Posted at 2017-12-04 by Wilberforce This npm module seems to support turning off masking: https://www.npmjs.com/package/ws-pure Posted at 2017-12-04 by @gfwilliams Neat - so if you used that on the server it'd probably be loads faster. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2017-12-03 by MortenMoulder
I have about 150 LEDs in a strip. I want to change those colors, based on patterns I write externally (in a browser for example). I send the 2D array like this:
and so on from my NodeJS server running the "ws" module as a server. The ESP8266 NodeMCU then connects to the NodeJS server, and waits for it to send the RGB colors for all these LEDs.
The problem occurs when I want to send the RGB codes for all 150 LEDs at once. This takes 1000-1500 milliseconds and it simply queues them up. If I keep it running for 30-60 seconds, then disconnect my NodeJS server, it will keep changing the colors on the LED strip, because it keeps the colors in a queue (because it's too slow?) .
I am running this on a local network and here is my Espruino code:
Any clue what could be wrong? Is 1800 characters simply too much?
Beta Was this translation helpful? Give feedback.
All reactions