|
Luc Pattyn wrote: So I would not exceed twice the processor count for identical threads.
So ProcessorCount * 2 formula... that's good. Now do you have a citation for that?
|
|
|
|
|
Thank you for the information. The optimal number of threads equals the number of processors on a system and it shouldn't exceed twice the processor count. Correct? Why not 3 times?
|
|
|
|
|
steve_a_p wrote: Thank you for the information. The optimal number of threads equals the number of processors on a system and it shouldn't exceed twice the processor count. Correct? Why not 3 times?
See my other reply in this thread.
The early bird who catches the worm works for someone who comes in late and owns the worm farm. -- Travis McGee
|
|
|
|
|
The main message is it is not tens of threads: just adding more and more threads will
increase the overhead and not reduce the overall execution time. And it does depend on
the thread function: if it is pure computation, one thread per processor will do;
if there is I/O latency involved, two per processor will be better (and more typically
does not help due to I/O limitations); if it is a pure Sleep() you can have as many as
you want.
The good thing is if you organize things around Environment.ProcessorCount:
1. you can try another factor and observe what it brings you.
2. your app is less likely to suddenly behave badly when you move it to a system with
a different processor count (which may well happen when you fix the number of threads).
And as Patrick pointed out, you are not completely in charge:
1. with .NET you will not (easily) control which thread runs on which processor;
2. other apps and services will be running too.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
|
Can I just say, this entire discussion in the context of the .NET Framework is a waste of time. The Framework provides no control over where those threads are going to execute, nor do they provide synchronization capabilities across processor cores.
The only limit on the number of threads you can actually create is the limit of the addressable memory space on the machine.
If you really need a parallelized application, the .NET Framework is not the platform to use. If you need this, you should be using something like MPI, OpenMP, or a newer solution by Intel called Threading Building Blocks (http://osstbb.intel.com/[^]) which is aware not only of separate processors, but distinct processor cores.
So far as I am aware, there are no .NET wrappers for those libraries. You'd be using C/C++.
Once you get to those libraries, a question of how many threads to use becomes heavily dependent on what each thread is doing and the overall architecture of a parallelized application.
The early bird who catches the worm works for someone who comes in late and owns the worm farm. -- Travis McGee
|
|
|
|
|
Yeah, it is not perfect, but my main objective was to warn against too many threads;
some people seem to expect performance increases linearly with the number of threads,
which obviously is not true at all.
So for a single processor I often give the following approach:
"as a first approximation, this is what you could do: write and run the code to use a
single thread; observe the CPU load (with Task Manager) as a percentage.
The inverse number is the number of threads you want, so if it is close to 100% extra
threads won't bring you anything; if it is near 25% using four threads MIGHT
increase the performance by four, bringing the CPU load to 100%. More threads
than that won't help you."
And one should not forget the obvious approach to increasing performance, is by optimizing
the application at all levels: algorithms, data structures, coding, compiler settings, etc.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
|
So just because a better threading lib exists in C one shouldn't use threading in .NET? Weird logic. I've used multithreading in dozens of situations in .NET and although it is not "aware" of the number of physical processors/cores it generally does a good job. Why? Because the operating system takes care of it.
|
|
|
|
|
Robert Rohde wrote: So just because a better threading lib exists in C one shouldn't use threading in .NET? Weird logic. I've used multithreading in dozens of situations in .NET and although it is not "aware" of the number of physical processors/cores it generally does a good job. Why? Because the operating system takes care of it.
Of course not. I was responding specifically in the context of counting threads based on the number of processors you have. That's pointless in .NET.
Yes, the OS will do some thread parallelization for you, but if you actively want to use those processors you have to use lower level languages with specialized libraries.
There's nothing wrong with threading, but you have to understand your problem and the limitations of various solutions before you start creating tons of threads thinking it will solve your problem, as Luc accurately points out.
The early bird who catches the worm works for someone who comes in late and owns the worm farm. -- Travis McGee
|
|
|
|
|
Patrick Sears wrote: I was responding specifically in the context of counting threads based on the number of processors you have. That's pointless in .NET.
Not totally. I agree that you cannot be 100% sure that if you run 4 threads in .NET that every thread will run on its own core (although it does it very often). Nevertheless you have a "hint" on how many parellel threads might be good. If you know you have only one core than you would normally not start several threads (assumming its only about number crunching).
But I agree with your other points.
Robert
|
|
|
|
|
Robert Rohde wrote: Not totally. I agree that you cannot be 100% sure that if you run 4 threads in .NET that every thread will run on its own core (although it does it very often). Nevertheless you have a "hint" on how many parellel threads might be good. If you know you have only one core than you would normally not start several threads (assumming its only about number crunching).
And I also agree with you there
The early bird who catches the worm works for someone who comes in late and owns the worm farm. -- Travis McGee
|
|
|
|
|
Patrick Sears wrote: but you have to understand your problem and the limitations of various solutions before you start
Sorry but that is counter the VB way of life. You "start" by dragging and dropping controls onto a form. All the rest of the development is insignificant overpaid typing.
|
|
|
|
|
led mike wrote: Sorry but that is counter the VB way of life. You "start" by dragging and dropping controls onto a form. All the rest of the development is insignificant overpaid typing.
Hehehe, touche'
The early bird who catches the worm works for someone who comes in late and owns the worm farm. -- Travis McGee
|
|
|
|
|
Hello everybody,
I have gone through lot many articles regarding the SOAP in webServices. I did many applications in the windows service in .net2005. Now my new requirement is to create a new windows service which can do two things: 1) it should be able to service a SOAP call by reading the MySQL db and generate a SOAP enevelpe. And 2) It should also run for every x-seconds/x-mins.
I am carrying out this task in C#.net2005. And MySQL.
Can anybody help me out in getting me the correct theory and code articles, because in my research.. i am getting deviated everytime.
So, please can anybody help me out..
Thanks in Advance
anumadhu
Anee
|
|
|
|
|
anumadhu wrote: 1) it should be able to service a SOAP call by reading the MySQL db and generate a SOAP enevelpe.
Can you break that out? Like:
1) Receive and parse a SOAP Request ( over what protocol)?
2) Query a MySQL database
3) Generate and send a SOAP Response ( over what protocol)?
|
|
|
|
|
Thanks Mike,
Task-1:
It should be able to do query and update MySQL database in backend for every x number of seconds.
Task-2:
And meanwhile, if it receives the SOAP request, it should do the following activities:
1) The windows service should be able to receive and parse a SOAP Request over HTTP protocol
2) Query and update a MySQL database
3) After updating the database, it should send a message(example: "Your Request Processed")as SOAP Response or SOAP Envelope over HTTP protocol.
Any related articles or the code samples in C#.net 2005, is of more help to me.
Thanks
Anee
|
|
|
|
|
|
It should also run for every x-seconds/x-mins.
you can create exe file and use
schedled task from os to run exe file every x-seconds/x-mins
|
|
|
|
|
WCF easily allows you to host a webservice from a Windows service.
Of course you can do it all yourself, but I can't think of any reason to do that.
EDIT: Hmm, now I see you wrote .Net 2005 which unfortunately doesn't really mean anything - I originally read it as VS2005 and replied based on this. If you mean .NET 2.0 then you have to do it yourself as is often the case when you try to do anything using outdated technology. If you mean VS2005, then simply install the CTP addons for VS2005 allowing you to program for .NET 3.0.
|
|
|
|
|
Hello,
I have been using VC++ for 3 yrs now.
Now I want to learn .NET Framework.
What is the actual purpose of .NET Framework and where should I start?
Regards,
Prithaa
|
|
|
|
|
The main purpose of .NET is to annoy the people at Sun.
C# is the best place for a C++ guy to start, there are books on starting C# from a C++ perspective.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
prithaa wrote: What is the actual purpose of .NET Framework
The primary purpose of the .net framework is to trivialize all the effort you put into learning C++. The secondary purpose is to trivialize your efforts to learn .Net by "managing" your code for you.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|