After so much research, I thought I should ask the experts.

I am working on a project for my corporate employer, we have android and iPhone mobile apps that make request to a web service, the request is logged in pending state for processing.

A windows service retrieves the pending requests and spins a new thread for every request. This is because the request could be directed to different providers who process request in different manners. One could immediately process the request and return feedback, others could receive the request and take up to 30 seconds to return a feedback which you have to poll for the status.

The mobile app will also be polling for the status of the request.

Now my challenge is:

I am thinking of creating a list of threads say 100 and assign each thread to execute a request, once finished the thread will be recreated and assigned a new request. It is a high response based platform so I am thinking of not using ThreadPool.

Is it advisable to spin new threads in a fire and forget sequence or manage these list of threads and if it is to managed, then what is the best approach to manage these list of threads and ensure high performance in C# as the mobile apps will be polling for a response.

  • 3
    Your second to last paragraph seems to suggest that you cannot use a ThreadPool if you want high responsiveness. I dispute that assertion. A ThreadPool is probably the best way to do this, because you get some management infrastructure for free. – Robert Harvey Jan 24 '14 at 20:16
  • Definitely use the threadpool until you have evidence that it will not meet your requirements. I have seen this scenario before but the thread pool worked for years as user load increased before we had to move off it, it's a rare enough scenario as to need proving before believing. – Jimmy Hoffa Jan 24 '14 at 20:26
  • Thanks Robert and Jimmy. I will give the threadpool a good hit and revert as per performance and outcomes. Thanks. – albertdadze Jan 24 '14 at 23:54
  • We had a very similar issue at work the other day. We had a piece of legacy software that created a new thread to process every request, this was working fine for years until we put it under heavy load (1000s of requests a second). Under heavy load the amount of threads got out of hand and we got out of memory exceptions. Moved to a threadpool and it instantly fixed the problem with very little performance degradation – Mike Norgate Jan 27 '14 at 8:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.