views:

55

answers:

1

I have a multi-threading code running on my asp.net app like follow:

...
List<Thread> workers = new List<Thread>();
foreach (Airline airline in this._criteria.Airlines)
{
    Task mytask = new Task();
    Thread t = new Thread(new ThreadStart(mytask.Execute));
    workers.Add(t);
    t.Start();
}

//block all until finish
foreach (var t in workers)
{
    t.Join();
}

...

This code is work fine on one of server(windows2003, 32bit) and a great speed. But when i moved it to the new server, windows2008 64bit, I found that all tasks didn't start concurrence as well.

Here is starting time for each tasks on both server: - Rqst = time when task start - Resp = time when task done

----------------------- server 2: 64bit windows 2008 ----------------- *you'll see that starting time of each task (first started on 01:12:55.233 and last started on 01:13:11.773)

26230 2009-12-29 01:13:12.953 5812 Resp
26229 2009-12-29 01:13:11.773 5812 Rqst

26228 2009-12-29 01:13:05.453 616 Resp
26220 2009-12-29 01:13:00.213 616 Rqst

26227 2009-12-29 01:13:02.843 5792 Resp
26224 2009-12-29 01:13:01.653 5792 Rqst

26225 2009-12-29 01:13:01.873 4136 Resp
26221 2009-12-29 01:13:00.657 4136 Rqst

26226 2009-12-29 01:13:02.433 4932 Resp
26223 2009-12-29 01:13:01.150 4932 Rqst

26222 2009-12-29 01:13:00.910 5096 Resp
26219 2009-12-29 01:12:59.813 5096 Rqst

26217 2009-12-29 01:12:56.703 3332 Resp
26216 2009-12-29 01:12:55.303 3332 Rqst

26218 2009-12-29 01:12:56.703 3768 Resp
26215 2009-12-29 01:12:55.233 3768 Rqst

------------------------ server1: windows 2003 -----------------

26129 2009-12-29 01:11:44.107 5056 Resp
26126 2009-12-29 01:11:42.950 5056 Rqst

26130 2009-12-29 01:11:44.107 7368 Resp
26127 2009-12-29 01:11:42.967 7368 Rqst

26128 2009-12-29 01:11:44.090 5548 Resp
26125 2009-12-29 01:11:42.933 5548 Rqst

26120 2009-12-29 01:11:42.887 8100 Resp
26117 2009-12-29 01:11:41.637 8100 Rqst

26121 2009-12-29 01:11:42.887 7640 Resp
26116 2009-12-29 01:11:41.623 7640 Rqst

26122 2009-12-29 01:11:42.887 7780 Resp
26119 2009-12-29 01:11:41.700 7780 Rqst

26123 2009-12-29 01:11:42.887 1868 Resp
26115 2009-12-29 01:11:41.543 1868 Rqst

26118 2009-12-29 01:11:41.670 5936 Resp
26124 2009-12-29 01:11:42.887 5936 Rqst

Is there anything wrong in my code or it's about the difference platforms? Thanks

+1  A: 

I think the stack size for threads on the x64 is larger than 1Mb like it was on Windows 2003 x86. Try using the threadpool instead to reduce the cost of creating new threads.

In addition, the new IIS on Windows 2008 might (I'm not sure) throttle how fast threads can be generated.

tgiphil