Link to home
Start Free TrialLog in
Avatar of DaveThomasPilot
DaveThomasPilotFlag for United States of America

asked on

How to prioritize Web Access between threads

I have a Windows C++ application that needs to access the web for a few kbytes of data every few minutes.  Latency for those bytes must be reasonably low--less than a second.

The application creates many files, each around 1 Mb.  If I upload those files while the my application is running using Filezilla,  my application suffers from occaisional time-outs, even with time-out set to as long as five seconds.

Can I  add a thread to my application to upload files in such a way that would avoid impacting latency on getting those 1 Kbyte web accesses?  Would it be sufficient to just have the thread that does the uploading be at a lower priority, or are there shared resources (Wifi, and everything else between my pc and the cloud) that could be consumed by the file upload, even it's thread is lower priority?
Avatar of Frosty555
Frosty555
Flag of Canada image

I don't think this is a thread priority issue, it's a quality-of-service issue on your network.

FileZilla is uploading a file. It is most likely saturating your available Internet upload bandwidth. When this happens there is a long lag for any other applications that are accessing the internet, in particular anything that requires a back-and-forth handshake like an HTTP Request. Your application's HTTP Request is queued behind a mile of Filezilla packets all waiting to be transmitted.

The simplest thing to do is simply throttle Filezilla's upload rate to something that is less than your ISP's upload bandwidth limit. Check your speeds at www.speedtest.net, and give Filezilla maximum of something like 50-60% of the upload speed.

A better solution is to have a router which is capable of QoS / bandwidth priority. Configure it so that HTTP traffic has high priority and FTP traffic has low priority. But this needs to be done at the Router level, because the lag is not being caused by your computer - it's being caused by your network.

Realistically, because the Internet is a best-effort service and because lags on the network DO happen (it may not necessarily be your computer causing the problem, somebody else on the network could be saturating the bandwidth), you really have to have a 30-60 second timeout for web requests.
Avatar of DaveThomasPilot

ASKER

I've tried used the "speed limits" on FileZilla then checking if the ping response to unrelated sites (like google.com) make a difference.  It didn't seem to have any impact.  
Maybe the FileZilla speed throttling mechanism reduces data transfer on average, but the "time constant" over which the slower average upload speed  is too long to be useful for a tiny Http request to get a crack at the bandwidth with low latency.

Generally, I'll have no control over the router.  The applicatiion is used at many different venues, with public wifi networks.  Are you suggesting I have a dedicated router for my pc that connects to the public wifi?  Would there be no way to do something on my pc to eliminate the need for the external router?  And how would that work anyway, there's only one Mac address for my laptop from which both the ftp transfers and the http requests are coming.


Instead, I'm thinking along the lines of doing something like an ftp from a lower priority thread (C++ code), but transfer partial files instead of a regular file. Target the file fragment size so that it rarely takes more than about a second for the file fragment to upload.  I  After the end of each fragment upload  (or time out if the upload took more than a time out period), do a "SwitchToThread()". or an equivalent call to relinquish the threads timeslot to the application's latency critical thread.

So, something like an ftp, but with extra parameters to limit the number of bytes transfer, a time-out, and the ability to keep track of how much of the file got uploaded so the next transfer attempt could start from that place in the file.

That would mean something would have to run on the host side, to "reassemble" the file fragments and create/save the file when all the data had arrived.

I was hoping that I was just ignorant of some common file transfer technique that was like ftp, but had this type of additional functionality.

?
ASKER CERTIFIED SOLUTION
Avatar of Frosty555
Frosty555
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, I'll try setting the speed limits even lower on FileZilla.

Thanks for the netbalancer.  That looks really interesting!  I'll probably give that a try if using lower speed limits on Filezilla doesn't help.

Dave Thomas