Replies: 3 comments
-
Hi @mdmitry Thanks for using those libraries. IMO, for speed-demanding use cases, it's better to use TCP Sockets, not even WebSockets, unless there is some reason to use WebSockets. You can research to get the real reasons, even somewhere in my libraries I have no time to check now. The AsyncWebServer / AsyncWebSockets_Server is good for multiple-simultaneous-client server (more than one connection at the same time), certainly you have to know where / how to limit the number of concurrent clients because the memory limitation of MPUs, depending on many settings, such as core, IDE, compiler, your LwIP stack-size settings, etc. I still don't think this Good Luck, |
Beta Was this translation helpful? Give feedback.
-
@khoih-prog Thanks for your reply, and for all your work on Arduino libraries. In my case I've switched from sync (WebServer + WebSockets2_Generic) to async primarily to stop audio dropouts when another user loads the web-interface. Actually by getting client() I'm already using raw AsyncTCP after AsyncHTTPRequest_Generic prepares the WebSocket connection, and it works really good, and the only reason the library performs worse is because it's waiting for ACK after every message. And my use-case is not as demanding as it may look, back when using WebSockets2_Generic ESP32 could serve 2 simultaneous clients without dropouts, each having two connections - one for audio and one for control, and I'm sure AsyncHTTPRequest_Generic can perform even better due to its efficient async nature. The article talks about 10-100 MB/sec and 0.02ms latency, while I only need 0.05 MB/sec, or a packet every 30ms. Completely different orders of magnitude, WebSocket overhead doesn't matter at all in my case. I would happily make those minor changes to make AsyncHTTPRequest_Generic WebSockets perform at least as good as WebSockets2_Generic, but I'm not sure I will be able to commit the patch to github afterwards (never contributed to github projects before), and I wouldn't want my work to go to waste. |
Beta Was this translation helpful? Give feedback.
-
If not so demanding, you can try adapt from example Async_WebSocketsServer_Xtreme, which is both AssyncWebServer and AsyncWebSockets Server. Multiple Clients can connect to AsyncWS server.
It's also good if you can improve this library with your PR. The PR process is so simple, especially for expert like you. We're all have to learn something everyday to be happy. |
Beta Was this translation helpful? Give feedback.
-
Hello,
I'm crafting an FM receiver using ESP32 with a web interface, it receives audio via I2S, compresses it 4x with ADPCM, and sends it to the browser using WebSockets, I've chose message size of 1430 bytes (almost full single TCP packet) to minimize latency and keep efficiency. Transferring 48000 Hz audio this way requires 33 packets/sec, or a packet every 30 ms.
Doing this using AsyncHTTPRequest_Generic turned out to be too slow, with Wireshark I've found that after sending an audio message ESP32 did not send the next audio message until TCP ACK from the browser arrived after 40 ms (that's Windows ACKing algorithm), unlike previously used WebSockets2_Generic, where ESP32 sent 2 audio packets followed by an ACK.
Turns out sending a second message calls _queueMessage() --> _runQueue(), where _messageQueue.front()->betweenFrames() returns false (_acked != _ack), thus the next message is not sent until ACK is received.
This limits maximum throughput to 25 messages/sec, unless every message is actively replied with another message.
I've worked this around by adding my own WS headers to audio and sending them directly to the socket (client->client()->add()/send()).
It would be very nice if AsyncHTTPRequest_Generic WebSockets could send as much messages as fit into the send window (5744 bytes on ESP32 on Arduino) without waiting for ACK, this would need ability to ACK multiple messages by a single ACK.
It would allow sending hundreds of messages per second and improve responsiveness, especially when communicating over WAN.
Just a suggestion for improvement, thank you for reading this.
Beta Was this translation helpful? Give feedback.
All reactions