You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@lws-team Hello Andy
I have seen some lws minimal http examples(server).
All samples looks using LWS_RECOMMENDED_MIN_HEADER_SPACE size buffer for reply back.
But, i want to use more than LWS_RECOMMENDED_MIN_HEADER_SPACE size buffer.
If server wants to reply back for GET method as json type more than LWS_RECOMMENDED_MIN_HEADER_SPACE, is it safe the server to write json data(more than 2048) in lws_writable callback ?
Thanks.
The text was updated successfully, but these errors were encountered:
It's generally safe to write larger amounts at once, but it's not efficient. Maybe you don't care too much in your use case which is fine then.
lws is told by the POSIX apis when an fd can accept "more" data (ie, is writeable). But it doesn't have a way to know how much data will be accepted by the fd kernelside... if memory is under pressure, that's a very dynamic piece of information controlled by how fast the sent data is being acknowledged vs the tcp window size. When you ask to write n bytes, the libc api copies into kernel memory the whole n bytes, then does the write call kernelside and then really finds out how much it will accept to buffer kernelside on the fd. The rest of the copied-into-kernelside data (not the original of it in userland) is discarded.
If the tcp window for the fd is almost full, it may accept only one mtu's worth, typ 1500 bytes or so. lws will understand this situation and silently allocate and manage a userland buffer to hold the unsent data, and prioritize sending it out, concealing WRITEABLE callbacks until it is all gone.
If n was large, eg, many megabytes, this means we copied megabytes around, in order to send maybe 1500 bytes, it's going to lead to poor performance in both speed and memory usage.
That's why the general advice is to write relatively small things (eg, 2K, 4K, 16K or whatever) each time and ask for a new writeable callback for the rest.
@lws-team
Thanks, I got it.
If i managed buffer size (transmitting bytes at once) optimizingly, lws would free to manage memory for better performance ..
@lws-team Hello Andy
I have seen some lws minimal http examples(server).
All samples looks using LWS_RECOMMENDED_MIN_HEADER_SPACE size buffer for reply back.
But, i want to use more than LWS_RECOMMENDED_MIN_HEADER_SPACE size buffer.
If server wants to reply back for GET method as json type more than LWS_RECOMMENDED_MIN_HEADER_SPACE, is it safe the server to write json data(more than 2048) in lws_writable callback ?
Thanks.
The text was updated successfully, but these errors were encountered: