Threads
-
Hi Friends, Is possible to run 500 threads per second using c#? Please help me Thanks in advance
C# would not be the limiting factor. Windows could probably cope; a server version would for sure. But I haven't encountered any application yet where it would make sense to have that many threads in a single process. It would be a huge waste of cycles (thread switches are expensive), bytes (each thread has its context, where the stack is the biggest chunck), and time (your cache efficiency goes down as the fixed size caches are used by more threads now). Here is my rule of thumb in multi-threading: For most apps, it does not pay to have similar code in more than 1*N to 2*N threads where N is the number of processors. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
[The QA section does it automatically now, I hope we soon get it on regular forums as well]
-
C# would not be the limiting factor. Windows could probably cope; a server version would for sure. But I haven't encountered any application yet where it would make sense to have that many threads in a single process. It would be a huge waste of cycles (thread switches are expensive), bytes (each thread has its context, where the stack is the biggest chunck), and time (your cache efficiency goes down as the fixed size caches are used by more threads now). Here is my rule of thumb in multi-threading: For most apps, it does not pay to have similar code in more than 1*N to 2*N threads where N is the number of processors. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
[The QA section does it automatically now, I hope we soon get it on regular forums as well]
-
Thank you your reply. Is there any example to use multi threading (Asynchornous and thread pool) in C# window service application?
-
C# would not be the limiting factor. Windows could probably cope; a server version would for sure. But I haven't encountered any application yet where it would make sense to have that many threads in a single process. It would be a huge waste of cycles (thread switches are expensive), bytes (each thread has its context, where the stack is the biggest chunck), and time (your cache efficiency goes down as the fixed size caches are used by more threads now). Here is my rule of thumb in multi-threading: For most apps, it does not pay to have similar code in more than 1*N to 2*N threads where N is the number of processors. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
[The QA section does it automatically now, I hope we soon get it on regular forums as well]
Luc Pattyn wrote:
have similar code in more than 1*N to 2*N threads
My rule of thumb is 1.5*N :thumbsup:
Harvey Saayman - South Africa Software Developer .Net, C#, SQL
you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111 -
Hi Friends, Is possible to run 500 threads per second using c#? Please help me Thanks in advance
Theoretically, yes... you can have unlimited threads. But in practice, not so much As Luc pointed out 500 threads are a bit heavy. If their running similar code I'd use Smart Thread Pool[^] Its easy to use, quite flexible and to quote JSOP, "It simply works" :cool:
Harvey Saayman - South Africa Software Developer .Net, C#, SQL
you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111 -
Luc Pattyn wrote:
have similar code in more than 1*N to 2*N threads
My rule of thumb is 1.5*N :thumbsup:
Harvey Saayman - South Africa Software Developer .Net, C#, SQL
you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111Harvey Saayman wrote:
1.5*N
you may run into trouble on an AMD triple core... :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
[The QA section does it automatically now, I hope we soon get it on regular forums as well]
-
Harvey Saayman wrote:
1.5*N
you may run into trouble on an AMD triple core... :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
[The QA section does it automatically now, I hope we soon get it on regular forums as well]
Even on single core dinosaurs... I was thinking that same thing just after clicking post on my OP :rolleyes:
Harvey Saayman - South Africa Software Developer .Net, C#, SQL
you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111 -
Luc Pattyn wrote:
have similar code in more than 1*N to 2*N threads
My rule of thumb is 1.5*N :thumbsup:
Harvey Saayman - South Africa Software Developer .Net, C#, SQL
you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111Having rules of thumb like 2* number of processors is a totally pointless affair. Consider the following scenario --I want to wait on 70 blocking operations --When one of these operations complete. I would like a response/somethingto happen, quickly (Low latency) I could *Have 2*2 processors threads constantly polling all 70 blocking operations every millisecond to see when they are done. This would waste lots of CPU *Use 70 threads which are all in Wait mode which would consume very little CPU Using 70 threads would be far better in this case The number of threads you need has nothing to do with the number of CPUs. And everything to do with latency and how much blocking operations you need to wait on