[Libwebsockets] Packet size question

Andy Green andy at warmcat.com
Tue May 19 23:33:02 CEST 2020



On 5/19/20 9:52 PM, Brice Hamon wrote:
> Hi guys,
> 
> I was wondering about payload size in lws.
> 
> Is there a maximum size pre-defined, or I can allocate a big buffer and 
> use lws_write() to let lws manage the fragmentation?
> 
> So far we are hitting around a 273872 chars limit somewhere.

No, should should definitely chop it up yourself into something 
reasonable.  lws doesn't have any fixed limit but if your connection 
gets choked, space will appear in the tcp window as things are acked, if 
the connection is relatively slow that will manifest itself as the tcp 
stack being willing to send "a bit more" measured in mtu-sized packets. 
Exactly how much it will accept depends on the platform, memory pressure 
and the state of the tcp window, but typically somewhere between 1 and 2 
mtu is a good bet, so chunks of 1.4 .. 2.8KB.

If you try to send giant buffers it all goes on the heap and it's very 
inefficient in that for every send(), the whole of the giant buffer is 
copied into kernel space each time, even if it ends up the network stack 
only used 2KB of it.

If it's ws protocol you can mark the writes after the first as not 
having a FIN, so it's a continuation of an existing ws message in its 
own frame.

If it's eg http body you can just keep sending the next part.

-Andy

> Thank you,
> Brice.
> 
> 
> 
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> https://libwebsockets.org/mailman/listinfo/libwebsockets
> 


More information about the Libwebsockets mailing list