coldfusion and exceeding time limits
I've got some long and complex code that does a bit of parsing, and takes a while to go through, it doesn't make much sense in this case to optimize the code.
What are the strategies for handling long execution times and letting the user know when it is done?
explanation of why it doesn't make much sense to optimize
The application has end-user-facing pages and non-end-user-facing pages. In the non-user facing area I am parsing several excel spreadsheets. Loading and looping through these takes a long time. It I optimize the code to run within my timeout limit it might work today, but a month from now I might be importing a file that's 4 times as long and it won't work yet again. The issue I am trying to solve is getting around the cf timeout for a specific operation that I know takes a long time.
I've tried using threads but for some reason worked on CF9 but not CF8 (though they are supported)
I also just found out about cfsetting requestTimeOut
which might be able to do what I need to do.
You've probably looked into it already, but see if anything could be cached, to reduce the amount of time waiting.
As for communicating it to the user, for starters make sure the user knows when things are happening. One of the worst things a program can do is receive input and not react. Make sure the user is well aware when something is happening. The way you display the loading is up to you. There could be an hourglass of sorts if the loadtime is under roughly ten seconds or so, but if the wait is longer you'll likely want a progress bar or something similar.
If there is any way you can allow some of it to happen in the background or during other processes, that could help ease the load. Otherwise, pop up a suggestion that tells them to go get coffee. :)
This is just a kneejerk response with only a little information, but if you can give more of an idea on what you are looking for and rough load time estimates I could maybe get more specific.
Approach 1
I had a site on II6 and CF 7. I added this bar graph that was manipulated via Javascript. I would then set the length of the graph via a Javascript followed by a <cfflush>
.
It worked well until the site got upgraded to II7.5 and CF 9. For some reason <cfflush>
does not work, the Javascript can still set the bar and give a meaningful progress.
Approach 2
This requires two iframes.
One iframe runs the long running process and is hidden from the users view.
The other iframe runs a page that refreshes every 10 seconds or so. This page queries the back end logging for the slow process. It may be 10 seconds behind, but end users may even notice
Approach 3
Do the same as approach 2, but with AJAX
Another approach is to start your page with something like this:
<div id="displayarea">
display something here
</div>
<cfflush>
Then do whatever processing you need to do. Once it's done, do something like this.
<cfsavecontent variable = "newdisplay_cf>
generate html here
</cfsavecontent>
<script>
<cfoutput>
var #toScript(newdisplay_cf, "newdisplay_js")#
</cfoutput>
document.getElementById("displayarea").value = newdisplay_js;
</script>
There may be some syntax errors here. I just typed the code into the textarea.
链接地址: http://www.djcxy.com/p/31200.html下一篇: coldfusion和超过时间限制