[lwip-users] Performance issues when using the raw TCP API of lwIP
From:
private private
Subject:
[lwip-users] Performance issues when using the raw TCP API of lwIP
Date:
Thu, 24 May 2012 10:56:15 +0200
Hello,
I use lwIP to add networking functionality to my system. On my platform i built a buffer that i want to send every time it is full. This can happen quite quickly. The system is directly connected to a switch in a private LAN. Initially the sending of data had a very large time gap in between of 2 seconds. Additionally the packets had a size of 720 bytes if my memory serves me correctly. The used buffer currently has capacity for about 20000 bytes and I might decide to increase this in the future. The network has 100 mbit speeds and I would like to come close to these speeds on my platform.
When searching for the cause of the slow speeds I ended up at lwIP's configuration. Prior to that I altered my sending mechanism. I use the raw lwIP API and at present I write the data as follows:
tcp_write(<pcb>, (const void*) data, <bytes>, TCP_WRITE_FLAG_COPY);
//<bytes> is at most tcp_sndbuf(<pcb>)
I know the copy flag creates a performance hit, but this is added because I don't want to overwrite data before it's actually sent. (and the flag isn't the main problem but something to polish once it's working properly) In a prior solution i omitted the flag and simply waited for all bytes to be ACK'd (after forcing data to be send after writing by calling tcp_output()) by using the callback function. (This might be worse performance wise and I dont think it's related)
I played a little with the settings in the of lwIP and that seemed to make some difference. I think the window size especially made a difference although I'm not quite sure. At the moment I increased the window size significantly and even though I get a burst of packets with about 2ms between them (instead of 2s!) this is followed with a long period of "nothing" and then a burst again. I want it to continuously send at the speed it should be capable of which should be 100 mbit at most but atleast 10 mbit is not weird to expect, right?
I loaded up wireshark to see what was happening.
192.168.1.26 is my desktop computer running windows. 192.168.1.192 is the embedded system that's using lwIP.
Initially I send a start request from the desktop to the lwIP system, letting the system know it should start sending the buffer each time it is full. In case it is relevant, this is the corresponding part of the trace:
I believe this is alright although i'm not certain. Anyway, after this the actual sending happens. The relevant trace looks as follows The start time is 207.992115 which should be considered the starting time. The difference between that and the 7.177903 is expected:
Now after this point there is a huge delay that I cannot explain. The next packets arrive at 345 seconds, this is a 135 second difference. (although in most cases it was a bit less, but still wayy too high) It starts as follows:
Later on a similar problems occur although the mentioned delay is shorter. My question is: How can I fix the problem of the slow sending from my platform and how should i configure my lwIP settings to expect decent/good results? I want to send the data at fast speeds. (my network is capable of 100Mbps, the closer the better) I think i currently messed up my settings entirely but I am not sure how to finetune them for my needs. Here are some (hopefully) relevant settings from my lwipopts.h