Performance of subprocess slow when called by Windows Service (.NET)

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Performance of subprocesses is very bad when called by Windows Service. Calling the same subprocess via a console test application I get 100% performance!
There is no performance problem with the machine and the machine is not doing any other work. Windows 7 64bit.
Why is this?
Details:
I have a Windows Service written in C#/.NET 4.0. This service calls some subprocesses (EXE) using the code below. One of this subprocesses is just a wrapper for two subsubprocesses (EXE) which both run very slow in this context. If I replace the outer frame
(windows service) by a console test application the performance is fine.
Fine means: one CPU core is used at nearly 100%. Slow means: one CPU core is used at something between 10% and 40% (all other cores are idle anyway).
The subsubprocesses read and write some larger files (several hundred MByte) and I could increase performance a bit by removing very frequent StreamWriter.Flush calls (after each WriteLine). There seems to be some more bottleneck.
Where is the difference / how to remove the brakes?
<br/>
<pre lang="x-c# Directory.CreateDirectory(subtmpdir);
Process m_Process;
m_Process = new Process(); // Start(si);
m_Process.StartInfo.EnvironmentVariables["TEMP"] = subtmpdir;
m_Process.StartInfo.EnvironmentVariables["TMP"] = subtmpdir;
m_Process.StartInfo.UseShellExecute = false;
m_Process.StartInfo.RedirectStandardError = true;
m_Process.StartInfo.RedirectStandardOutput = true;
m_Process.StartInfo.StandardErrorEncoding = Encoding.GetEncoding("ISO-8859-1");
m_Process.StartInfo.StandardOutputEncoding = Encoding.GetEncoding("ISO-8859-1");
m_Process.OutputDataReceived += new DataReceivedEventHandler(GotOutput);
m_Process.ErrorDataReceived += new DataReceivedEventHandler(GotError);
m_Process.StartInfo.FileName = executable;
m_Process.StartInfo.Arguments = " + tempcontrol + ";
m_Process.StartInfo.CreateNoWindow = true;
m_Process.StartInfo.WorkingDirectory = Path.GetDirectoryName(tempcontrol);
bool started = m_Process.Start();
m_Process.BeginOutputReadLine();
m_Process.BeginErrorReadLine();
m_Process.PriorityClass = ProcessPriorityClass.Idle;
while (!m_Process.HasExited)
{
Thread.Sleep(1000);
}<br/><br/>[/code]

View the full article
 
Back
Top