esphome-stream-server icon indicating copy to clipboard operation
esphome-stream-server copied to clipboard

Buffer `send_buf` for high throughput

Open ayufan opened this issue 3 years ago • 5 comments

Thanks for great component. It was great to find it :)

I was having a trouble when running UART on ESP8266 on 1.5M where there was clearly buffer overrun first on UART side, second on TCP side. This changes how this is implemented and makes it work pretty well by buffering UART receive, to ensure that TCP write succeeds. It is being retried on next try. This works for me well after these changes:

uart:
  id: uart_bus
  tx_pin: GPIO15
  rx_pin: GPIO13
  baud_rate: 1500000
  rx_buffer_size: 8192

Note: it would be great if this project would have license assigned (MIT preferable?). Currently, it is unclear under what conditions I'm contributing.

ayufan avatar Aug 29 '21 11:08 ayufan

Do I understand it correctly that the problem you want to solve is that if in high throughput situations, there could be read more data from the UART than fits in the TCP buffers, and data gets lost (because the result of tcp_client->write() isn't checked/handled properly)?

Note: it would be great if this project would have license assigned (MIT preferable?). Currently, it is unclear under what conditions I'm contributing.

There's a GPLv3 header in every file. I could add a LICENSE file to the repository, but the license should be pretty clear already.

oxan avatar Aug 29 '21 12:08 oxan

Do I understand it correctly that the problem you want to solve is that if in high throughput situations, there could be read more data from the UART than fits in the TCP buffers, and data gets lost (because the result of tcp_client->write() isn't checked/handled properly)?

Exactly. This happens with larger RX buffers on UART side. I have Linux-based devices that output 1.5M by default (Rockchip SBC) that easily overruns first UART (unless you enlarge buffer), second a way how it is written to TCP.

There's a GPLv3 header in every file. I could add a LICENSE file to the repository, but the license should be pretty clear already.

Ah. I did not notice that. I usually look for LICENSE. This is great! Thank you

ayufan avatar Aug 29 '21 12:08 ayufan

Do you plan to merge this PR?

bojanpotocnik avatar Oct 24 '21 14:10 bojanpotocnik

Do you plan to merge this PR?

Yes, but I've to find some time and energy to properly review, test and adapt this.

oxan avatar Oct 27 '21 15:10 oxan

@ayufan Could you rebase your PR? Thanks in advance!

syssi avatar Dec 31 '21 11:12 syssi

Hi! Sorry for the silence, I've neglected this project quite a bit over the last year.

Tonight I've finished refactoring the component to use ESPHome's socket abstraction (see #25). During that process I've also implemented something analogous to this PR, but in slightly different manner. I've used a ringbuffer and keep track of the read position of each client separately, so that one lagging client doesn't prevent sending of data to other clients (until the buffer is full). I've also made the buffer side configurable in the YAML configuration.

oxan avatar Feb 03 '23 01:02 oxan

Equivalent functionality has been merged with #25.

oxan avatar Feb 07 '23 21:02 oxan