473,387 Members | 1,619 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,387 software developers and data experts.

PROBLEM WITH THREADS - WIN 2003

Mr
Hi

We have a application with Framework 1.1 and Vs .NET 2003.
the application has a service with pooling; like a
File system Watcher, but works.

the system works fine in the development enviroment with
a performance very good; but production not.
-------------------------------------------------------------------------------------------

SAMPLE CODE
-------------------------------------------------------------------------------------------

using Microsoft.ApplicationBlocks.Data;
using System.Data.SqlClient;
using System;
using System.ServiceProcess;
using System.Diagnostics;
using System.Configuration;
using System.Threading;
using System.Runtime.Remoting;
using System.IO;
using System.Data;
using LibreriasCIV.Proyectos;
using CLSutilidades.Utilidades;
using System.EnterpriseServices;

public class CIVmonitor : System.ServiceProcess.ServiceBase
{
private DateTime timeStart; //Used to note the start time of the service
private DateTime timeEnd; //Used to note the end time of the service
private TimeSpan timeElapsed = new TimeSpan(0); //' Initialize to 0;
// Used to calculate difference between timeEnd and TimeStart
private TimeSpan timeDifference;
private bool isPaused = false; // Notes whether the service is paused;
//ManualResetEvent b = new ManualResetEvent(false);
private bool INICIAR;
private DataSet DSproyectos ;
CLSutilidades.Utilidades.cUtilidadesSeguimiento OBJutil= new
CLSutilidades.Utilidades.cUtilidadesSeguimiento();//PARA TRABAJAR LOS ARCHIVOS
#region " Component Designer generated code ";

public CIVmonitor()
{
// This call is required by the Component Designer.
InitializeComponent();
// Add any initialization after the InitializeComponent() call
}
//UserService overrides dispose to clean up the component list.
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
// The main entry point for the process
static void Main()
{
System.Runtime.Remoting.RemotingConfiguration.Conf igure(AppDomain.CurrentDomain.SetupInformation.Con figurationFile);
System.ServiceProcess.ServiceBase[] ServicesToRun;
// More than one NT Service may run within the same process. To add
// another service to this process, change the following line to
// create a second service object. For example,
ServicesToRun = new System.ServiceProcess.ServiceBase[] {new CIVmonitor()};
System.ServiceProcess.ServiceBase.Run(ServicesToRu n);
}

//Required by the Component Designer
private System.ComponentModel.IContainer components = null;
// NOTE: The following procedure is required by the Component Designer
// It can be modified using the Component Designer.
// Do not modify it using the code editor.
private void InitializeComponent()
{
//
// CIVmonitor
//
this.CanPauseAndContinue = true;
this.CanShutdown = true;
this.ServiceName = "CIVmonitor";

}

#endregion
// OnContinue occurs when the user asks a paused Service to continue. In
order
// for this method to be called the CanPauseAndContinue property must be
// set to true. (It is false by default.)
protected override void OnContinue()
{
// Begin measuring the elapsed time. This means setting the
// timeStart back to the current time, and resetting isPaused
// to false
CrearTabla();
if (isPaused)
{
timeStart = DateTime.Now;
}
isPaused = false;
OBJutil.WriteLOG(ConfigurationSettings.AppSettings .Get("LOGpath").ToString(),"","CIVmonitor Reanudo OperaciĆ³n ","CIVMONITOR","ProcessDir");

}

// OnPause occurs when the user asks a running Service to pause. In order
// for this method to be called the CanPauseAndContinue property must be
// set to true. (It is false by default.)
protected override void OnPause()
{
timeEnd = DateTime.Now;
DSproyectos = null;

if (! isPaused)
{
timeDifference = timeEnd.Subtract(timeStart);
timeElapsed = timeElapsed.Add(timeDifference);
}
isPaused = true;

OBJutil.WriteLOG(ConfigurationSettings.AppSettings .Get("LOGpath").ToString(),"","CIVmonitor Pausado ","CIVMONITOR","ProcessDir");
}

// OnShutdown occurs when the computer is powered off and the
// Service has not been stopped. In order for this method to be called
// the CanShutdown property must be set to true. (It is false by default.)
protected override void OnShutdown()
{
this.OnStop();
DSproyectos = null;
}

// OnStart is called whenever the service is started.
protected override void OnStart(string[] args)
{
System.Threading.Thread.CurrentThread.Name = "GESTOR INTEGRAL DE ARCHIVOS
CIV";
System.Threading.Thread.CurrentThread.Priority=
System.Threading.ThreadPriority.Highest;

timeElapsed = new TimeSpan(0);
// Initialize the Start time
timeStart = DateTime.Now;
isPaused = false;
OBJutil.WriteLOG(ConfigurationSettings.AppSettings .Get("LOGpath").ToString(),"","CIVmonitor Iniciado "+timeElapsed,"CIVMONITOR","ProcessDir");
INICIAR = true;
Debug.Write("INICIO");
CrearTabla(); //CREAR DATASET CON CADA UNO DE LOS PROYECTOS ACTIVOS, ESTOS
SON LOS QUE SE MONITOREARAN
Pickup (); //DISPARAR LA FUNCION QUE MONITOREARA ARCHIVOS
Debug.Write("INICIO");
}

// OnStop is called whenever the service is stopped.
protected override void OnStop()
{
timeEnd = DateTime.Now;
if (! isPaused)
{
timeDifference = timeEnd.Subtract(timeStart);
timeElapsed = timeElapsed.Add(timeDifference);
}
OBJutil.WriteLOG(ConfigurationSettings.AppSettings .Get("LOGpath").ToString(),"","CIVMONITOR DETENIDO "+timeDifference,"CIVMONITOR","ProcessDir");
OBJutil.WriteLOG(ConfigurationSettings.AppSettings .Get("LOGpath").ToString(),"","CIVmonitor Detenido por "+timeElapsed,"CIVMONITOR","ProcessDir");
DSproyectos=null; //LIMPIAR DS
INICIAR =false; //BANDERA A FALSE PARA QUE NO ITERE MAS
}

private void ProcessDir()
{
//
// Processes the files in that directory
//
try
{
while(INICIAR)
{
Debug.WriteLine(" ITERANDO ");
//ITERAR POR CADA UNO DE LOS ELEMENTOS DEL DATASET
if(DSproyectos.Tables.Count > 0 )
{
if(DSproyectos.Tables[0].Rows.Count > 0)
{
//foreach(DataRow dr in DSproyectos.Tables[0].Rows) // LOS ARCHIVOS SE
ALMACENAN UNO A UNO EN UN VECTOR
for(int index=0;index<DSproyectos.Tables[0].Rows.Count;index++)
{
//LLAMAR AL OBJETO QUE VIGILA CARPETAS
CLScontroladora.Controladora.cControl OBJcontroladora = new
CLScontroladora.Controladora.cControl(
DSproyectos.Tables[0].Rows[index].ItemArray[0].ToString(),
//CLInombre
DSproyectos.Tables[0].Rows[index].ItemArray[1].ToString(),
//PROnombre
DSproyectos.Tables[0].Rows[index].ItemArray[2].ToString(), //PROalias
DSproyectos.Tables[0].Rows[index].ItemArray[3].ToString(),
//PROentrada
DSproyectos.Tables[0].Rows[index].ItemArray[4].ToString(), //PROlog
DSproyectos.Tables[0].Rows[index].ItemArray[5].ToString(),
//PRObackup
DSproyectos.Tables[0].Rows[index].ItemArray[6].ToString(),
//PROsalida
DSproyectos.Tables[0].Rows[index].ItemArray[7].ToString(),
//PROextension
DSproyectos.Tables[0].Rows[index].ItemArray[8].ToString(), //PROftp
ConfigurationSettings.AppSettings.Get("Conexion"). ToString());
//CONEXION DB
OBJcontroladora.ClasificarData();
}
Thread.Sleep(int.Parse(ConfigurationSettings.AppSe ttings["Pausa"].ToString())); //PAUSA EN MS PARA QUE NO SE COMA EL SERVICIO LA MAQUINA
}
}

}
}
catch(Exception exp)
{
OBJutil.WriteLOG(ConfigurationSettings.AppSettings .Get("LOGpath").ToString(),"",exp.Message,"CIVMONI TOR","ProcessDir");
}
}

private void CrearTabla()
{
SqlConnection connection = null;// SqlConnection that will be used to
execute the sql commands
DSproyectos = new DataSet("Proyectos"); // SAVE PROYECS
try
{
try
{
Debug.WriteLine("INICIALIZANDO CADENA DE CONEXION");
connection = new
SqlConnection(ConfigurationSettings.AppSettings["Conexion"]);
}
catch
{
Debug.WriteLine("ERROR");
CLSutilidades.Utilidades.cUtilidadesSeguimiento OBJutil= new
CLSutilidades.Utilidades.cUtilidadesSeguimiento();//PARA TRABAJAR LOS ARCHIVOS
OBJutil.WriteLOG(ConfigurationSettings.AppSettings .Get("LOGpath").ToString(),"","NO SE PUDO CONECTAR A LA DB","CIVMONITOR","CrearTabla");
return;
}
DSproyectos = SqlHelper.ExecuteDataset(connection,
CommandType.StoredProcedure, "SpGetProyectos", new SqlParameter("@Estado",
"ACT") );
Debug.WriteLine("SE RECUPERO EL DATASET
"+DSproyectos.Tables[0].Rows.Count);
}
catch(Exception exp)
{
string errMessage = "";
for( Exception tempException = exp; tempException != null ; tempException
= tempException.InnerException )
{
errMessage += tempException.Message + Environment.NewLine +
Environment.NewLine;
}
OBJutil.WriteLOG(ConfigurationSettings.AppSettings .Get("LOGpath").ToString(),"","ERROR
AL TRATAR DE CONSULTAR INFORMACION DE CLIENTES/PROYECTOS EN LA DATABASE -
"+exp.Message,"CIVMONITOR","ProcessDir");
OBJutil.WriteLOG(ConfigurationSettings.AppSettings .Get("LOGpath").ToString(),"",exp.Message,"CIVMONI TOR","ProcessDir");
}
finally
{
if(connection != null)
connection.Dispose();
}

}
private void Pickup ()
{
try
{
System.Threading.Thread.CurrentThread.Name = "Monitor CIV";
Thread objThread= new Thread(new ThreadStart(ProcessDir));
objThread.Name = "Gestor Directorios";
objThread.Priority = System.Threading.ThreadPriority.Highest;
objThread.Start();
Debug.WriteLine("PASO POR PICKUP ");
}

catch(ThreadAbortException exp)
{
OBJutil.WriteLOG(ConfigurationSettings.AppSettings .Get("LOGpath").ToString(),"",exp.Message,"CIVMONI TOR","ProcessDir");

}

}

}

We changed machine.config and nothing.

The performance in production is very slow, the system is WIN 2003.
DEVELOPMENT ENVIROMENT: WIN2000 - SQL SERVER 2000

PRODUCTION ENVIROMENT: WIN2003 - SQL SERVER 2000

What can i do?

Ideas

The application has a service with MultiThreading. For each task
starts a Thread.
Feb 14 '06 #1
5 1398
Hi,

It's not a good idea to post your entire code, nobody will read it
completely ( most of the us people are in the office :) )

Which is the slow part?

Did you check if you may have any sync problems, like two threads
reading/writing the same variable?

what if you try to pinpoint the problem, remove as much code as possible
until you get the method where the performance problem is.

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Feb 14 '06 #2
Mr
thanks

The threads in the server works very slow.

the production server has Win 2003 with SQL 2000.

The problem is; We need more priority for the execution of Threads, because
the process has only a few of CPU.
The program works fine, but very slow.
We need more priority.
ideas?

"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

It's not a good idea to post your entire code, nobody will read it
completely ( most of the us people are in the office :) )

