473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Multi-Threading & Performance Questions

I am re-architecting a C# application written as a multithreaded
Windows Service and trying to squeeze every bit of performance out of
it.
1) Does the thread that an object is instantiated on have any impact on
its performnce?

Example: if I instantiate object "X" on thread "A" pass a reference
of "X" to Thread "B" and then have "B" run "X" (Exclusively). Does
this impact performance as compared to Thread "B" instantiating object
"X" itself?

2) In the above example would it matter if object "X" was using
Interop?

I'm asking the above questions because we currently have a group of
objects instantiated on thread "A" and then when one of the
"Calculation worker threads" > "B","C","D" etc.. need a particular
object, Thread "A" provides them a reference for there exclusive use.
All the objects contain a reference to a COM object through interop
(not sure if the use of Interop has any impact).
I'm running this on an 8 CPU Windows 2003 Server.

As I add "Calculation worker threads" Throughput Performance increases
up to about 3 Threads after that performance actually starts to
decrease. I'm surprised that on an 8 CPU Server that the "tipping
point" is so low. The "Calculation worker threads" are very
mathematically intensive, is it possible there is "blocking" going on
within the .NET Runtime or Interop? I'm trying to pinpoint the bottle
neck. (There is no IO in the Calculation Threads)

Thanks In Advance!!!

Jan 13 '06 #1
2 2578
See inline:
1) Does the thread that an object is instantiated on have any impact on
its performnce?

Example: if I instantiate object "X" on thread "A" pass a reference
of "X" to Thread "B" and then have "B" run "X" (Exclusively). Does
this impact performance as compared to Thread "B" instantiating object
"X" itself?
No, but you do have to be careful of any affinity that an object might
have for a thread, as well as for multiple threads hitting the object. You
will need to synchronize access.
2) In the above example would it matter if object "X" was using
Interop?
By interop, I assume you mean COM interop. This is absolutely
important. Objects in COM live in apartments, and you have to set the
apartment state of the thread before you use a COM object. Also, if the
apartment state of the thread is different from that of the object, then a
proxy needs to be created and the object accessed through that.
I'm asking the above questions because we currently have a group of
objects instantiated on thread "A" and then when one of the
"Calculation worker threads" > "B","C","D" etc.. need a particular
object, Thread "A" provides them a reference for there exclusive use.
All the objects contain a reference to a COM object through interop
(not sure if the use of Interop has any impact).
If you are porting this from an unmanaged application, you should be
familiar with the apartment issues already. This will not be too efficient
if the objects are Single-Threaded Apartment (STA) objects. In effect, if
you create all the objects on the main thread, you would have to marshal
proxies to the worker threads. The calls would all then be marshaled to the
main thread where they were created, and in effect, all calls would be
serialized.

You don't have this problem so much with the multi threaded apartment,
free threaded apartment, or neutral threaded apartment models. However,
some might require you to set up your thread in a particular manner.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com


I'm running this on an 8 CPU Windows 2003 Server.

As I add "Calculation worker threads" Throughput Performance increases
up to about 3 Threads after that performance actually starts to
decrease. I'm surprised that on an 8 CPU Server that the "tipping
point" is so low. The "Calculation worker threads" are very
mathematically intensive, is it possible there is "blocking" going on
within the .NET Runtime or Interop? I'm trying to pinpoint the bottle
neck. (There is no IO in the Calculation Threads)

Thanks In Advance!!!

Jan 13 '06 #2

<19*****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
|I am re-architecting a C# application written as a multithreaded
| Windows Service and trying to squeeze every bit of performance out of
| it.
|
|
| 1) Does the thread that an object is instantiated on have any impact on
| its performnce?
|
| Example: if I instantiate object "X" on thread "A" pass a reference
| of "X" to Thread "B" and then have "B" run "X" (Exclusively). Does
| this impact performance as compared to Thread "B" instantiating object
| "X" itself?
|
If the object is exclusively used by B, the answer is no.

| 2) In the above example would it matter if object "X" was using
| Interop?
|
| I'm asking the above questions because we currently have a group of
| objects instantiated on thread "A" and then when one of the
| "Calculation worker threads" > "B","C","D" etc.. need a particular
| object, Thread "A" provides them a reference for there exclusive use.
| All the objects contain a reference to a COM object through interop
| (not sure if the use of Interop has any impact).
|
If your COM object is a STA class object, then you have to take care you
aren't creating an instance of these COM objects when creating an instance
of your class. That means you must create the COM object on your secondary
threads.
You also have to make sure your COM objects run in a compatible apartment,
that is, when your COM objects are STA type objects, you have to initialize
your threads to enter an STA (set the ApartmentState property to STA before
starting the threads). Failing to do so will create a huge bottleneck:
- all COM objects will live in the single process STA thread, not in the
creators thread apartment which is MTA per default,
- all calls to the objects are automatically marshaled/synchronized, so only
a single call can be handled at a time.

|
| I'm running this on an 8 CPU Windows 2003 Server.
|
| As I add "Calculation worker threads" Throughput Performance increases
| up to about 3 Threads after that performance actually starts to
| decrease. I'm surprised that on an 8 CPU Server that the "tipping
| point" is so low. The "Calculation worker threads" are very
| mathematically intensive, is it possible there is "blocking" going on
| within the .NET Runtime or Interop? I'm trying to pinpoint the bottle
| neck. (There is no IO in the Calculation Threads)
|

Looks like your COM objects are STA and are living in a single STA threads
apartment. That means you have to initialize your threads to enter a STA
(see Thread.ApartmentState) and make sure you create the COM instance in
this same thread.

Willy.
Jan 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Frank Jona | last post by:
Intellisense with C# and a multi-file assembly is not working. With VB.NET it is working. Is there a fix availible? We're using VisualStudio 2003 Regards Frank
12
by: * ProteanThread * | last post by:
but depends upon the clique: ...
0
by: frankenberry | last post by:
I have multi-page tiff files. I need to extract individual frames from the multi-page tiffs and save them as single-page tiffs. 95% of the time I receive multi-page tiffs containing 1 or more black...
6
by: cody | last post by:
What are multi file assemblies good for? What are the advantages of using multiple assemblies (A.DLL+B.DLL) vs. a single multi file assembly (A.DLL+A.NETMODULE)?
6
by: Joe | last post by:
I have 2 multi-list boxes, 1 displays course categories based on a table called CATEGORIES. This table has 2 fields CATEGORY_ID, CATEGORY_NAME The other multi-list box displays courses based on...
4
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the...
5
by: bobwansink | last post by:
Hi, I'm relatively new to programming and I would like to create a C++ multi user program. It's for a project for school. This means I will have to write a paper about the theory too. Does anyone...
5
by: dkelly925 | last post by:
Is there a way to add an If Statement to the following code so if data in a field equals "x" it will launch one report and if it equals "y" it would open another report. Anyone know how to modify...
17
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, Wide character and multi-byte character are two popular encoding schemes on Windows. And wide character is using unicode encoding scheme. But each time I feel confused when...
1
by: mknoll217 | last post by:
I am recieving this error from my code: The multi-part identifier "PAR.UniqueID" could not be bound. The multi-part identifier "Salary.UniqueID" could not be bound. The multi-part identifier...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.