Trouble with speed and ETA calculations

mscdex

Member
Joined
Feb 21, 2007
Messages
5
Programming Experience
5-10
I have a file transfer client and server that works just fine and uses tcplistener and tcpclient. My problem is this: when I transfer this one file over the internet for testing, almost exactly at when 43% of the transfer is complete, the transfer rate suddenly inflates really high and the ETA drops like a brick. Before this though, the speed and ETA are displayed correctly. However after it inflates, it does start to level out, but it takes a very long time for it to go back to what it should be reading. This happens consistently, with other large files this happens also, but at a different completion percentage.

I have tried changing the client side to send small chunks of the file at a time instead of writing the entire contents to the networkstream at once, but that made no difference. Initially I was only having it update the speed and ETA display every so many seconds, but the artificial inflation still ocurred. The aforementioned file is only 12.1mb.

Does anyone have any suggestions as to what might cause this to happen consistently?
 
Ok I'm going to answer my own post here. What seems to have corrected this problem was I changed how the rate was calculated (thus affecting the ETA, since it is based on the rate). I was dividing the total amount of bytes currently received by the amount of time elapsed since the start of the transfer. This evening I tried another method that still makes logical sense and should still yield the same correct rate and ETA (and what eventually seemingly fixed my problem). I instead used the difference between the previous total amount received and the current total amount received and divided that by the change in time from when the previous total amount changed to now.

I.E.:

VB.NET:
nowTime = Now
amountReceived += BytesRead

If (nowTime - lastUpdate).Seconds >= UPDATE_INTERVAL Then
     TransferRate = (amountReceived - lastChunk) / (nowTime - lastUpdate).Seconds ' this is our bytes/second transfer rate
     ' ------
     ' Generate the rate and ETA text for display
     ' ------
     lastChunk = amountReceived
     lastUpdate = nowTime
End If

' write to file here
 
Back
Top