c# - Best way to work on 15000 work items that need 1-2 I/O calls each -


i have c#/.net 4.5 application work on around 15,000 items independent of each other. each item has relatively small cpu work (no more few milliseconds) , 1-2 i/o calls wcf services implemented in .net 4.5 sql server 2008 backend. assume queue concurrent requests can't process quick enough? these i/o operations can take anywhere few milliseconds full second. work item has little more cpu work(less 100 milliseconds) , done.

i running on quad-core machine hyper-threading. using task parallel library, trying best performance machine can little waiting on i/o possible running operations asynchronously , cpu work done in parallel.

synchronously, no parallel processes , no async operations, application takes around 9 hours run. believe can speed under hour or less not sure if going right way.

what best way work per item in .net? should make 15000 threads , have them doing work context switching? or should make 8 threads (how many logical cores have) , go way? on appreciated.

my usuall suggestion tpl dataflow.

you can use actionblock async operation , set parallelism high need be:

var block = new actionblock<workitem>(wi => {     dowork(wi);     await task.whenall(dosomeworkasync(wi), dootherworkasync(wi)); },  new executiondataflowblockoptions{ maxdegreeofparallelism = 1000 });  foreach (var workitem in workitems) {     block.post(workitem); }  block.complete(); await block.completion; 

that way can test , tweak maxdegreeofparallelism until find number fits specific situation most.

for cpu intensive work having higher parallelism cores doesn't help, i/o (and other async operations) if cpu intensive work short go @ least 1000.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -