James Rollinson
James Rollinson

Reputation: 13

Processing lots of tasks with required call to a web service without blocking

In my server application I want to process lots of coming from client tasks. Client application submits tasks for processing and processing each task requires calling a web service for pre-processing and then actual processing happens.

I was suggested having a queue into which I'll put all tasks that server receives. Then a thread picks up a task from a queue and calls a web service. There will be maybe 40 threads doing this if one blocks on web service, other can do calls as well, picking up items from queue. After a thread receives response from web service it puts pre-processed item on a second queue from which another thread takes tasks for processing. And there will be 1 thread for this queue (will be scaled further per processor - so probably 4 (or more) threads on a 4 core machine).

I believe this can be accomplished more efficiently without having 40 predefined threads doing web service calls and maybe having 1 queue. I think there are multiple options for doing this is .NET more efficiently. Any suggestions?

It's probably broader question how to implement better such a system rather then a .net specific.

Upvotes: 0

Views: 102

Answers (3)

Stephen Cleary
Stephen Cleary

Reputation: 456352

I recommend looking into TPL Dataflow, a library that allows you to define a "pipeline" or "mesh" for data processing and then you put the data through it. TPL Dataflow works very well with both asynchronous (e.g., web request) blocks and synchronous (e.g., processing) blocks and has lots of options for parallelism.

Upvotes: 1

AliK
AliK

Reputation: 1067

In case for some reason you are not up to version 4.5 of the framework look into one-way WCF calls as a kind of "fire and forget" method.

Upvotes: 0

gleb.kudr
gleb.kudr

Reputation: 1508

I think you should learn about async/await construction awailable in .net 4.5. It is hard to say if it meets all your requirements but you should check it.

Upvotes: 2

Related Questions