0

I have an existing application written in c++ that does a number of tasks currently, reading transactiosn from a database for all customers, processing them and writing the results back.

What I want to do is have multiple versions of this running in parallel on separate machines to increase transaction capacity, by assigning a certain subset of customers to each version of the app so that there is no contention or data sharing required, hence no locking or synchronisation.

What I want to do though is have multiple versions running on the same machine aswell as distributed across other machines, so if I have a quad core box, there would be four instances of the application running, each utilising one of the CPU's.

I will be wrapping the c++ code in a .NET c# interface and managing all these processes - local and distributed from a parent c# management service responsible for creating, starting and stopping the processes, aswell as all communication and management between them.

What I want to know is if I create four instances each on a separate background thread on a quad core box, whether or not the CLR and .NET will automatically take care of spreading the load across the four CPUs on each box or whether I need to do something to make use of the parallel processing capability?

NZJames
  • 4,963
  • 15
  • 50
  • 100

2 Answers2

1

You can set the process affinity when launching the process via the Process object (or ProcessThread depending on how you are launching the app).

Here is an SO post which covers the subject (I didn't vote to close as a duplicate (yet) because I'm not 100% sure if this is exactly what you are after).

Community
  • 1
  • 1
Ed S.
  • 122,712
  • 22
  • 185
  • 265
1

If you mean that you will be running your application in four processes on the same box, then it is the operating system (Windows) which controls how these processes are allocated CPU time. If the processes are doing similar work, then generally they will get roughly equal processor time.

But, have you considered using four threads within a single process? Threads are much more lightweight than processes, and you wouldn't then need a separate management service, i.e., you would have one process (with four threads) instead of 5 processes. Do you come from a unix background by any chance?

Polyfun
  • 9,479
  • 4
  • 31
  • 39
  • You can set [the process affinity](http://msdn.microsoft.com/en-us/library/system.diagnostics.process.processoraffinity.aspx) before launching it. – Ed S. Jun 07 '12 at 16:24
  • The reason I was opting to do it via processes and a management process is that I wanted to have the ability to launch and create processes across different servers, locations etc. If a box has 4 CPU's then ideally having four threads would be optimal but I may want for example 15 threads running, split across 4 boxes. Which in that case would result in 4 processes, some with 4 threads, and one with 3, which would be a lot harder to manage, monitor online status and start up/shut down remotely – NZJames Jun 08 '12 at 09:04