1

We have an asp.net application on an iis 7. we need to create an async process to do calculating (using a web service) and not keeping the client waiting, we used ThreadPool to do that (i prefer Tasks but i am a server side guy).
My questions are :
1. if using a thread pool on iis does it take threads from the iis pool from clients or from the OS ?
2. What would you use Tasks or ThreadPool (Tasks give you much more i know but the UI guys like the pool).
Tanks

2
  • If you're worried about fully loading your server, I would consider using a separate server to process the async requests so that you can scale each type of usage separately (applies if you expect your volume to necessitate more than a handful of servers in total). Commented Jul 14, 2011 at 17:42
  • we are using the calculating on a different server, but the call to the server and the returned answer is still on the same one Commented Jul 14, 2011 at 18:13

2 Answers 2

4

The ASP.NET host provides a single thread pool per process. So if you're using ThreadPool, then it's taking from the same pool that is drawn from for server requests.

That said, if you're starting background operations that are independent from a single client request, then you should be using a Win32 service, web service, message queue system, or something similar. Running "background" threads in ASP.NET goes against the entire architecture of IIS; it's much easier to scale properly and do other IT work (e.g., restarting app pools) if you maintain the stateless nature of HTTP.

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

4 Comments

Just to make clear because i didn't quite understood, your recommendation is to create some other independent service (Some process separated from the current client request ) and transfer it to it? is it possible to create on the same app different stat thread and use the consumer producer design ?
The key is what you mean by "not keeping the client waiting". If you mean that a page request is used to start an operation and the page request completes before the operation is complete, then yes, it should be a different service (not hosted by ASP.NET).
If task pulls a thread from the IIS thread pool, will that prevent a recycle from stopping your task? For example, say I want to delete a file on a remote SAN, but I don't want the client to wait for the delete. I'd like to just call Task.Run(IO.File.Delete(....)). Is this bad? If so, my server has oodles of RAM and cores. Can't I just configure more threads to be created in the pool?
@Brain2000: No, it won't prevent a recycle. If a recycle occurs, the work you're doing on a thread pool thread will be aborted. I describe alternatives here. RAM/cores are immaterial; ASP.NET must recycle periodically because of the (IMO idiodic) way they handle connection aborts.
0

Task, still consumes threads from thread pool.

As far, as I understood you question, 3rd party service performs CPU-heavy calculation, and you need asynchronously wait it to complete.

In case, if you want to postpone page rendering, until computation is complete, Async pages will help. This approach will return processing thread to thread-pool, while waiting.

Could you provide more details about required solution, for more precise answer?

3 Comments

We are uploading a file from the client to our server and manipulating it. this action takes up to a minute in large files. this is preformed on different server. when calling the proxy client we want to use it on different thread in order not keeping the client to wait. by using threadPool we are taking a thread waiting a call from another client no ?
As Sthepen said, waiting for a web service to complete in as separate Task/ThreadPool_WorkItem will occupy one of IIS processing threads. In this case, you will not be able to serve, more that 25 clients at the same time. If you need wait for completion of WebService do in via Async pattern, by generating async proxies for WS and Async page rendering. However, if you want to show nice progress bar for the user, it's a different story.
Isn't it better to use a thread from the IIS thread pool? My thinking is if you are using your own thread that a recycle might kill a non-pool thread because it is unaware of its existence.

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.