I'm writing a program that uploads huge amounts of data and I need to limit it's interference with web browsing and other user activities.
The upload is composed of many large-ish files that are transferred individually, the connection must be a standard HTTP POST (I have no control of the server) and I need to control the HTTP headers (the server uses them for authentication and metadata)
It's important that the upload will resume full speed when the user is no longer using the internet because otherwise it will never finish (I expect it will need to run for a week or more at full speed to complete).
I want to solve this problem by somehow making my HTTP connection low priority, detecting open browser windows and slowing down does not solve the problem because (a) the user may be using a non-browser app (FTP, twitter client, e-mail, etc.) and (b) I don't want to slow down if there's an open idle web browser window.
I've found BITS but I think it's not relevant for me since I need it to be a standard HTTP POST.
I'm using .net 3.5, the program is written in C# and I'm currently using HttpWebRequest for the upload.
Clarification: I’m writing consumer software that will run on the customer’s personal computer at home. My beta testers complain that the internet is slow when they run my program (understandable, since I am using all their bandwidth) so I want to give higher priority to other programs so their internet is no longer slow.
There is no fancy network infrastructure that can prioritize packets on the network and no IT team to install and configure anything, I do expect most customers will have a cheap wireless router they got for free from their ISP
Simultaneously keep track of number of bytes your app sends and the total bytes sent on the network using the System.Net.NetworkInformation.IPv4InterfaceStatistics class' bytesSent Property at a given interval. Subtract the total bytes your app has sent in that interval from the total bytes sent on the network (during the same interval). If the difference is high enough to where you need to throttle your uploading then do so. Once the difference becomes small enough, crank up the uploading.
I hope you have the throttling end of the problem covered, so you only need to know two things:
and
Now, using other API-s is maybe fine, but why learn them and introduce all new kind of bug generators, when you can do something more simple.
Now - the problem with uploads with most internet connections (say ADSL) is that they consume precious UPLOAD that is extremely limited, say 256-512k. User probably report the problems because your upload is killing the requests they send, so they can't get any data back.
I am proposing that you do two things... to resolve WHEN problem, do this:
To resolve HOW MUCH is another question. First, you should measure how much you can upload when nobody else is using the connection - your baseline upload speed per client. Then, using the WHEN technique, you can throttle down the upload until you get 'free' result that will work for their connection.
Hope I made myself clear - ask if anything needs clarification.
EDIT:
Few more thing to consider:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With