Which is the slow part?

Did you check if you may have any sync problems, like two threads
reading/writing the same variable?

what if you try to pinpoint the problem, remove as much code as possible
until you get the method where the performance problem is.

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Feb 14 '06 #3
You need to profile the code to see where the slow parts are. Since
the service is reading/writing data to a database I suspect that will
be your bottleneck. Changing the priority of the worker will have
little effect especially if the thread is speading most of its time in
an idle state waiting for the database IO to complete.

If you can post a short, but complete program that demonstrates the
slowness you're seeing we can help. Often times, in the process of
attempting to provide that short program, you'll discover the problem
yourself.

Also, like Ignacio, when all else fails use the process of
trial-and-error by removing and adding back code until you find the
performance problem.

Brian

Mr wrote:
thanks

The threads in the server works very slow.

the production server has Win 2003 with SQL 2000.

The problem is; We need more priority for the execution of Threads, because
the process has only a few of CPU.
The program works fine, but very slow.
We need more priority.
ideas?

"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

It's not a good idea to post your entire code, nobody will read it
completely ( most of the us people are in the office :) )

Which is the slow part?

Did you check if you may have any sync problems, like two threads
reading/writing the same variable?

what if you try to pinpoint the problem, remove as much code as possible
until you get the method where the performance problem is.

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Feb 14 '06 #4
Mr <Mr@discussions.microsoft.com> wrote:
We have a application with Framework 1.1 and Vs .NET 2003.
the application has a service with pooling; like a
File system Watcher, but works.

