|
Alberto
Any other considerations? Sure: what are the threads doing, do the threads interact with other (operating system) processes and threads, are you going to be implementing a thread pool (that is, sharing lots of thread-like activity amongst a small set of threads), how are you implementing synchronization, how many objects need synchronization, do the threads interface with the UI thread, etc, etc.
What I'm trying to get at is this. The question as posed has no right or wrong answer. To find out your answer, you need to write the app, or as much of the app as makes sense, and then profile it (that is run it and tweak it) in the environment you want. Worrying too much about fine details like how can you extract as much performance from a four processor system versus, say, a two processor system when you don't have the actual code is putting the cart before the horse. Writing performant multithreaded apps tends to be more about how efficient and well-written your inter-threadd communication is set up than anything else.
Also, in my experience, trying to second-guess the operating system by forcing some threads onto some CPU and others onto another, could do more harm than good.
Cheers, Julian [MSFT]
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
Julian,
I have - lets say 16 - working threads that are doing a very intensive task and 1 UI threads that waits for them. I work on a double Intel XEON processor workstation.
After waiting this 16 workers (with the WaitAll on 16 ManualResetEvent handles) I sort the results alter the data and start again. In 2 words a GA algorithm.
Threads are completely indipendend one from the other and don't interact with the UI thread.
In my opinions should be better to detect the number of processor (suppose 2) and do 8 job on each processor (this would mean 1 UI thread, 2 workers and 2 MaualResetEvent for synchronization). The other option is to start all the 16 threads and leave the OS to split the work between available processors. I did not consider the Threadpool because I read somewere that it is not good for very intensive tasks...
Am I right?
Do you know any article that specifically talk about these matters?
Thanks a lot,
Alberto Bencivenni
www.devDept.com
|
|
|
|
|
I don't know. The best answer I can give is: write it to not "know" about the number of processors. This is the simplest code you could write: you're going to let the OS do all the scheduling work. After all the OS is going to be context-switching under you anyway to service the network, do file IO, do whatever.
If the performance isn't all it's cracked up to be, now add some moderately complex code to identify how many processors there are, how to split up the total work between processors, etc. Run it and profile. Tweak. Run it and profile. Rinse and repeat. I would doubt that you'd make much difference for the amount of work it will take you. I would hazard a guess that improving the algorithm that's doing the work will get you more bang for your coding buck.
The threadpool is designed to obviate the need to continually create OS threads, an expensive process. That's all. It makes no difference to the speed of execution of code in the thread.
References, wow. Not off the top of my head, no, sorry. Certainly I don't know of any in the C#/.NET world.
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
I seem to recall that the optimal number of active worker threads per CPU is two. If those threads will be waiting, you will, of course, need a larger thread pool.
To scale correctly, you should detect the number of CPUs and act accordingly, but unless you are doing something very specialized (like assigning a thread to a CPU) I'd suggest using a single pool.
Of course, you'd want to empirically test any proposed solution to the extent possible. (I can't actually emphasize this enough. I've been surprised more than once by actual performance in heavily multi-threaded apps.)
|
|
|
|
|
Interesting, in my work project, I've been assuming something like a minimum of 10 threads and an upper bound of 25 threads. (I've been using Mike Woodring's ThreadPool, which seems far more superior to System.Threading.ThreadPool.) I'm worried that it's overloading the CPU... My project does a lot of work with collecting a bunch of Web pages and parsing them. Some time is spent waiting for a page to be received, but a lot more is spent processing/scraping the pages. Perhaps I'll try a lower minimum and perhaps a lower maximum.
|
|
|
|
|
Hello Joe,
So, we can say that to improve the application performances it is better to use the smallest number of thread that keep processors at 100% of usage?
Thanks a lot,
Alberto Bencivenni
www.devDept.com
|
|
|
|
|
For optimal performance you want to minimize context switches, so the fewest number of threads using the maximum amount of CPU is the best. (Realize, of course, that if your threads are using up their entire slice, you will see serious system degredation from other, especially low priority, processes [like the GUI].)
|
|
|
|
|
Hi,
How do I read data in cells of Excel file by using Microsoft Excel Object 9.0 component?
Please help me.
Thanks
H.Dung
|
|
|
|
|
I guess there is article about Ecxel and C# in CP.
Mazy
No sig. available now.
|
|
|
|
|
|
|
This reads it into a DataTable
public void CreateXLSDataTable( String fileName )
{
//DataTable tb = new DataTable("XLS");
dtXLS = new DataTable();
Excel.Application ExcelObj = null;
ExcelObj = new Excel.Application();
if ( ExcelObj != null )
{
Excel.Workbook empBook = ExcelObj.Workbooks.Open(fileName,0,true,5,"","",true,
Excel.XlPlatform.xlWindows,"\t",false,false,0,true);
Excel.Sheets empSheets = empBook.Worksheets;
Excel.Worksheet empSheet = (Excel.Worksheet)empSheets.get_Item(1);
bool lineValid = true;
int iCount = 1;
while ( lineValid )
{
iCount++;
Excel.Range range = empSheet.get_Range("A"+iCount.ToString(), "X"+iCount.ToString());
System.Array myvalues = (System.Array)range.Cells.Value;
string[] strArray = ConvertToStringArray(myvalues);
if(strArray[0].Equals("") )
{
lineValid = false;
continue;
}
if( iCount != 2 )
{
object[] objArray = strArray;
dtXLS.Rows.Add(objArray);
}
else
{
for(int i=0; i< strArray.Length; i++)
{
dtXLS.Columns.Add(strArray[i]);
}
}
}
}
else
{
Trace.WriteLine("Excel reading Error: could not load the excel file object");
}
ExcelObj.Quit();
ExcelObj = null;
}
private string[] ConvertToStringArray(System.Array values)
{
string[] theArray = new string[values.Length];
for(int i=1; i<=values.Length; i++ )
{
if( values.GetValue(1,i) == null )
theArray[i-1] = "";
else
theArray[i-1] = (string)values.GetValue(1,i).ToString().Trim();
}
return theArray;
}
public DataTable XLS
{
get
{
return dtXLS;
}
}
|
|
|
|
|
lets say I have an
object[] myObjects
once populated from a sqldatareader using getvalues method they can be tons of different ones
how do I use the typeof or different reflections methods to find what exact type it is to compare in a switch statement?
please help, I'm using string comparisons.
nick
|
|
|
|
|
object.GetType() should give you the information you require.
Rocky Moore <><
|
|
|
|
|
foreach (object o in myObjects){
if(o is string ){
...
}
else if(o is int ){
...
}
else if(o is ...){
...
}
...
}
I hope this helps
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|
|
This snippet goes through the collection of objects and does a breakdown by type. This assumes that you have different processes you want applied to the data based on different data types that exist in the collection.
foreach (object item in myObjects)
{
switch (item.GetType())
case typeof(string):
{
...
}
case typeof(int):
{
...
}
...
}
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
|
You're welcome.
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
I'm using reflection to grab the type
propertyCaller.PropertyType.GetType()
I get this errpr "a value of integral type expected."
what gives? and why a integer type
|
|
|
|
|
what properties do I set if I have a class like
public class MyClass : CollectionBase, IBindingList, ITypedList, and a few more I cant remember
how od i do it?
|
|
|
|
|
Just started to read up on ADO.NET. Do I understand this correctly:
Normally, when I code a C++ app I open a connection or two when I first start my app. I keep the connection open until my app is closed. I would created and destroy command objects many times during the life of the app.
With ADO.NET am I supposed to call Close on the Connection after EVERY time I get done using it? - - Because there is a connection pool that it is returned too.
|
|
|
|
|
Yep, that is pretty much it. I think the connection pooling is more for ASP.NET but also think that when you are holding on to a connection, that is one more connection license being used on the server. If you happen to run against MSDE, there are only five I believe before it throttles down.
You have to use planning though, as there is an time overhead in establishing those connections depending on where the server is located.
Rocky Moore <><
|
|
|
|
|
I'm creating an exception manager for my application. When an unhandled application exception occurs the class needs to be able to send the report back to the company. I know about the System.Web.Mail namespace, but it looks like an smpt server is required, and it seems like win2k is also required. How can I send an email and have it work even on win98 without specifying an smpt server. Does the .net framework have a class that will send an email with its own smpt server.
|
|
|
|
|
AK wrote:
it work even on win95
You are asking the wrong group, .NET is not supported on Win95. You will have to choose another programming langauge.
Rocky Moore <><
|
|
|
|
|
I didn't know that .net framework didn't work on 95. I really don't care, as long as the majority of the windows users have support.
Anyway. Does the .net framework have a class that would send email with it's own smpt server?
|
|
|
|