4 Replies - 20008 Views - Last Post: 12 October 2007 - 06:38 AM Rate Topic: -----

#1 iownu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 12-October 07

Managing Multiple Processes, not Threads

Post icon  Posted 12 October 2007 - 04:58 AM

Hello,

I have never something like this and don't know of anyone that have done something like. I know its possible, because I have seen many applications written that can do this.

So what I want do is this:

I have one process, I want to run this same process multiple times and need the ability to manage these processes. I would prefer to do it with a windows service, what is the best approach. What this process does is, picks up xml files from a directory and imports this data into multiple databases after doing some analsysis on it.

I have tried creating a multi-threaded application and realized with a lot of tuning that this was not the way to go. I don't know why, but it was not fast enough. When I manually ran 2-4 processes, each with one thread, it was going way faster then a single process running with 10 threads, I know this is kind of weird, but after a week of testing and debugging, this I believe is the best approach.

So I was curious if anyone has any links to documentation or even some examples on how to manage the same process with a service. I want to run this process 5 times with this service, all 5 processes will be reading from the same xml directory (this is where it gets interesting). If anyone has any help, I would really appreciate it.

Thanks.
Ravi

Is This A Good Question/Topic? 0
  • +

Replies To: Managing Multiple Processes, not Threads

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Managing Multiple Processes, not Threads

Posted 12 October 2007 - 05:41 AM

Well I dont know where you went wrong with threading but that is the way to go. If you have concurrent processes running, all in the same thread, one has to wait for the other to execute before they can execute, kind of a "hurry up and wait" process.

Threading eliminates that bottleneck and allows to run concurrent processes simultaneously, which is what threading is all about. If you've seen an application running concurrent process chances are its a multi-threaded application.
Was This Post Helpful? 0
  • +
  • -

#3 iownu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 12-October 07

Re: Managing Multiple Processes, not Threads

Posted 12 October 2007 - 05:57 AM

So, I might sound a little stupid here, but here it goes:

If you have, in the Task Manager, five processes running that are called "XMLReader.exe", and all these five processes are run by a service called "XML Loader", is this a multi-threaded application?

I have created multi-threaded applications, that lets say have 10 threads in it, but in the task manager only show one instance of the process. I would only see "EmailPush.exe" in the processes, but in reality, this service had 10 threads running.

Am I just confused about threading in general in c#? Do you understand what I am getting to?

Thanks.
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Managing Multiple Processes, not Threads

Posted 12 October 2007 - 06:01 AM

Yes you are confused. If you aren't running each process in its own thread then you are not multi-threading,. What you're referring to is a single instance of the application. Unless you created a new thread when the process started, using the System.Thread Class from the System.Threading Namespace then you have not tried multi-threading.

Multi-threading does indeed making running concurrent processes much faster, as they dont have to wait for the one before to finish executing before they can execute.
Was This Post Helpful? 0
  • +
  • -

#5 iownu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 12-October 07

Re: Managing Multiple Processes, not Threads

Posted 12 October 2007 - 06:38 AM

foreach (FileInfo fiInfo in srcFiles)
				{
					freeIndex = WaitHandle.WaitAny(threadEvents, new TimeSpan(0, 2, 0), false);
					if (freeIndex == WaitHandle.WaitTimeout)
					{
						AbortAllWorkerThreads();
						freeIndex = 0;
					}
					Thread.Sleep(1);
					string sourceFile = fiInfo.FullName;
					threadEvents[freeIndex] = new ManualResetEvent(false);
					curFileDetail[freeIndex] = new ThreadClass(sourceFile, threadEvents[freeIndex]);
					processThread[freeIndex] = new Thread(new ParameterizedThreadStart(LoadInputXml));
					processThread[freeIndex].Name = freeIndex.ToString();
					processThread[freeIndex].Start(curFileDetail[freeIndex]);

				}



Thats my code for starting 10 or any number of threads in an application/service. Am I doing this correctly? I believe this is the corret way of threading.


The reason I am asking this question is, I ran this application that we wrote over here with 1 thread in debug mode and then ran 5 more instances of it in debug mode, each with its own process. So technically, I was running 5 threads, but each with its own process.

Now I compared the results with the number of documents that processed to when I actived 5 threads with only one application, and the other was way better. Which I am not sure why, maybe I might be doing something wrong in the threading?

Do you have any good examples or articles that I can read on advanced threading practices? Basically I dont know if this would help, but the CPU utalization when using 1 thread compared to using 5 threads was pretty much the same, around 33% on a 4 CPU machine. I am doing a lot of analsysis with these documents, and importing in large lexicon files.

Please let me know if you have any suggestions.

Thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1