the system works fine in the development enviroment with
a performance very good; but production not.


<snip>

The first thing I'd do is try to reproduce the problem in a console
application. That would be a lot shorter to post, and a lot easier to
debug too.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 14 '06 #5
To add what the others, said. It's wrong to set the priority of a thread
above normal, espcially in a service, it won't make your code run faster
anyway. In you thread procedure (ProcessDir) you run an endless loop, which
does't really shows what you are actually doing (the ClasificarData is
missing) except Sleeping for a while! Now, if this is what you call slow,
why did you include the Sleep call, and what amount of time are you putting
this (high priority!) thread asleep?

Willy.

"Mr" <Mr@discussions.microsoft.com> wrote in message
news:D1**********************************@microsof t.com...
| thanks
|
| The threads in the server works very slow.
|
| the production server has Win 2003 with SQL 2000.
|
| The problem is; We need more priority for the execution of Threads,
because
| the process has only a few of CPU.
| The program works fine, but very slow.
| We need more priority.
| ideas?
|
| "Ignacio Machin ( .NET/ C# MVP )" wrote:
|
| > Hi,
| >
| > It's not a good idea to post your entire code, nobody will read it
| > completely ( most of the us people are in the office :) )
| >
| > Which is the slow part?
| >
| > Did you check if you may have any sync problems, like two threads
| > reading/writing the same variable?
| >
| > what if you try to pinpoint the problem, remove as much code as possible
| > until you get the method where the performance problem is.
| >
| >
| >
| > --
| > Ignacio Machin,
| > ignacio.machin AT dot.state.fl.us
| > Florida Department Of Transportation
| >
| >
| >
Feb 14 '06 #6

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

