Sign in to follow this  
Followers 0
lgodfrey

InetGet Timing

1 post in this topic

I am seeing some unexpected (to me) behaviour using InetGet and @InetGetActive that someone might know how to get around.

I have a script that downloads information from a URL and puts it in a format for easy use in Excel. I am trying to make the system run as fast as possible. I must not allow download times to exceed a certain amount of time (less than a second) without taking action, so I use background downloading with a loop to check to see how long the download is taking. The script is working great, typical download times are under 100 msec! But sometimes something unexpected happens.

The unexcpedted behaviour is that GetInet seems to "hang" sometimes. The attached code will illlustrate what I mean. It just starts a background down load, displays the time delta from before to after the InetGet call, waits 300 msec, and starts checking to see if the download is complete using @InetGetActive. ToolTips is used to display timing and cycle count info.

;Download timing tests********************************************
Opt ("MustDeclareVars", 1)    ;0=no, 1=require pre-declare      *************not default
Dim $SavedTXTfile, $K, $StartTime, $URL = "http://www.autoitscript.com/autoit3/", $Loops, $J
$SavedTXTfile = "C:\test3.txt"
$Loops = 1000
;$URL = "http://finance.yahoo.com/?u" ;uncomment this line to change to slower URL
$K = 0
InetGet($URL, $SavedTXTfile, 0, 0) ;force fast "down load" from cache
While $K < $Loops
    $K = $K + 1
    $J = 0
    $StartTime = TimerInit();initialize timer
    InetGet($URL, $SavedTXTfile, 1, 1) ;start download
;show the elapsed time from the start to the release back to the script by InetGet, plus a download number counter $K
    ToolTip("Cycle Time= " & Int(TimerDiff($StartTime)) & " " & $K)
    sleep(300)
    While @InetGetActive ;CHECK DOWNLOAD STATUS LOOP
        $J = $J + 1
         Sleep(20)
        ;show the elapsed time from the start to this check cycle, plus download counter, plus a check counter  $J   
        ToolTip("Cycle Time= " & Int(TimerDiff($StartTime)) & " " & $K & " " & $J & "  In @InetGetActive Loop")
    WEnd
    Sleep(300); sleep some time to allow each download to be visually differentiated
WEnd
ToolTip("")
Exit

The code will go into the check download loop if the download takes more than 300 msec after InetGet releases control back to the script. For my machine, most of the time the download will be complete in this 300 msec, but if it did not, you can see the J counter count up in the tool tip info box. The 300 might have to be changed to see this behaviour depending on trafic to the site and your system.

But un-comment the URL line to change to a yahoo finance site. This takes longer to download. Now, the first time display can be as long as 5 seconds!!! elapsed time after the start of the download!. Apparently, InetGet is not releasing back to the script very fast for a longer download site. The tootip with the J counter "never" shows up, meaning that the download is complete withing 300 msec of release back to the script from InetGet.

This is my guess as to what is happening. InetGet is not releasing control back to the script until the download process is actually in progress. That is, the first packets arrive back at your computer. Depending on the site, this can take quite a while. If the size of the file to download is small, then it might happen that when InetGet releases back to the script, the download is actually already completed.

Now for the help:

1) Is this interpretation right?

2) If so, what is the maximum size of file to download so that the download is complete when InetGet releases control?

3) Is there a way to stop and restart the download if InetGet doesn't release back to the script quickly? I suspect this might involve launching another exucutable script to acutally do the download, and monitor the target file from this script. If the target file does not get closed fast enough, then stop the executable (have no clue how to stop an running executable)

I have cable, actually runs close to the advertised 3MB/sec download speed, and a good speed PC.

Thanks in advance for some insightfull comments.

Best Regards

Larry


I'm, Lovin' IT, X

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0