2

I have a controller action that aggregates data from multiple sources: web service, database, file lookups, etc... and passes results to the view. So in order to render the page all tasks must have completed. Currently they are performed sequentially but as they are independent I am thinking of running them in parallel as this could improve performance.

So what would be the best approach to achieve this? For each task start a new thread and block the main thread as all tasks are finished? Should I use a thread from the thread pool or spawn a new thread manually? Using threads from the thread pool would limit my web server's capability of serving new requests so this might not be a good idea. Spawning new threads manually could be expensive, so at the end of the day would there be a net gain in performance by paralleling these tasks or just leave them run sequentially?

5
  • 1
    Is it an option to have an AJAX call (or calls?) retrieve the data after the page loads and while telling the user that their request is being processed? Users will willingly wait longer if they are shown a message that something is happening and their request will be answered shortly... Commented Jun 17, 2009 at 14:13
  • I cannot use AJAX because the interface is totally conditioned by results returned from these tasks, like buttons should be visible or not, regions of page visible or not. Commented Jun 17, 2009 at 14:16
  • Perhaps async controllers could help you out? Sounds like the tasks are mostly I/O bound. Commented Feb 22, 2011 at 21:56
  • @bzlm, sure, they have already helped me :-) Unfortunately back in Jun 17 2009 when I asked this question they didn't exist yet :-) Commented Feb 22, 2011 at 22:02
  • Well, this is still a good question. :) Did you use them in this specific case? Commented Feb 23, 2011 at 7:22

2 Answers 2

1

If it's between spawning your own threads or using the thread pool threads, I'd say use the ones from the thread pool. You can always adjust your server settings to allow for more threads in the pool if you find that you are running out of threads.

Sign up to request clarification or add additional context in comments.

Comments

0

The only way to answer your final question would be to actually test it out, as we don't know how complicated the separate aggregation tasks are. If you want to give the illusion of a responsive UI, you could always display the loading page and kick off the aggregation with AJAX. Even non-threaded, this may placate your users sufficiently.

1 Comment

Currently users are not complaining, it's just a matter of personal desire to look for an optimization.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.