Reputation: 2577
I've been tasked with optimizing some scheduled tasks that run for hours. One of the tasks runs through data from 1995-present. My first thought (besides revising queries,etc) was to create a cfloop through all the years and start a thread for each year.
Is this a good approach? Is there a better way to divide up the workload on such a task?
Upvotes: 1
Views: 90
Reputation: 3036
You really need to work out what is slow before you optimize anything. Otherwise you may spend a lot of time tweaking code for relatively small gains. Databases are often the bottleneck but you need to find that out first.
At a simple level, you can enable debugging (on a dev machine) and see where time is being spent. There are also tools like Fusion Reactor which will give you more insight. Alternatively you can can just add some <cflog>
calls to your script and then analyze them to identify the slow blocks. Which ever way you decide to do it, you need to know where your effort is best spent.
Some other thoughts....
If not then compile the data once and store it so that the scheduled tasks don't have to redo the work each time
You could run out of threads if you are not careful - which would be particularly bad if your server is running other stuff. But yes, threads could be part of your solution.
Upvotes: 2