> I'd like to be able to measure the response times of
> thousands of various URLs I have in a database. This
> is one way:
>
> <CFOUTPUT QUERY="GetSites">
>
> <CFSET TimeHack1 = TimeFormat(Now(), 'hh:mm:ssTT')>
>
> <CFHTTP URL="#GetSites.URL#"
> METHOD="GET"
> resolveURL="1"
> throwOnError="YES">
> </CFHTTP>
>
> <CFSET TimeHack2 = TimeFormat(Now(), 'hh:mm:ssTT')>
>
> <CFSET TimeDiff = DateDiff("s", TimeHack1, TimeHack2) * 1000>
>
> <H1>Ping time: #TimeDiff# Milliseconds!</H1>
>
> </CFOUTPUT>
>
> The PROBLEM with this method is that the ColdFusion time
> functions only allow resolution to the nearest second, so
> I get results like 0, 1000, 2000, 3000 etc., a very crude
> measurement when what I really want is response time in
> milliseconds.
As JediHomer mentioned, you can use GetTickCount for this. You would need to
run it immediately before and after the CFHTTP:
<cfset start = GetTickCount()>
<cfhttp ...>
<cfset end = GetTickCount() - start>
However, I wouldn't recommend that you use CFHTTP - or CF at all - for this.
Instead, you'd be better off using some asynchronous process outside of CF
for this.
> Here is another way to to potentially solve the problem ...
> ...
> The PROBLEM with this second method is that it's got to be
> horribly inefficient to repeatedly call Ping.exe with CFEXECUTE
> (and wait for four replies), write a file, then read the file.
There's a bigger problem in my opinion - it doesn't tell you anything about
HTTP response times, or even whether a web server is running. ICMP isn't
HTTP. You may ping the IP address of a web server, and that web server may
not accept ICMP requests, so the ping would fail. Alternatively, you could
ping a machine that isn't even running a web server.
But again, if you were going to take this approach, I'd recommend that you
do most if not all the work somewhere other than CF. You could write a
program that takes a list of IP addresses or DNS names, pings each, parses
the results, and writes them to a file. From CF, all you'd have to do is
launch that program and provide it with the address list. This kind of thing
is pretty simple using a shell script or batch file, I think.
> 2) Secondly, because CF is limited in the number of
> simultaneous threads it can handle (I'm using CF 5 although
> I could use MX 6 if I really had to), what happens if
> thousands of CFHTTP requests are made this way very quickly?
> Does CF just stop and wait until there are threads available
> or could so many CFHTTP requests lock up the server this app
> would be running on? I suppose I could throttle down the
> request rate if I had to, there isn't any reason why thousands
> of CFHTTP requests have to be made all in one batch. So I guess
> this question boils down to: what would be the maximum number
> of CFHTTP requests that I should burden the server with at
> any one time?
I'm not sure, but I believe that all the CFHTTP requests will be processed
synchronously, one after the other, by the same thread that's processing the
page. So you wouldn't use additional threads, but it would take a long time
for that request to complete.
> 3) Finally, CFHTTP if successful will return all the code
> from the URL called, unlike Ping.exe. I like this fact
> because it will give me a truer response time for each URL
> in my database, but all I actually need is the response time
> in milliseconds. Is all the data returned going to fill up
> RAM on the server or worse go to disk cache, or can I somehow
> tell CF to discard it immediately?
Each CFHTTP tag you run will overwrite the results of the previous CFHTTP
within that page. I don't know if the underlying memory management uses the
same memory for each one, but I would assume so. You could easily test this,
however, by looping over a set on an unused server, and seeing if memory
continues to increase while the request is running.
Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
Fig Leaf Software provides the highest caliber vendor-authorized
instruction at our training centers in Washington DC, Atlanta,
Chicago, Baltimore, Northern Virginia, or on-site at your location.
Visit http://training.figleaf.com/ for more information!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking
application. Start tracking and documenting hours spent on a project or with a
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:214322
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54