espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.83k stars 7.32k forks source link

[WebSocket Transport]: aggregate or cork writes to underlying transport (IDFGH-14105) #14914

Open bryghtlabs-richard opened 5 days ago

bryghtlabs-richard commented 5 days ago

Is your feature request related to a problem?

WebSocket writes (eventually calling tranport_ws.c's _ws_write() function) tend to create more packets than needed. This increases single packet upload latency from 1 packet to 3 packets:

  1. Client->Server: TLS send WebSocket header, Nagler blocks payload upload
  2. Server->Client: TCP ACK for WebSocket header packet, unblock Nagler
  3. Client->Server: TLS send WebSocket payload

Describe the solution you'd like.

I'd like _ws_write() to either batch writes to esp_transport_write(), or to add something like esp_transport_cork() and esp_transport_push() to the transport layer so that higher layer transports can combine writes that would then be sent only when esp_transport_push() is called.

Describe alternatives you've considered.

Nagle's algorithm doesn't help here - the first TLS packet containing the WebSocket frame headers is sent immediately, and the TLS packet containing the WebSocket payload deferred until the other side aknowledges the first TLS packet. Once the acknowledgement is received, the Nagler is disabled and the payload is uploaded.

Additional context.

image