-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sending data in MB takes long time #3295
Comments
You noticed that the library, plus your code / config, on your platform, with your connection, and your specific route between the two peers, acts a particular way. Depending on the details of all those things, sending 1MB/sec might be perfectly reasonable. I would look first at how large are the individual packets coming out, and what size are you asking lws to send each time? Where are you sending it? Does it act differently if the peer is on 127.0.0.1 / lo and no actual internet involved? |
I am reading data from a file & sending 512 kb each time. Memory for 512 kb buffer is allocated before reading the file. It's on local network from machine 1 to machine 2. I am using libwebsocket on windows & sending on linux server. |
Yeah don't try to send large amounts like 512KB at one time, it cannot actually succeed to do it unless the tcp window has space for it. What it does instead is accept what you asked for, and buffer again what couldn't actually be sent in the tcp window by doing it in the background. So you should think about sending eg 4KB or at least no more than 16KB, which is the size of the tls buffers for the connection. You should generate the next 16KB to be sent in the writeable callback and ask for another writeable callback while still more to send. How long it takes to get the next writeable callback depends on what you're sending and the tcp window situation as ACKs arrive. Check the sizes of packets actually going out on the wire, eg, with wireshark. |
I think I'm not able to upload the image so writing some details here Frame 114074: 1272 bytes on wire (10176 bits), 1272 bytes captured (10176 bits) on interface |
... that's not how event loops work... please follow the examples provided instead of making up your own. You need to ask for lws_callback_on_writable() every time you want to write something. And in the WRITEABLE callback, it is an indication that you have the go-ahead to write something. After writing it, 4K, 16K or whatever, if something else to write then you must ask for lws_callback_on_writable() again and exit the callback. When it's possible to write on the connection again, you will get the next WRITEABLE callback. POSIX indicates a POLLOUT event on the connection when you can write "something". It doesn't indicate how much; it depends on how many packets where ACKed, clearing space for you to send more. If you write more than the kernel will accept, lws has to buffer the remainder and send it in the background, If you take this wrong approach where you imagine you can loop "sending" everything in one callback, you are just buffering all the data locally and are made to wait until it is actually issued in the background. Network programming does not work sitting there in a loop spamming things that can't be sent. How it can work is you will fill up the tcp window and have to wait to send more, the gap between asking for the writeable callback and getting it is regulating your production of outgoing data vs the connection's ability to absorb it. |
I checked examples & follow the same steps. Changed the callback code int pos = 0, sent = 0; lws_callback_on_writable(wsi); But still there is same issue. |
Nope... show me the example where we sit in a loop doing more than one lws_write() in a writeable callback? The examples do not work like that because I know that if we get a POLLOUT event, if we are bulk-writing, it usually means we have space in the tcp window only for a handful of packets (this space created by hearing about ACKs received from the peer). It's stupid then to sit in a loop filling up heap with buffered copies we cannot send until later. We should emit a small amount, ask for a callback when more writeable, and then go back to the event loop. In particular, each WRITEABLE should only produce a single lws_write(). |
There is no such case when it was executing more than one time inside the loop in callback. It was just a safe check. |
The problem didn't solve after using the latest version 4.3.3. It's uploading 350 mb of data in 5 mins. |
I am using libwebsockets to send data using WSS connection. I noticed that the library sends max 60 mb of data per minute.
To send data I followed following steps:
Please suggest what wrong I am doing. Is there any way to increase the speed?
The text was updated successfully, but these errors were encountered: