Threading -- Performance
-
Hi all, An interresting problem in the context of interprocess communication. Consider following code:
public void StartSepThread() { ThreadStart tsThread = new ThreadStart(RunServerSepThread); TestThread = new Thread(tsThread); TestThread.Name = "IPC.Test"; TestThread.Start(); } public void RunServerSepThread() { while(true) { (lot of code here...) } }
The code above proves to be 50% less performant than following code:public void RunServerSameThread() { while(true) { (exact same code here...) } }
When running the server in the same thread, we are able to move 163 Mbit/sec of data between two running processes. However, when running the same code as a seperate thread, performance goes down by almost 35% to a level of 111 Mbit/sec. Anybody any idea what this might be??? Thanks -
Hi all, An interresting problem in the context of interprocess communication. Consider following code:
public void StartSepThread() { ThreadStart tsThread = new ThreadStart(RunServerSepThread); TestThread = new Thread(tsThread); TestThread.Name = "IPC.Test"; TestThread.Start(); } public void RunServerSepThread() { while(true) { (lot of code here...) } }
The code above proves to be 50% less performant than following code:public void RunServerSameThread() { while(true) { (exact same code here...) } }
When running the server in the same thread, we are able to move 163 Mbit/sec of data between two running processes. However, when running the same code as a seperate thread, performance goes down by almost 35% to a level of 111 Mbit/sec. Anybody any idea what this might be??? ThanksUmmm... Just in case you have misssed this, try
Thread.Sleep(0);
immediately after you doTestThread.Start();
method. Do post the resultant performance. ;) MSDN documentation onSystem.Threading.Thread
overview says "On a uniprocessor machine, the (child) thread does not get any processor time until the main thread yields." -
Ummm... Just in case you have misssed this, try
Thread.Sleep(0);
immediately after you doTestThread.Start();
method. Do post the resultant performance. ;) MSDN documentation onSystem.Threading.Thread
overview says "On a uniprocessor machine, the (child) thread does not get any processor time until the main thread yields."Well... the performance gain is nothing. I didn't mentio it in my code posted, but inside the While loop there is a blocking call. This is exactly the same code in the single thread and new thread code. So that doesn't make any difference. I believe the CPU would go 100% if no blocking call was inside the loop and
Thread.Sleep(0)
was missing... Thanks Peter