Parallelism


hi all,

if parallel start task @ once? or wait time complete others?

this scenario have facing issues.

i have collection, , has 200 items, calling a method(assume holds time processing 1 min) , wait response.  if use foreach took 200x 1 min complete process.

if use parallel supposed complete within min 200 item call?

below code tried, took same time used in classic foreach.


            list<int> paralleltask = new list<int>();              for(int i=1; i<=200; i++)              {                  paralleltask.add(i);              }                console.writeline("parallel process started");              paralleltask.asparallel().forall(x => {                  console.writeline("response : {0}", new messagecontainer().getmessage(x));              });                console.writeline("parallel processing completed");    =======================================================      public class messagecontainer      {          public messagecontainer()          {            }            public string getmessage(int id)          {              thread.sleep(5000);              return string.format("message : {0}", id);          }      }
could please describe how parallel works.
thanks,


"if use parallel supposed complete within min 200 item call?"

no not true. still limited # of threads (tasks) system can execute @ 1 time. dependent upon processor (multi core? hyperthreading?), each method doing (any blocking calls suspend it) , other processes running in system.  scenario perfect world pretty never true.

tasks using default scheduler go through thread pool. thread pool starts 25 threads can go (default) of 100. once gets point, further attempts use thread block until existing thread released. non-deterministic in regard. while may start 200 tasks @ once first 100 scheduled while remainder block waiting 1 finish. out of 100 start still fighting time rest of threads running in system. given quad core processor no hyperthreading @ 4 running @ 1 time. since windows round robin-like scheduling (and assuming no blocking calls , ignoring thread priorities) thread run allocated quantum , sleep until time run again.

personally question benefit of running 200 tasks @ once. should consider changing problem set need less tasks , can consolidate appropriate. going faster have 100 tasks running @ 2 mins 200 tasks taking @ least 1 min. again, windows non-deterministic dependent upon going on in system, how threads interact , doing. profiling of code while running answer of these questions.

michael taylor
http://www.michaeltaylorp3.net



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'