Similar topics

2
by: Tobias | last post by:
Hi! I had Apache 2.0.47 and PHP 4.3.0 DEV running successfully on a W2k Server. For some reason, I couldn't get PHP to read XML-Attributes with the DOM XML -functions. So I thought, it would be...
2
by: Vinay Aggarwal | last post by:
I have been thinking about the lazy initialization and double checked locking problem. This problem is explain in detail here http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html...
6
by: Evan David Light | last post by:
After agonizing over this problem for a few days, I've decided to seek help. No, not the variety that involes a jacket that zips up the back but this august body of intrepid individuals. I've...
7
by: David Sworder | last post by:
Hi, I'm developing an application that will support several thousand simultaneous connections on the server-side. I'm trying to maximize throughput. The client (WinForms) and server communicate...
6
by: David | last post by:
Hi all, In my code I have a bottleneck which consists of a cpu-intensive loop of size LENGTH. What I did was to divide that loop into two threads, Thread1 doing the 0 to LENGTH/2 part, and...
8
by: Rob Edwards | last post by:
When trying to add the Microsoft CDO for Exchange Management Library (aka CDOEXM.dll) I receive the following message: "A reference to 'Microsoft CDO for Exchange Management Library' could not be...
3
by: Jack Fox | last post by:
While stress-testing our ASP.NET app, we discovered a flaw in our test set-up, which also reveals a flaw in our ASP.NET configuration that we do not know how to address. We simulated too...
3
by: Dave | last post by:
Hi, I have a .NET class which uses the .NET threadpool (using QueueUserWorkItem) to create about 8 threads, which do some work while the parent thread waits for them all to complete, which works...
3
by: Doug | last post by:
I'm having problems w/ the VS2005 debugger with C#. It blows past any breakpoints in even the simplest "Hello World" console application. I can't do any step-by-step debugging. I've provided the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.