Here is the scenario:
There are clients sending requests to a server (it will be sockets or wcf server, that is not important).
Server will keep an open duplex channel and will use it to send an answer (serialized data) to a client. Server will process requests and involves query generation (basing on parameters from a request) and execution against data sources of various types (sql server, file system, analysis services server - olaps, offline cubes and so on...). So heavy IO-bound tasks - definitely often long running.
Performance is important, consider hundreds or maybe thousands of requests at the same time. It must be scalable.
I have never used TPL nor written a asynchronous server. But I've read a lot for a few days and... still can't wrap my head around it.
- Is TPL (4.0, not 4.5) a good choice here?
- Should I create tpl Task for every request that comes to a server? (for async processing)
- Should I create those Tasks with LongRunning option? (so no ThreadPool involved)
- Should I implement any queue mechanism for requests? How?
- Should I chain all parts of a request processing (a. query generation b. query execution against data source) with separate tasks (continuations) or is it ok to use single a task for both a. and b.?
- Should I use .FromAsync task generation for query executions? Or standard .StartNew is enough?
- What are other important areas I should watch for, given those above requirements?