views:

355

answers:

7

Every once in awhile I am fed a large data file that my client uploads and that needs to be processed through CMFL. The problem is that if I put the processing on a CF page, then it runs into a timeout issue after 120 seconds. I was able to move the processing code to a CFC where it seems to not have the timeout issue. However, sometime during the processing, it causes ColdFusion to crash and has to restarted. There are a number of database queries (5 or more, mixture of updates and selects) required for each line (8,000+) of the file I go through as well as other logic provided by me in the form of CFML.

My question is what would be the best way to go through this file. One caveat, I am not able to move the file to the database server and process it entirely with the DB. However, would it be more efficient to pass each line to a stored procedure that took care of everything? It would still be a lot of calls to the database, but nothing compared to what I have now. Also, what would be the best way to provide feedback to the user about how much of the file has been processed?

Edit: I'm running CF 6.1

A: 

SQL Server Integration Services (SSIS) is the recommended tool for complex ETL (Extract, Transform, and Load) work, which is what this sounds like. (It can be configured to access files on other servers.) The question might be, can you work up an interface between Cold Fusion and SSIS?

Philip Kelley
+4  A: 

I just did a similar thing and use CF often for data parsing.

1) Maintain a file upload table (Parent table). For every file you upload you should be able to keep a list of each file and what status it is in (uploaded, processed, unprocessed)

2) Temp table to store all the rows of the data file. (child table) Import the entire data file into a temporary table. Attempting to do it all in memory will inevitably lead to some errors. Each row in this table will link to a file upload table entry above.

3) Maintain a processing status - For each row of the datafile you bring in, set a "process/unprocessed" tag. This way if it breaks, you can start from where you left off. As you run through each line, set it to be "processed".

4) Transaction - use cftransaction if possible to commit all of it at once, or at least one line at a time (with your 5 queries). That way if something goes boom, you don't have one row of data that is half computed/processed/updated/tested.

5) Once you're done processing, set the file name entry in the table in step 1 to be "processed"

By using the approach above, if something fails, you can set it to start where it left off, or at least have a clearer path of where to start investigating, or worst case clean up in your data. You will have a clear way of displaying to the user the status of the current upload processing, where it's at, and where it left off if there was an error.

If you have any questions, let me know.

Other thoughts:

  1. You can increase timeouts, give the VM more memory, put it in 64 bit but all of those will only increase the capacity of your system so much. It's a good idea to do these per call and do it in conjunction with the above.

  2. Java has some neat file processing libraries that are available as CFCS. if you run into a lot of issues with speed, you can use one of those to read it into a variable and then into the database

  3. If you are playing with XML, do not use coldfusion's xml parsing. It works well for smaller files and has fits when things get bigger. There are several cfc's written out there (check riaforge, etc) that wrap some excellent java libraries for parsing xml data. You can then create a cfquery manually if need be with this data.

Jas Panesar
Thanks for explaining your method, it's given my some guidance for running some massive data sets in CF.
JasonBartholme
Glad it was of use. I am sure it's not complete and at the least a list formed from learning what not to do and arriving at these. Good luck :)
Jas Panesar
+4  A: 

It's hard to tell without more info, but from what you have said I shoot out three ideas.

The first thing, is with so many database operations, it's possible that you are generating too much debugging. Make sure that under Debug Output settings in the administrator that the following settings are turned off.

  • Enable Robust Exception Information
  • Enable AJAX Debug Log Window
  • Request Debugging Output

The second thing I would do is look at those DB queries and make sure they are optimized. Make sure selects are happening with indicies, etc.

The third thing I would suspect is that the file hanging out in memory is probably suboptimal.

I would try looping through the file using file looping:

Terry Ryan
Looks like maybe you intended a code sample to be there at the end? If so, it's missing.
Adam Tuttle
A: 

If you can upgrade to cf8 and take advantage of cfloop file="" which would give you greater speed and the file would not be put in memory (which is probably the cause of the crashing).

Depending on the situation you are encountering you could also use cfthread to speed up processing.

Sam Farmer
Unfortunately, moving to CF8 is not an option at this point.
Jason
Is it possible to install the developer edition on your local machine and connect to the database. That way, you can take advantage of the CF8 features. I have done this in the past, but you may not be able to in your situation.
JasonBartholme
+1  A: 

Have you tried an event gateway? I believe those threads are not subject to the same timeout settings as page request threads.

Al Everett
A: 

Currently, an event gateway is the only way to get around the timeout limits of an HTTP request cycle. CF does not have a way to process CF pages offline, that is, there is no command-line invocation (one of my biggest gripes about CF - very little offling processing).

Your best bet is to use an Event Gateway or rewrite your parsing logic in straight Java.

Cody Caughlan
A: 

I had to do the same thing, Ben Nadel has written a bunch of great articles uses java file io, to allow you to more speedily read files, write files etc...

Really helped improve the performance of our csv importing application.

crosenblum