My Projects
Search Blog

Categories
Archives
Useful Links
Photo Albums
RSS

Powered by
BlogCFM v1.15

Vivio Technologies VPS Hosting
18 July 2006
Asynchronous HTTP from Coldfusion
Ever wanted to make an HTTP request but you didn't really care whether or not it returned anything successfully?

You can't do that with CFHTTP... well, you can, but you would have to still wait for it to finish before your page continued - it's not asynchronous.

Well, your prayers are answered.  Mark Mandel justed posted his AsyncHTTP package that uses existing java classes to perform asynchronous http GET and POST operations.

You can find out more here:
http://www.compoundtheory.com/?action=asynchttp.index
Posted by rickroot at 6:06 PM | Link | 0 comments
12 July 2006
Reading large files with java versus CFFILE

A question was posted on the cf-talk list (thread) about reading large files with CFFILE and problems they were having.

I suggested trying java to read the large file line by line and I posted the following code:

<cfsetting showdebugoutput="Yes">
<cfscript>
 cnt = 0;
 // large text file, 4MB, 80,000+ lines
 srcFile = "E:\Inetpub\wwwroot\tools\mass_email\list.dat";
 // create a FileReader object
 fr = createObject("java","java.io.FileReader");
 // Call the constructure with the source file path
 fr.init(srcFile);
 // create a BufferedReader object
 br = createObject("java","java.io.BufferedReader");
 // call the constructor with the FileReader as the arg
 br.init(fr);
 // read the first line
 str = br.readLine();
 // loop ... str will be undefined if there are no more lines
 while (isDefined("str")) {
  // do stuff with the string
  cnt = cnt + 1;
  // read the next line so we can continue the loop
  str = br.readLine();
 }
 // close the buffered reader object
 br.close();
 writeOutput(cnt);
</cfscript>

 

The code above was tested on CFMX 7 and it does work.  On my server, it consistently returns the results in about 400ms (ranging between 350ms and 500ms).

In order to compare, I wrote some CFML code that does essentially the same thing using CFFILE and looping through the file content as a list with chr(10) as the delimiter.

The CFFILE route was slower and much more erratic, ranging from 450ms to over 2000ms - probably averaging 1400ms in the 20-30 times I reloaded the page.

So if you're reading a large file and doing line by line processing - consider using native java rather than CFFILE.

Posted by rickroot at 2:15 PM | Link | 1 comment